Skip to content

Commit 6ab54be

Browse files
Merge pull request #118 from mrkalmdn/main
Convert PHPUnit to Pest
2 parents 189888f + 8f8a1a4 commit 6ab54be

19 files changed

+1569
-1940
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ jobs:
4848
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
4949
5050
- name: Execute tests
51-
run: vendor/bin/phpunit
51+
run: vendor/bin/pest
5252
env:
5353
REDIS_PORT: ${{ job.services.redis.ports['6379'] }}

composer.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@
2727
"require-dev": {
2828
"ext-redis": "*",
2929
"mockery/mockery": "^1.4",
30+
"nunomaduro/larastan": "^1.0",
3031
"orchestra/testbench": "^6.23|^7.0",
31-
"phpunit/phpunit": "^9.5",
32-
"spatie/phpunit-snapshot-assertions": "^4.2",
32+
"pestphp/pest": "^1.21",
33+
"pestphp/pest-plugin-laravel": "^1.2",
3334
"phpstan/extension-installer": "^1.1",
3435
"phpstan/phpstan-deprecation-rules": "^1.0",
3536
"phpstan/phpstan-phpunit": "^1.0",
36-
"nunomaduro/larastan": "^1.0"
37+
"phpunit/phpunit": "^9.5",
38+
"spatie/pest-plugin-snapshots": "^1.1",
39+
"spatie/phpunit-snapshot-assertions": "^4.2"
3740
},
3841
"autoload": {
3942
"psr-4": {
@@ -47,8 +50,8 @@
4750
},
4851
"scripts": {
4952
"analyse": "vendor/bin/phpstan analyse",
50-
"test": "vendor/bin/phpunit",
51-
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
53+
"test": "vendor/bin/pest",
54+
"test-coverage": "vendor/bin/pest --coverage"
5255
},
5356
"config": {
5457
"sort-packages": true

tests/Console/CacheDiscoveredSettingsCommandTest.php

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,27 @@
22

33
namespace Spatie\LaravelSettings\Tests\Console;
44

5+
use function Orchestra\Testbench\artisan;
56
use Spatie\LaravelSettings\SettingsContainer;
6-
use Spatie\LaravelSettings\Tests\TestCase;
77
use Spatie\LaravelSettings\Tests\TestClasses\DummySettings;
88
use Spatie\LaravelSettings\Tests\TestClasses\DummySimpleSettings;
9-
use Spatie\Snapshots\MatchesSnapshots;
10-
11-
class CacheDiscoveredSettingsCommandTest extends TestCase
12-
{
13-
use MatchesSnapshots;
149

15-
private SettingsContainer $container;
10+
use function Spatie\Snapshots\assertMatchesSnapshot;
11+
use Spatie\Snapshots\MatchesSnapshots;
1612

17-
public function setUp(): void
18-
{
19-
parent::setUp();
13+
uses(MatchesSnapshots::class);
2014

21-
$this->app['config']->set('settings.settings', [
22-
DummySettings::class,
23-
DummySimpleSettings::class,
24-
]);
15+
beforeEach(function () {
16+
$this->app['config']->set('settings.settings', [
17+
DummySettings::class,
18+
DummySimpleSettings::class,
19+
]);
2520

26-
$this->container = app(SettingsContainer::class);
27-
}
21+
$this->container = app(SettingsContainer::class);
22+
});
2823

29-
/** @test */
30-
public function it_can_cache_the_registered_sessions()
31-
{
32-
$this->artisan('settings:discover')->assertExitCode(0);
24+
it('can cache the registered sessions', function () {
25+
artisan($this, 'settings:discover')->assertExitCode(0);
3326

34-
$this->assertMatchesSnapshot(file_get_contents(config('settings.discovered_settings_cache_path').'/settings.php'));
35-
}
36-
}
27+
assertMatchesSnapshot(file_get_contents(config('settings.discovered_settings_cache_path').'/settings.php'));
28+
});

tests/Console/ClearDiscoveredSettingsCacheCommandTest.php

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,29 @@
22

33
namespace Spatie\LaravelSettings\Tests\Console;
44

5+
use function Orchestra\Testbench\artisan;
6+
use function PHPUnit\Framework\assertFileDoesNotExist;
7+
use function PHPUnit\Framework\assertFileExists;
8+
59
use Spatie\LaravelSettings\SettingsContainer;
6-
use Spatie\LaravelSettings\Tests\TestCase;
710
use Spatie\LaravelSettings\Tests\TestClasses\DummySettings;
811
use Spatie\LaravelSettings\Tests\TestClasses\DummySimpleSettings;
912

10-
class ClearDiscoveredSettingsCacheCommandTest extends TestCase
11-
{
12-
private SettingsContainer $settingsContainer;
13-
14-
public function setUp(): void
15-
{
16-
parent::setUp();
17-
18-
$this->app['config']->set('settings.settings', [
19-
DummySettings::class,
20-
DummySimpleSettings::class,
21-
]);
13+
beforeEach(function () {
14+
$this->app['config']->set('settings.settings', [
15+
DummySettings::class,
16+
DummySimpleSettings::class,
17+
]);
2218

23-
$this->settingsContainer = app(SettingsContainer::class);
24-
}
19+
$this->settingsContainer = app(SettingsContainer::class);
20+
});
2521

26-
/** @test */
27-
public function it_can_clear_the_registered_settings()
28-
{
29-
$this->artisan('settings:discover')->assertExitCode(0);
22+
it('can clear the registered settings', function () {
23+
artisan($this, 'settings:discover')->assertExitCode(0);
3024

31-
$this->assertFileExists(config('settings.discovered_settings_cache_path').'/settings.php');
25+
assertFileExists(config('settings.discovered_settings_cache_path').'/settings.php');
3226

33-
$this->artisan('settings:clear-discovered')->assertExitCode(0);
27+
artisan($this, 'settings:clear-discovered')->assertExitCode(0);
3428

35-
$this->assertFileDoesNotExist(config('settings.discovered_settings_cache_path').'/settings.php');
36-
}
37-
}
29+
assertFileDoesNotExist(config('settings.discovered_settings_cache_path').'/settings.php');
30+
});

tests/Console/MakeSettingsMigrationCommandTest.php

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,20 @@
22

33
namespace Spatie\LaravelSettings\Tests\Console;
44

5-
use Spatie\LaravelSettings\Tests\TestCase;
5+
use function Orchestra\Testbench\artisan;
66

7-
class MakeSettingsMigrationCommandTest extends TestCase
8-
{
9-
/** @test */
10-
public function it_creates_a_new_test_settings_migration_on_specified_path()
11-
{
12-
$tmpDir = sys_get_temp_dir();
7+
it('creates a new test settings migration on specified path', function () {
8+
$tmpDir = sys_get_temp_dir();
139

14-
$this->artisan('make:settings-migration', [
15-
'name' => 'CreateNewTestSettingsMigration',
16-
'path' => $tmpDir,
17-
])->assertExitCode(0);
10+
artisan($this, 'make:settings-migration', [
11+
'name' => 'CreateNewTestSettingsMigration',
12+
'path' => $tmpDir,
13+
])->assertExitCode(0);
1814

19-
$tmpList = glob(sprintf('%s/*_create_new_test_settings_migration.php', $tmpDir));
15+
$tmpList = glob(sprintf('%s/*_create_new_test_settings_migration.php', $tmpDir));
2016

21-
$this->assertCount(1, $tmpList);
17+
expect($tmpList)->toHaveCount(1);
2218

23-
// Remove test file.
24-
unlink($tmpList[0]);
25-
}
26-
}
19+
// Remove test file.
20+
unlink($tmpList[0]);
21+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
use Spatie\LaravelSettings\Models\SettingsProperty;
4+
use Spatie\LaravelSettings\SettingsRepositories\DatabaseSettingsRepository;
5+
6+
dataset('configurationsProvider', [
7+
fn () => new DatabaseSettingsRepository([
8+
'connection' => 'other',
9+
]),
10+
function () {
11+
$model = new class() extends SettingsProperty {
12+
public function getConnectionName()
13+
{
14+
return 'other';
15+
}
16+
};
17+
18+
return new DatabaseSettingsRepository([
19+
'model' => get_class($model),
20+
]);
21+
},
22+
]);

tests/DiscoversSettingsTest.php

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,31 @@
22

33
namespace Spatie\LaravelSettings\Tests;
44

5+
use function PHPUnit\Framework\assertEqualsCanonicalizing;
56
use Spatie\LaravelSettings\Support\Composer;
67
use Spatie\LaravelSettings\Support\DiscoverSettings;
78
use Spatie\LaravelSettings\Tests\TestClasses\DummyEncryptedSettings;
89
use Spatie\LaravelSettings\Tests\TestClasses\DummySettings;
910
use Spatie\LaravelSettings\Tests\TestClasses\DummySettingsWithCast;
1011
use Spatie\LaravelSettings\Tests\TestClasses\DummySettingsWithImportedType;
12+
1113
use Spatie\LaravelSettings\Tests\TestClasses\DummySimpleSettings;
1214

13-
class DiscoversSettingsTest extends TestCase
14-
{
15-
/** @test */
16-
public function it_can_get_all_classes_that_are_settings()
17-
{
18-
$pathToComposerJson = __DIR__.'/../composer.json';
15+
it('can get all classes that are settings', function () {
16+
$pathToComposerJson = __DIR__.'/../composer.json';
1917

20-
$discovered = (new DiscoverSettings())
21-
->within([__DIR__.'/TestClasses'])
22-
->useBasePath(realpath(__DIR__.'/../'))
23-
->useRootNamespace('Spatie\LaravelSettings\\')
24-
->ignoringFiles(Composer::getAutoloadedFiles($pathToComposerJson))
25-
->discover();
18+
$discovered = (new DiscoverSettings())
19+
->within([__DIR__.'/TestClasses'])
20+
->useBasePath(realpath(__DIR__.'/../'))
21+
->useRootNamespace('Spatie\LaravelSettings\\')
22+
->ignoringFiles(Composer::getAutoloadedFiles($pathToComposerJson))
23+
->discover();
2624

27-
$this->assertEqualsCanonicalizing([
28-
DummySimpleSettings::class,
29-
DummySettings::class,
30-
DummyEncryptedSettings::class,
31-
DummySettingsWithImportedType::class,
32-
DummySettingsWithCast::class,
33-
], $discovered);
34-
}
35-
}
25+
assertEqualsCanonicalizing([
26+
DummySimpleSettings::class,
27+
DummySettings::class,
28+
DummyEncryptedSettings::class,
29+
DummySettingsWithImportedType::class,
30+
DummySettingsWithCast::class,
31+
], $discovered);
32+
});

0 commit comments

Comments
 (0)