|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Loevgaard\DandomainAltapayBundle\Tests\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use GuzzleHttp\Psr7\Request; |
|
6
|
|
|
use GuzzleHttp\Psr7\Response; |
|
7
|
|
|
use GuzzleHttp\Psr7; |
|
8
|
|
|
use Loevgaard\DandomainAltapayBundle\Entity\WebhookExchange; |
|
9
|
|
|
use Loevgaard\DandomainAltapayBundle\Entity\WebhookQueueItem; |
|
10
|
|
|
use PHPUnit\Framework\TestCase; |
|
11
|
|
|
|
|
12
|
|
|
class WebhookQueueItemTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
private $webhookExchange; |
|
15
|
|
|
|
|
16
|
|
|
public function setUp() |
|
17
|
|
|
{ |
|
18
|
|
|
parent::setUp(); |
|
19
|
|
|
|
|
20
|
|
|
$this->webhookExchange = new WebhookExchange('https://www.example.com'); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function testInstantiation() |
|
24
|
|
|
{ |
|
25
|
|
|
$webhookQueueItem = new WebhookQueueItem('content', $this->webhookExchange); |
|
26
|
|
|
$this->assertSame(0, $webhookQueueItem->getId()); |
|
27
|
|
|
$this->assertSame('content', $webhookQueueItem->getContent()); |
|
28
|
|
|
$this->assertSame($this->webhookExchange, $webhookQueueItem->getWebhookExchange()); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testGettersSetters() |
|
32
|
|
|
{ |
|
33
|
|
|
$nextTry = new \DateTimeImmutable(); |
|
34
|
|
|
|
|
35
|
|
|
$response = new Response(); |
|
36
|
|
|
$request = new Request('get', 'https://www.example.com'); |
|
37
|
|
|
|
|
38
|
|
|
$webhookQueueItem = new WebhookQueueItem('content', $this->webhookExchange); |
|
39
|
|
|
$webhookQueueItem |
|
40
|
|
|
->setId(1) |
|
41
|
|
|
->setNextTry($nextTry) |
|
42
|
|
|
->setStatus(WebhookQueueItem::STATUS_SUCCESS) |
|
43
|
|
|
->setError('error') |
|
44
|
|
|
->setTries(1) |
|
45
|
|
|
->setResponse($response) |
|
46
|
|
|
->setRequest($request) |
|
|
|
|
|
|
47
|
|
|
; |
|
48
|
|
|
|
|
49
|
|
|
$this->assertSame(1, $webhookQueueItem->getId()); |
|
50
|
|
|
$this->assertSame($nextTry, $webhookQueueItem->getNextTry()); |
|
51
|
|
|
$this->assertSame(WebhookQueueItem::STATUS_SUCCESS, $webhookQueueItem->getStatus()); |
|
52
|
|
|
$this->assertSame('error', $webhookQueueItem->getError()); |
|
53
|
|
|
$this->assertSame(1, $webhookQueueItem->getTries()); |
|
54
|
|
|
$this->assertSame(Psr7\str($response), $webhookQueueItem->getResponse()); |
|
55
|
|
|
$this->assertSame(Psr7\str($request), $webhookQueueItem->getRequest()); |
|
56
|
|
|
$this->assertCount(3, WebhookQueueItem::getStatuses()); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testMarkAsError() |
|
60
|
|
|
{ |
|
61
|
|
|
$now = new \DateTime(); |
|
62
|
|
|
$expectedNextTry = \DateTimeImmutable::createFromMutable($now)->add(new \DateInterval('PT2M')); |
|
63
|
|
|
|
|
64
|
|
|
$webhookQueueItem = new WebhookQueueItem('content', $this->webhookExchange); |
|
65
|
|
|
$webhookQueueItem->setUpdatedAt($now); |
|
66
|
|
|
$webhookQueueItem->markAsError('test'); |
|
67
|
|
|
|
|
68
|
|
|
$this->assertSame('test', $webhookQueueItem->getError()); |
|
69
|
|
|
$this->assertSame(1, $webhookQueueItem->getTries()); |
|
70
|
|
|
$this->assertSame(WebhookQueueItem::STATUS_ERROR, $webhookQueueItem->getStatus()); |
|
71
|
|
|
$this->assertEquals($expectedNextTry, $webhookQueueItem->getNextTry()); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function testMarkAsErrorWithException() |
|
75
|
|
|
{ |
|
76
|
|
|
$exception = new \Exception('message'); |
|
77
|
|
|
$webhookQueueItem = new WebhookQueueItem('content', $this->webhookExchange); |
|
78
|
|
|
$webhookQueueItem->markAsError($exception); |
|
79
|
|
|
|
|
80
|
|
|
$this->assertInternalType('string', $webhookQueueItem->getError()); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function testUpdateNextTryWithMinutesOver120() |
|
84
|
|
|
{ |
|
85
|
|
|
$now = new \DateTime(); |
|
86
|
|
|
$expectedNextTry = \DateTimeImmutable::createFromMutable($now)->add(new \DateInterval('PT120M')); |
|
87
|
|
|
|
|
88
|
|
|
$exception = new \Exception('message'); |
|
89
|
|
|
$webhookQueueItem = new WebhookQueueItem('content', $this->webhookExchange); |
|
90
|
|
|
$webhookQueueItem->setUpdatedAt($now); |
|
91
|
|
|
$webhookQueueItem->setTries(10); |
|
92
|
|
|
$webhookQueueItem->markAsError($exception); |
|
93
|
|
|
|
|
94
|
|
|
$this->assertEquals($expectedNextTry, $webhookQueueItem->getNextTry()); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: