Passed
Push — 1.x ( 774941...781dbf )
by Kevin
03:22 queued 01:44
created

InteractsWithMessenger::_resetTransports()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Zenstruck\Messenger\Test;
4
5
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
6
use Zenstruck\Messenger\Test\Transport\TestTransport;
7
use Zenstruck\Messenger\Test\Transport\TestTransportRegistry;
8
9
/**
10
 * @author Kevin Bond <[email protected]>
11
 */
12
trait InteractsWithMessenger
13
{
14
    /**
15
     * @internal
16
     * @after
17
     */
18
    final protected static function _resetMessengerTransports(): void
19
    {
20
        TestTransport::resetAll();
21
    }
22
23
    final protected function messenger(?string $transport = null): TestTransport
24
    {
25
        if (!$this instanceof KernelTestCase) {
26
            throw new \LogicException(\sprintf('The %s trait can only be used with %s.', __TRAIT__, KernelTestCase::class));
27
        }
28
29
        if (!self::$container) {
30
            self::bootKernel();
31
        }
32
33
        if (!self::$container->has(TestTransportRegistry::class)) {
34
            throw new \LogicException('Cannot access transport - is ZenstruckMessengerTestBundle enabled in your test environment?');
35
        }
36
37
        return self::$container->get(TestTransportRegistry::class)->get($transport);
38
    }
39
}
40