From 99006bfd06ffc669ce6b38a59d51075b4c92c10c Mon Sep 17 00:00:00 2001 From: Martin Kluska Date: Thu, 29 Jun 2023 20:34:52 +0200 Subject: [PATCH] fix(Testing): PHPStorm run for ResourceTestCase with single data entry test BREAKING CHANGE: to allow running single data test in PHPStorm, test function was removed. To run tests add this method when extending the TestCase. ```php /** * @param \Closure(static):void $assert * @dataProvider data */ public function test(\Closure $assert): void { $assert($this); } ``` --- src/Testing/PHPUnit/ResourceTestCase.php | 9 --------- .../Testing/PHPUnit/LaraStrictResourceTestCaseTest.php | 10 ++++++++++ .../PHPUnit/LaraStrictResourcesTestCaseTest.php | 10 ++++++++++ .../Testing/PHPUnit/LaravelResourceTestCaseTest.php | 10 ++++++++++ .../Testing/PHPUnit/LaravelResourcesTestCaseTest.php | 10 ++++++++++ .../Unit/Testing/PHPUnit/ModelResourceTestCaseTest.php | 10 ++++++++++ 6 files changed, 50 insertions(+), 9 deletions(-) diff --git a/src/Testing/PHPUnit/ResourceTestCase.php b/src/Testing/PHPUnit/ResourceTestCase.php index 9c5a5f37..b70fd47a 100644 --- a/src/Testing/PHPUnit/ResourceTestCase.php +++ b/src/Testing/PHPUnit/ResourceTestCase.php @@ -25,15 +25,6 @@ abstract class ResourceTestCase extends AssertExpectationTestCase */ abstract public function data(): array; - /** - * @param Closure(static):void $assert - * @dataProvider data - */ - public function test(Closure $assert): void - { - $assert($this); - } - /** * @param TEntity|callable():TEntity $object * @param array|Exception $expected diff --git a/tests/Unit/Testing/PHPUnit/LaraStrictResourceTestCaseTest.php b/tests/Unit/Testing/PHPUnit/LaraStrictResourceTestCaseTest.php index bd2591eb..fe4cd9eb 100644 --- a/tests/Unit/Testing/PHPUnit/LaraStrictResourceTestCaseTest.php +++ b/tests/Unit/Testing/PHPUnit/LaraStrictResourceTestCaseTest.php @@ -4,6 +4,7 @@ namespace Tests\LaraStrict\Unit\Testing\PHPUnit; +use Closure; use Illuminate\Http\Resources\Json\JsonResource; use LaraStrict\Testing\Laravel\TestingContainer; use LaraStrict\Testing\PHPUnit\ResourceTestCase; @@ -28,6 +29,15 @@ public function data(): array ]; } + /** + * @param Closure(static):void $assert + * @dataProvider data + */ + public function test(Closure $assert): void + { + $assert($this); + } + protected function myAssert(string $value, string $instance): void { $this->assert( diff --git a/tests/Unit/Testing/PHPUnit/LaraStrictResourcesTestCaseTest.php b/tests/Unit/Testing/PHPUnit/LaraStrictResourcesTestCaseTest.php index 2966646b..33f96843 100644 --- a/tests/Unit/Testing/PHPUnit/LaraStrictResourcesTestCaseTest.php +++ b/tests/Unit/Testing/PHPUnit/LaraStrictResourcesTestCaseTest.php @@ -4,6 +4,7 @@ namespace Tests\LaraStrict\Unit\Testing\PHPUnit; +use Closure; use Illuminate\Http\Resources\Json\JsonResource; use LaraStrict\Testing\Laravel\TestingContainer; use LaraStrict\Testing\PHPUnit\ResourceTestCase; @@ -28,6 +29,15 @@ public function data(): array ]; } + /** + * @param Closure(static):void $assert + * @dataProvider data + */ + public function test(Closure $assert): void + { + $assert($this); + } + protected function myAssert(string $value, string $instance): void { $this->assert( diff --git a/tests/Unit/Testing/PHPUnit/LaravelResourceTestCaseTest.php b/tests/Unit/Testing/PHPUnit/LaravelResourceTestCaseTest.php index 5582f947..8d1c9494 100644 --- a/tests/Unit/Testing/PHPUnit/LaravelResourceTestCaseTest.php +++ b/tests/Unit/Testing/PHPUnit/LaravelResourceTestCaseTest.php @@ -4,6 +4,7 @@ namespace Tests\LaraStrict\Unit\Testing\PHPUnit; +use Closure; use Illuminate\Http\Resources\Json\JsonResource; use LaraStrict\Testing\Laravel\TestingContainer; use LaraStrict\Testing\PHPUnit\ResourceTestCase; @@ -39,6 +40,15 @@ public function data(): array ]; } + /** + * @param Closure(static):void $assert + * @dataProvider data + */ + public function test(Closure $assert): void + { + $assert($this); + } + protected function createResource(mixed $object): JsonResource { return new LaravelResource($object); diff --git a/tests/Unit/Testing/PHPUnit/LaravelResourcesTestCaseTest.php b/tests/Unit/Testing/PHPUnit/LaravelResourcesTestCaseTest.php index 78598a89..6d189e6e 100644 --- a/tests/Unit/Testing/PHPUnit/LaravelResourcesTestCaseTest.php +++ b/tests/Unit/Testing/PHPUnit/LaravelResourcesTestCaseTest.php @@ -4,6 +4,7 @@ namespace Tests\LaraStrict\Unit\Testing\PHPUnit; +use Closure; use Illuminate\Http\Resources\Json\JsonResource; use LaraStrict\Testing\Laravel\TestingContainer; use LaraStrict\Testing\PHPUnit\ResourceTestCase; @@ -39,6 +40,15 @@ public function data(): array ]; } + /** + * @param Closure(static):void $assert + * @dataProvider data + */ + public function test(Closure $assert): void + { + $assert($this); + } + protected function createResource(mixed $object): JsonResource { return LaravelResource::collection($object); diff --git a/tests/Unit/Testing/PHPUnit/ModelResourceTestCaseTest.php b/tests/Unit/Testing/PHPUnit/ModelResourceTestCaseTest.php index 525b1d96..636f7d35 100644 --- a/tests/Unit/Testing/PHPUnit/ModelResourceTestCaseTest.php +++ b/tests/Unit/Testing/PHPUnit/ModelResourceTestCaseTest.php @@ -5,6 +5,7 @@ namespace Tests\LaraStrict\Unit\Testing\PHPUnit; use Carbon\Carbon; +use Closure; use Illuminate\Http\Resources\Json\JsonResource; use LaraStrict\Testing\PHPUnit\ModelResourceTestCase; use Tests\LaraStrict\Feature\Database\Models\Test; @@ -32,6 +33,15 @@ public function data(): array ]; } + /** + * @param Closure(static):void $assert + * @dataProvider data + */ + public function test(Closure $assert): void + { + $assert($this); + } + protected function createResource(mixed $object): JsonResource { return new ModelResource($object);