Skip to content

Commit

Permalink
feat(Testing): ResourceTestCase $object supports mixed type or closure
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Update createResource typehint to mixed.
  • Loading branch information
pionl committed Jun 29, 2023
1 parent 3e7b7e9 commit 780f59a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/Testing/PHPUnit/ResourceTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Mockery\Adapter\Phpunit\MockeryTestCaseSetUp;

/**
* @template TEntity of object
* @template TEntity
*/
abstract class ResourceTestCase extends AssertExpectationTestCase
{
Expand Down Expand Up @@ -44,15 +44,15 @@ protected function mockeryTestTearDown(): void
}

/**
* @param TEntity $object
* @param TEntity|callable():TEntity $object
* @param array<string|int, mixed> $expected
* @param TestingContainer|null $container Set container to the resource.
*/
protected function assert(object $object, array $expected, ?TestingContainer $container = null): void
protected function assert(mixed $object, array $expected, ?TestingContainer $container = null): void
{
$request = new Request();

$resource = $this->createResource($object);
$resource = $this->createResource(is_callable($object) ? $object() : $object);

if ($resource instanceof LaraStrictJsonResource && $container !== null) {
$resource->setContainer($container);
Expand All @@ -64,5 +64,5 @@ protected function assert(object $object, array $expected, ?TestingContainer $co
/**
* @param TEntity $object
*/
abstract protected function createResource(object $object): JsonResource;
abstract protected function createResource(mixed $object): JsonResource;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function myAssert(string $value, string $instance): void
);
}

protected function createResource(object $object): JsonResource
protected function createResource(mixed $object): JsonResource
{
return new LaraStrictResource($object);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Testing/PHPUnit/LaravelResourceTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function data(): array
];
}

protected function createResource(object $object): JsonResource
protected function createResource(mixed $object): JsonResource
{
return new LaravelResource($object);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Testing/PHPUnit/ModelResourceTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function data(): array
];
}

protected function createResource(object $object): JsonResource
protected function createResource(mixed $object): JsonResource
{
return new ModelResource($object);
}
Expand Down

0 comments on commit 780f59a

Please sign in to comment.