Skip to content

Commit 7f6f9b8

Browse files
Merge pull request #49 from mollie/release/1.10.3
Release/1.10.3
2 parents f0c9967 + 26e80c2 commit 7f6f9b8

8 files changed

+152
-11
lines changed

Model/SubscriptionToProductRepository.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public function delete(
264264
) {
265265
try {
266266
$subscriptionToProductModel = $this->subscriptionToProductFactory->create();
267-
$this->resource->load($subscriptionToProductModel, $subscriptionToProduct->getSubscriptionToProductId());
267+
$this->resource->load($subscriptionToProductModel, $subscriptionToProduct->getEntityId());
268268
$this->resource->delete($subscriptionToProductModel);
269269
} catch (\Exception $exception) {
270270
throw new CouldNotDeleteException(__(

Service/Email/SubscriptionToProductEmailVariables.php

+10-7
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ class SubscriptionToProductEmailVariables
2121
private $mollie;
2222

2323
/**
24-
* @var Customer|null
24+
* @var Customer[]
2525
*/
26-
private $customer;
26+
private $customers = [];
2727

2828
/**
2929
* @var ProductRepositoryInterface
@@ -52,14 +52,17 @@ public function __construct(
5252

5353
public function getMollieCustomer(SubscriptionToProductInterface $subscriptionToProduct): Customer
5454
{
55-
if ($this->customer) {
56-
return $this->customer;
55+
$storeId = $subscriptionToProduct->getStoreId();
56+
$customerId = $subscriptionToProduct->getCustomerId();
57+
$key = $storeId . '-' . $customerId;
58+
if (array_key_exists($key, $this->customers)) {
59+
return $this->customers[$key];
5760
}
5861

59-
$api = $this->getApiForStore($subscriptionToProduct->getStoreId());
62+
$api = $this->getApiForStore($storeId);
6063

61-
$this->customer = $api->customers->get($subscriptionToProduct->getCustomerId());
62-
return $this->customer;
64+
$this->customers[$key] = $api->customers->get($customerId);
65+
return $this->customers[$key];
6366
}
6467

6568
public function get(SubscriptionToProductInterface $subscriptionToProduct): array

Test/Integration/Cron/SendPrePaymentReminderEmailCronTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,27 @@
22

33
namespace Mollie\Subscriptions\Test\Integration\Cron;
44

5+
use Magento\Framework\App\Config\ScopeConfigInterface;
56
use Mollie\Payment\Test\Integration\IntegrationTestCase;
67
use Mollie\Subscriptions\Api\Data\SubscriptionToProductInterface;
78
use Mollie\Subscriptions\Api\SubscriptionToProductRepositoryInterface;
89
use Mollie\Subscriptions\Cron\SendPrePaymentReminderEmailCron;
10+
use Mollie\Subscriptions\Model\Adminhtml\Backend\SaveCronValue;
911
use Mollie\Subscriptions\Service\Email\SendPrepaymentReminderEmail;
1012
use Mollie\Subscriptions\Service\Mollie\CheckIfSubscriptionIsActive;
1113

1214
class SendPrePaymentReminderEmailCronTest extends IntegrationTestCase
1315
{
16+
public function testHasADefaultScheduleAvailable(): void
17+
{
18+
/** @var ScopeConfigInterface $config */
19+
$config = $this->objectManager->get(ScopeConfigInterface::class);
20+
21+
$value = $config->getValue(SaveCronValue::CRON_SCHEDULE_PATH);
22+
23+
$this->assertEquals('0 1 * * *', $value);
24+
}
25+
1426
/**
1527
* @magentoDbIsolation enabled
1628
* @magentoConfigFixture default_store mollie_subscriptions/prepayment_reminder/enabled 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Mollie\Subscriptions\Test\Integration\Model;
4+
5+
use Mollie\Payment\Test\Integration\IntegrationTestCase;
6+
use Mollie\Subscriptions\Api\Data\SubscriptionToProductInterface;
7+
use Mollie\Subscriptions\Api\SubscriptionToProductRepositoryInterface;
8+
9+
class SubscriptionToProductRepositoryTest extends IntegrationTestCase
10+
{
11+
public function testCanSaveAModel(): void
12+
{
13+
$model = $this->getModel();
14+
15+
/** @var SubscriptionToProductRepositoryInterface $instance */
16+
$instance = $this->objectManager->get(SubscriptionToProductRepositoryInterface::class);
17+
18+
$result = $instance->save($model);
19+
20+
$this->assertNotEmpty($result->getEntityId());
21+
$this->assertIsNumeric($result->getEntityId());
22+
}
23+
24+
public function testCanDeleteModel(): void
25+
{
26+
$model = $this->getModel();
27+
28+
/** @var SubscriptionToProductRepositoryInterface $instance */
29+
$instance = $this->objectManager->get(SubscriptionToProductRepositoryInterface::class);
30+
31+
$result = $instance->save($model);
32+
33+
$this->assertTrue($instance->delete($result));
34+
}
35+
36+
public function testCanDeleteBySubscriptionId(): void
37+
{
38+
$model = $this->getModel();
39+
40+
/** @var SubscriptionToProductRepositoryInterface $instance */
41+
$instance = $this->objectManager->get(SubscriptionToProductRepositoryInterface::class);
42+
43+
$result = $instance->save($model);
44+
45+
$this->assertTrue(
46+
$instance->deleteBySubscriptionId(
47+
(int)$result->getCustomerId(),
48+
(int)$result->getSubscriptionId()
49+
)
50+
);
51+
}
52+
53+
public function getModel(): SubscriptionToProductInterface
54+
{
55+
/** @var SubscriptionToProductInterface $model */
56+
$model = $this->objectManager->create(SubscriptionToProductInterface::class);
57+
$model->setProductId(1);
58+
$model->setSubscriptionId(1);
59+
$model->setCustomerId(1);
60+
61+
return $model;
62+
}
63+
}

Test/Integration/Model/Test/ExtensionStatusTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Mollie\Subscriptions\Test\Integration\Model\Test;
99

10-
use Magento\Framework\App\ObjectManager;
1110
use Mollie\Payment\Test\Integration\IntegrationTestCase;
1211
use Mollie\Subscriptions\Config;
1312
use Mollie\Subscriptions\Service\Test\ExtensionStatus;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
}

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "mollie/magento2-subscriptions",
33
"description": "Mollie subscriptions extension for Magento 2",
44
"type": "magento2-module",
5-
"version": "1.10.2",
5+
"version": "1.10.3",
66
"license": [
77
"OSL-3.0",
88
"AFL-3.0"

etc/config.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<default>
1111
<mollie_subscriptions>
1212
<general>
13-
<version>v1.10.2</version>
13+
<version>v1.10.3</version>
1414
<enable>0</enable>
1515
<debug>0</debug>
1616
</general>

0 commit comments

Comments
 (0)