Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Commit daa2558

Browse files
author
Jens Schulze
committed
feat(Subscription): add getter for message to message subscription payload
Closes #308
1 parent 74c5a15 commit daa2558

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

src/Model/Subscription/MessageDelivery.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Commercetools\Core\Model\Common\Reference;
99
use Commercetools\Core\Model\Common\DateTimeDecorator;
10+
use Commercetools\Core\Model\Message\Message;
1011
use DateTime;
1112

1213
/**
@@ -54,4 +55,9 @@ public function fieldDefinitions()
5455
);
5556
return $definition;
5657
}
58+
59+
public function getMessage()
60+
{
61+
return Message::fromArray($this->rawData);
62+
}
5763
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
/**
3+
* @author @jayS-de <jens.schulze@commercetools.de>
4+
*/
5+
6+
7+
namespace Commercetools\Core\Model\Subscription;
8+
9+
10+
use Commercetools\Core\Model\Message\Message;
11+
use Commercetools\Core\Model\Message\ProductCreatedMessage;
12+
13+
class DeliveryTest extends \PHPUnit_Framework_TestCase
14+
{
15+
16+
public function testGetGenericMessage()
17+
{
18+
$payload = [
19+
'projectKey' => 'test',
20+
'notificationType' => 'Message',
21+
'resource' => [
22+
'typeId' => 'product',
23+
'id' => '123465678'
24+
],
25+
'id' => 'abcdef',
26+
'version' => 1,
27+
'sequenceNumber' => 1,
28+
'resourceVersion' => 1,
29+
];
30+
31+
$delivery = Delivery::fromArray($payload);
32+
33+
$this->assertInstanceOf(MessageDelivery::class, $delivery);
34+
$this->assertInstanceOf(Message::class, $delivery->getMessage());
35+
}
36+
37+
public function testGetSpecificMessage()
38+
{
39+
$payload = [
40+
'projectKey' => 'test',
41+
'notificationType' => 'Message',
42+
'resource' => [
43+
'typeId' => 'product',
44+
'id' => '123465678'
45+
],
46+
'id' => 'abcdef',
47+
'version' => 1,
48+
'sequenceNumber' => 1,
49+
'resourceVersion' => 1,
50+
'type' => 'ProductCreated',
51+
'productProjection' => []
52+
];
53+
54+
$delivery = Delivery::fromArray($payload);
55+
56+
$this->assertInstanceOf(MessageDelivery::class, $delivery);
57+
$this->assertInstanceOf(ProductCreatedMessage::class, $delivery->getMessage());
58+
}
59+
60+
public function testResourceCreatedPayload()
61+
{
62+
$payload = [
63+
'projectKey' => 'test',
64+
'notificationType' => 'ResourceCreated',
65+
'resource' => [
66+
'typeId' => 'product',
67+
'id' => '123465678'
68+
],
69+
'version' => 1,
70+
];
71+
72+
$delivery = Delivery::fromArray($payload);
73+
74+
$this->assertInstanceOf(ResourceCreatedDelivery::class, $delivery);
75+
}
76+
77+
public function testResourceUpdatedPayload()
78+
{
79+
$payload = [
80+
'projectKey' => 'test',
81+
'notificationType' => 'ResourceUpdated',
82+
'resource' => [
83+
'typeId' => 'product',
84+
'id' => '123465678'
85+
],
86+
'oldVersion' => 1,
87+
'version' => 2,
88+
];
89+
90+
$delivery = Delivery::fromArray($payload);
91+
92+
$this->assertInstanceOf(ResourceUpdatedDelivery::class, $delivery);
93+
}
94+
95+
public function testResourceDeletedPayload()
96+
{
97+
$payload = [
98+
'projectKey' => 'test',
99+
'notificationType' => 'ResourceDeleted',
100+
'resource' => [
101+
'typeId' => 'product',
102+
'id' => '123465678'
103+
],
104+
'version' => 2,
105+
];
106+
107+
$delivery = Delivery::fromArray($payload);
108+
109+
$this->assertInstanceOf(ResourceDeletedDelivery::class, $delivery);
110+
}
111+
}

0 commit comments

Comments
 (0)