From 1c11595504284a104f1bdef3917eed3c60738059 Mon Sep 17 00:00:00 2001 From: nuno maduro Date: Sun, 19 Jul 2026 03:41:57 +0100 Subject: [PATCH] chore: moves to coding stlye --- rector.php | 3 +-- tests/Autoload.php | 6 ++++-- tests/Features/AfterAll.php | 2 +- tests/Features/DatasetsTests.php | 11 +++-------- tests/Features/Exceptions.php | 8 +++----- tests/Features/Test.php | 2 +- tests/Fixtures/Inheritance/ExampleTest.php | 2 +- .../CustomAffixes/FolderWithAn@/ExampleTest.php | 2 +- .../SubFolder/SubFolder/CustomTestCaseInSubFolder.php | 2 +- .../SubFolder2/UsesPerFile.php | 2 +- 10 files changed, 17 insertions(+), 23 deletions(-) diff --git a/rector.php b/rector.php index 99fafbd9..1d219d27 100644 --- a/rector.php +++ b/rector.php @@ -23,8 +23,7 @@ return RectorConfig::configure() __DIR__.'/tests', ]) ->withSets([ - PestSetList::PEST_CODE_QUALITY, - PestSetList::PEST_CHAIN, + PestSetList::CODING_STYLE, ]) ->withSkip([ __DIR__.'/src/Plugins/Parallel/Paratest/WrapperRunner.php', diff --git a/tests/Autoload.php b/tests/Autoload.php index c9eb2848..034c1e51 100644 --- a/tests/Autoload.php +++ b/tests/Autoload.php @@ -1,12 +1,14 @@ assertTrue(true); + expect(true)->toBeTrue(); } } @@ -14,7 +16,7 @@ trait SecondPluginTrait { public function assertSecondPluginTraitGotRegistered(): void { - $this->assertTrue(true); + expect(true)->toBeTrue(); } } diff --git a/tests/Features/AfterAll.php b/tests/Features/AfterAll.php index 6ef10fff..0afd0a56 100644 --- a/tests/Features/AfterAll.php +++ b/tests/Features/AfterAll.php @@ -14,7 +14,7 @@ afterAll(function () use ($file): void { test('deletes file after all', function () use ($file): void { file_put_contents($file, 'foo'); - $this->assertFileExists($file); + expect($file)->toBeFile(); register_shutdown_function(function (): void { // $this->assertFileDoesNotExist($file); }); diff --git a/tests/Features/DatasetsTests.php b/tests/Features/DatasetsTests.php index dd3934b7..b7ac4811 100644 --- a/tests/Features/DatasetsTests.php +++ b/tests/Features/DatasetsTests.php @@ -10,17 +10,12 @@ beforeEach(function (): void { }); it('throws exception if dataset does not exist', function (): void { - $this->expectException(DatasetDoesNotExist::class); - $this->expectExceptionMessage("A dataset with the name `first` does not exist. You can create it using `dataset('first', ['a', 'b']);`."); - - DatasetsRepository::resolve(['first'], __FILE__); + expect(fn () => DatasetsRepository::resolve(['first'], __FILE__))->toThrow(DatasetDoesNotExist::class, "A dataset with the name `first` does not exist. You can create it using `dataset('first', ['a', 'b']);`."); }); it('throws exception if dataset already exist', function (): void { DatasetsRepository::set('second', [[]], __DIR__); - $this->expectException(DatasetAlreadyExists::class); - $this->expectExceptionMessage('A dataset with the name `second` already exists in scope ['.__DIR__.'].'); - DatasetsRepository::set('second', [[]], __DIR__); + expect(fn () => DatasetsRepository::set('second', [[]], __DIR__))->toThrow(DatasetAlreadyExists::class, 'A dataset with the name `second` already exists in scope ['.__DIR__.'].'); }); it('sets closures', function (): void { @@ -38,7 +33,7 @@ it('sets arrays', function (): void { }); it('gets bound to test case object', function ($value): void { - $this->assertTrue(true); + expect(true)->toBeTrue(); })->with([['a'], ['b']]); test('it truncates the description', function (): void { diff --git a/tests/Features/Exceptions.php b/tests/Features/Exceptions.php index ec5ca430..72a1c28a 100644 --- a/tests/Features/Exceptions.php +++ b/tests/Features/Exceptions.php @@ -1,9 +1,7 @@ expectException(InvalidArgumentException::class); - - throw new InvalidArgumentException; + expect(fn () => throw new InvalidArgumentException)->toThrow(InvalidArgumentException::class); }); it('catch exceptions', function (): void { @@ -27,7 +25,7 @@ it('can just define the code', function (): void { })->throws(1); it('not catch exceptions if given condition is false', function (): void { - $this->assertTrue(true); + expect(true)->toBeTrue(); })->throwsIf(false, Exception::class); it('catch exceptions if given condition is true', function (): void { @@ -59,7 +57,7 @@ it('can just define the code if given condition is 1', function (): void { })->throwsIf(1, 1); it('not catch exceptions if given condition is true', function (): void { - $this->assertTrue(true); + expect(true)->toBeTrue(); })->throwsUnless(true, Exception::class); it('catch exceptions if given condition is false', function (): void { diff --git a/tests/Features/Test.php b/tests/Features/Test.php index a14ba486..df1a1db7 100644 --- a/tests/Features/Test.php +++ b/tests/Features/Test.php @@ -3,7 +3,7 @@ declare(strict_types=1); test('a test', function (): void { - $this->assertArrayHasKey('key', ['key' => 'foo']); + expect(['key' => 'foo'])->toHaveKey('key'); }); test('higher order message test')->expect(true)->toBeTrue(); diff --git a/tests/Fixtures/Inheritance/ExampleTest.php b/tests/Fixtures/Inheritance/ExampleTest.php index 6e10c613..eb5ffd10 100644 --- a/tests/Fixtures/Inheritance/ExampleTest.php +++ b/tests/Fixtures/Inheritance/ExampleTest.php @@ -11,6 +11,6 @@ class ExampleTest extends Base\ExampleTest #[\Override] public function test_example(): void { - $this->assertTrue(true); + expect(true)->toBeTrue(); } } diff --git a/tests/PHPUnit/CustomAffixes/FolderWithAn@/ExampleTest.php b/tests/PHPUnit/CustomAffixes/FolderWithAn@/ExampleTest.php index ed285079..39bf62e7 100644 --- a/tests/PHPUnit/CustomAffixes/FolderWithAn@/ExampleTest.php +++ b/tests/PHPUnit/CustomAffixes/FolderWithAn@/ExampleTest.php @@ -7,7 +7,7 @@ class MyCustomClassTest extends TestCase { public function assertTrueIsTrue(): void { - $this->assertTrue(true); + expect(true)->toBeTrue(); } } diff --git a/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder/SubFolder/CustomTestCaseInSubFolder.php b/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder/SubFolder/CustomTestCaseInSubFolder.php index 15997eff..aae6e502 100644 --- a/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder/SubFolder/CustomTestCaseInSubFolder.php +++ b/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder/SubFolder/CustomTestCaseInSubFolder.php @@ -10,6 +10,6 @@ class CustomTestCaseInSubFolder extends TestCase { public function assertCustomInSubFolderTrue(): void { - $this->assertTrue(true); + expect(true)->toBeTrue(); } } diff --git a/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder2/UsesPerFile.php b/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder2/UsesPerFile.php index c114778a..49ef3cbe 100644 --- a/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder2/UsesPerFile.php +++ b/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder2/UsesPerFile.php @@ -14,7 +14,7 @@ abstract class MyCustomClass extends TestCase { public function assertTrueIsTrue(): void { - $this->assertTrue(true); + expect(true)->toBeTrue(); } }