Skip to content

Commit

Permalink
fix(Testing): PHPStorm run for ResourceTestCase with single data entr…
Browse files Browse the repository at this point in the history
…y 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);
    }
```
  • Loading branch information
pionl committed Jun 30, 2023
1 parent 20b1ff4 commit 99006bf
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 9 deletions.
9 changes: 0 additions & 9 deletions src/Testing/PHPUnit/ResourceTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string|int, mixed>|Exception $expected
Expand Down
10 changes: 10 additions & 0 deletions tests/Unit/Testing/PHPUnit/LaraStrictResourceTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand Down
10 changes: 10 additions & 0 deletions tests/Unit/Testing/PHPUnit/LaraStrictResourcesTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand Down
10 changes: 10 additions & 0 deletions tests/Unit/Testing/PHPUnit/LaravelResourceTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions tests/Unit/Testing/PHPUnit/LaravelResourcesTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions tests/Unit/Testing/PHPUnit/ModelResourceTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 99006bf

Please sign in to comment.