Completed
Push — master ( 8e286a...78e0f9 )
by Rafał
09:27
created

theFailedItemsExistInTheFailureQueue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SWP\Behat\Contexts;
6
7
use Behat\Behat\Context\Context;
8
use SWP\Behat\Stamp\RedeliveryStamp;
9
use SWP\Bundle\CoreBundle\MessageHandler\Message\ContentPushMessage;
10
use Symfony\Component\ErrorHandler\Exception\FlattenException;
11
use Symfony\Component\Messenger\Envelope;
12
use Symfony\Component\Messenger\Stamp\DelayStamp;
13
use Symfony\Component\Messenger\Stamp\SentToFailureTransportStamp;
14
use Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransport;
15
16
class MessengerContext extends AbstractContext implements Context
17
{
18
    private $failureTransport;
19
20
    public function __construct(
21
        DoctrineTransport $failureTransport
22
    ) {
23
        $this->failureTransport = $failureTransport;
24
    }
25
26
    /**
27
     * @Given the failed items exist in the failure queue
28
     */
29
    public function theFailedItemsExistInTheFailureQueue()
30
    {
31
        $throwable = new \Exception('error');
32
        $envelope = new Envelope(new ContentPushMessage(1, 'some content'));
33
        $flattenedException = class_exists(FlattenException::class) ? FlattenException::createFromThrowable($throwable) : null;
34
        $envelope = $envelope->with(
35
            new SentToFailureTransportStamp('messenger.transport.failed'),
36
            new DelayStamp(0),
37
            new RedeliveryStamp(0, $throwable->getMessage(), $flattenedException)
38
        );
39
40
        $this->failureTransport->send($envelope);
41
    }
42
}
43