diff --git a/src/Contracts/ResourceDecorator.php b/src/Contracts/ResourceDecorator.php index ae9669df..c74d3e65 100644 --- a/src/Contracts/ResourceDecorator.php +++ b/src/Contracts/ResourceDecorator.php @@ -10,7 +10,7 @@ interface ResourceDecorator { /** - * @param Response|BaseResource|BaseCollection|LazyCollection $resource + * @param Response|BaseResource|BaseCollection|LazyCollection $resource */ public static function fromResource($resource): self; } diff --git a/src/Http/Requests/ResourceHydratableRequest.php b/src/Http/Requests/ResourceHydratableRequest.php index d08b126e..dd1d824b 100644 --- a/src/Http/Requests/ResourceHydratableRequest.php +++ b/src/Http/Requests/ResourceHydratableRequest.php @@ -39,8 +39,7 @@ public function getHydratableResource() } /** - * @param string|DecorateResource $hydratableResource - * @return self + * @param string|DecorateResource $hydratableResource */ public function setHydratableResource($hydratableResource): self { @@ -49,7 +48,7 @@ public function setHydratableResource($hydratableResource): self } if ($hydratableResource instanceof DecorateResource && ! $hydratableResource->getDecorator()) { - throw new \InvalidArgumentException("The decorator class is not set."); + throw new \InvalidArgumentException('The decorator class is not set.'); } $this->customHydratableResource = $hydratableResource; diff --git a/src/Resources/ResourceFactory.php b/src/Resources/ResourceFactory.php index e17d5b43..1c8e6e42 100644 --- a/src/Resources/ResourceFactory.php +++ b/src/Resources/ResourceFactory.php @@ -3,8 +3,8 @@ namespace Mollie\Api\Resources; use Mollie\Api\Contracts\Connector; -use Mollie\Api\Contracts\ResourceDecorator; use Mollie\Api\Contracts\EmbeddedResourcesContract; +use Mollie\Api\Contracts\ResourceDecorator; use Mollie\Api\Exceptions\EmbeddedResourcesNotParseableException; use Mollie\Api\Http\Response; @@ -61,9 +61,7 @@ public static function createBaseResourceCollection( /** * Create a decorated resource from a response or existing resource. * - * @param Response|BaseResource|BaseCollection|LazyCollection $response - * @param string $decorator - * @return ResourceDecorator + * @param Response|BaseResource|BaseCollection|LazyCollection $response */ public static function createDecoratedResource($response, string $decorator): ResourceDecorator { diff --git a/tests/Resources/ResourceFactoryTest.php b/tests/Resources/ResourceFactoryTest.php index 87923344..453bada3 100644 --- a/tests/Resources/ResourceFactoryTest.php +++ b/tests/Resources/ResourceFactoryTest.php @@ -2,17 +2,17 @@ namespace Tests\Resources; +use Mollie\Api\Contracts\ResourceDecorator; use Mollie\Api\Http\Response; use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\AnyResource; +use Mollie\Api\Resources\BaseCollection; use Mollie\Api\Resources\Client; use Mollie\Api\Resources\Onboarding; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\RefundCollection; use Mollie\Api\Resources\ResourceFactory; -use Mollie\Api\Contracts\ResourceDecorator; -use Mollie\Api\Resources\BaseCollection; use PHPUnit\Framework\TestCase; class ResourceFactoryTest extends TestCase @@ -128,7 +128,7 @@ public function embedded_resources_are_type_casted() /** @test */ public function it_throws_exception_when_response_is_missing() { - $apiResult = new \stdClass(); + $apiResult = new \stdClass; $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Response is required'); @@ -190,7 +190,7 @@ public function it_creates_base_resource_collection() $response = $this->createMock(Response::class); $data = [ ['id' => 'payment-1', 'resource' => 'payment'], - ['id' => 'payment-2', 'resource' => 'payment'] + ['id' => 'payment-2', 'resource' => 'payment'], ]; $collection = ResourceFactory::createBaseResourceCollection( @@ -211,7 +211,7 @@ public function it_creates_base_resource_collection_with_custom_collection_class { $response = $this->createMock(Response::class); $data = [ - ['id' => 'payment-1', 'resource' => 'payment'] + ['id' => 'payment-1', 'resource' => 'payment'], ]; $collection = ResourceFactory::createBaseResourceCollection( @@ -289,8 +289,11 @@ class CustomPaymentCollection extends BaseCollection class CustomResourceDecorator implements ResourceDecorator { public string $status; + public bool $canReceivePayments; + public bool $canReceiveSettlements; + public string $dashboardUrl; public function __construct( diff --git a/tests/Resources/ResourceHydratorTest.php b/tests/Resources/ResourceHydratorTest.php index 4c811654..dc207214 100644 --- a/tests/Resources/ResourceHydratorTest.php +++ b/tests/Resources/ResourceHydratorTest.php @@ -6,27 +6,28 @@ use Mollie\Api\Contracts\ResourceDecorator; use Mollie\Api\Http\Requests\ResourceHydratableRequest; use Mollie\Api\Http\Response; +use Mollie\Api\MollieApiClient; +use Mollie\Api\Resources\AnyResource; use Mollie\Api\Resources\BaseResource; use Mollie\Api\Resources\CursorCollection; use Mollie\Api\Resources\DecorateResource; -use Mollie\Api\Resources\ResourceHydrator; -use Mollie\Api\MollieApiClient; -use Mollie\Api\Resources\AnyResource; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\ResourceCollection; +use Mollie\Api\Resources\ResourceHydrator; use Mollie\Api\Traits\IsIteratableRequest; use PHPUnit\Framework\TestCase; class ResourceHydratorTest extends TestCase { private ResourceHydrator $hydrator; + private MollieApiClient $client; protected function setUp(): void { parent::setUp(); - $this->hydrator = new ResourceHydrator(); + $this->hydrator = new ResourceHydrator; $this->client = $this->createMock(MollieApiClient::class); } @@ -57,7 +58,8 @@ public function hydrate_collection(): void $request = $this->createMock(ResourceHydratableRequest::class); $response = $this->createMock(Response::class); - $mockCollection = new class($this->client, $response) extends ResourceCollection { + $mockCollection = new class($this->client, $response) extends ResourceCollection + { public static string $resource = AnyResource::class; public static string $collectionName = 'items'; @@ -73,9 +75,9 @@ public function hydrate_collection(): void $response->expects($this->once()) ->method('json') - ->willReturn((object)[ - '_embedded' => (object)['items' => []], - '_links' => (object)[] + ->willReturn((object) [ + '_embedded' => (object) ['items' => []], + '_links' => (object) [], ]); $result = $this->hydrator->hydrate($request, $response); @@ -106,14 +108,14 @@ public function hydrate_iteratable_collection(): void $response->expects($this->once()) ->method('json') - ->willReturn((object)[ - '_embedded' => (object)['items' => [ - (object)[ + ->willReturn((object) [ + '_embedded' => (object) ['items' => [ + (object) [ 'id' => 'id', 'foo' => 'bar', - ] + ], ]], - '_links' => (object)[] + '_links' => (object) [], ]); $result = $this->hydrator->hydrate($request, $response); @@ -187,6 +189,6 @@ class CustomDecorator implements ResourceDecorator { public static function fromResource($resource): self { - return new self(); + return new self; } }