|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Mollie\Subscriptions\Test\Integration\Service\Email; |
| 4 | + |
| 5 | +use Mollie\Api\Endpoints\CustomerEndpoint; |
| 6 | +use Mollie\Api\MollieApiClient; |
| 7 | +use Mollie\Api\Resources\Customer; |
| 8 | +use Mollie\Payment\Model\Mollie; |
| 9 | +use Mollie\Payment\Test\Integration\IntegrationTestCase; |
| 10 | +use Mollie\Subscriptions\Api\Data\SubscriptionToProductInterface; |
| 11 | +use Mollie\Subscriptions\Service\Email\SubscriptionToProductEmailVariables; |
| 12 | + |
| 13 | +class SubscriptionToProductEmailVariablesTest extends IntegrationTestCase |
| 14 | +{ |
| 15 | + public function testDoesNotCacheTheCustomer(): void |
| 16 | + { |
| 17 | + $client = new MollieApiClient(); |
| 18 | + |
| 19 | + $client->customers = new class($client) extends CustomerEndpoint { |
| 20 | + private $customers; |
| 21 | + |
| 22 | + public function __construct(MollieApiClient $api) |
| 23 | + { |
| 24 | + $customer1 = new Customer($api); |
| 25 | + $customer1->id = 1; |
| 26 | + |
| 27 | + $customer2 = new Customer($api); |
| 28 | + $customer2->id = 2; |
| 29 | + |
| 30 | + $this->customers = [ |
| 31 | + 1 => $customer1, |
| 32 | + 2 => $customer2 |
| 33 | + ]; |
| 34 | + } |
| 35 | + |
| 36 | + public function get($id, array $parameters = []) |
| 37 | + { |
| 38 | + return $this->customers[$id]; |
| 39 | + } |
| 40 | + }; |
| 41 | + |
| 42 | + $mollieMock = $this->createMock(Mollie::class); |
| 43 | + $mollieMock->method('getMollieApi')->willReturn($client); |
| 44 | + |
| 45 | + /** @var SubscriptionToProductEmailVariables $instance */ |
| 46 | + $instance = $this->objectManager->create(SubscriptionToProductEmailVariables::class, [ |
| 47 | + 'mollie' => $mollieMock, |
| 48 | + ]); |
| 49 | + |
| 50 | + $model1 = $this->objectManager->create(SubscriptionToProductInterface::class); |
| 51 | + $model1->setCustomerId(1); |
| 52 | + |
| 53 | + $model2 = $this->objectManager->create(SubscriptionToProductInterface::class); |
| 54 | + $model2->setCustomerId(2); |
| 55 | + |
| 56 | + $this->assertEquals(1, $instance->getMollieCustomer($model1)->id); |
| 57 | + $this->assertEquals(2, $instance->getMollieCustomer($model2)->id); |
| 58 | + |
| 59 | + $this->assertNotEquals( |
| 60 | + $instance->getMollieCustomer($model1)->id, |
| 61 | + $instance->getMollieCustomer($model2)->id |
| 62 | + ); |
| 63 | + } |
| 64 | +} |
0 commit comments