Skip to content

Commit

Permalink
docs: add mocking resources docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Naoray committed Feb 18, 2025
1 parent f8e0974 commit 4665971
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,53 @@ $client = MollieApiClient::fake([
->create()
]);
```

### Handling Embedded Resources
Simulate HAL+JSON embedded resources using the `_embedded` property:

**Key Concepts**
- Use `MockResponse::resource()` to start building a resource response
- Chain `embed()` calls to add related collections
- Maintain resource relationships with fluent interface

```php
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\RefundCollection;
use Mollie\Api\Resources\ChargebackCollection;

$client = MollieApiClient::fake([
GetPaymentRequest::class => MockResponse::resource(Payment::class)
->with([ // Main resource properties
'resource' => 'payment',
'id' => 'tr_xxxxxxxxxxxx',
'amount' => [
'value' => '20.00',
'currency' => 'EUR'
]
])
->embed(RefundCollection::class) // First embedded collection
->add([
'resource' => 'refund',
'id' => 're_12345',
'amount' => [
'value' => '10.00',
'currency' => 'EUR'
]
])
->embed(ChargebackCollection::class) // Second embedded collection
->add([
'resource' => 'chargeback',
'id' => 'chb_12345',
'amount' => [
'value' => '20.00',
'currency' => 'EUR'
]
])
->create()
]);

// Resulting response will contain:
// - Payment details in main body
// - Refunds in _embedded.refunds
// - Chargebacks in _embedded.chargebacks
```

0 comments on commit 4665971

Please sign in to comment.