Completed
Push — 1.x ( c2f735...1d81a7 )
by Kevin
12s queued 11s
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\TestTransportFactory;
8
use Zenstruck\Messenger\Test\Transport\TestTransportRegistry;
9
10
/**
11
 * @author Kevin Bond <[email protected]>
12
 */
13
trait InteractsWithMessenger
14
{
15
    /**
16
     * @internal
17
     * @after
18
     */
19
    final protected function _resetTransports(): void
20
    {
21
        TestTransportFactory::reset();
22
    }
23
24
    final protected function messenger(?string $transport = null): TestTransport
25
    {
26
        if (!$this instanceof KernelTestCase) {
27
            throw new \LogicException(\sprintf('The %s trait can only be used with %s.', __TRAIT__, KernelTestCase::class));
28
        }
29
30
        if (!self::$container) {
31
            self::bootKernel();
32
        }
33
34
        if (!self::$container->has(TestTransportRegistry::class)) {
35
            throw new \LogicException('Cannot access transport - is ZenstruckMessengerTestBundle enabled in your test environment?');
36
        }
37
38
        return self::$container->get(TestTransportRegistry::class)->get($transport);
39
    }
40
}
41