Passed
Pull Request — master (#2)
by Vincent
03:17
created

BdfQueueBundleTest::test_kernel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
namespace Bdf\QueueBundle\Tests;
4
5
require_once __DIR__.'/TestKernel.php';
6
7
use Bdf\Queue\Console\Command\BindCommand;
8
use Bdf\Queue\Console\Command\ConsumeCommand;
9
use Bdf\Queue\Console\Command\Failer\AbstractFailerCommand;
10
use Bdf\Queue\Console\Command\Failer\DeleteCommand;
11
use Bdf\Queue\Console\Command\Failer\FlushCommand;
12
use Bdf\Queue\Console\Command\Failer\ForgetCommand;
13
use Bdf\Queue\Console\Command\Failer\RetryCommand;
14
use Bdf\Queue\Console\Command\Failer\ShowCommand;
15
use Bdf\Queue\Console\Command\InfoCommand;
16
use Bdf\Queue\Console\Command\ProduceCommand;
17
use Bdf\Queue\Console\Command\SetupCommand;
18
use Bdf\Queue\Destination\DestinationInterface;
19
use Bdf\Queue\Destination\DestinationManager;
20
use Bdf\Queue\Failer\DbFailedJobRepository;
0 ignored issues
show
Bug introduced by
The type Bdf\Queue\Failer\DbFailedJobRepository was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
use Bdf\Queue\Failer\DbFailedJobStorage;
0 ignored issues
show
Bug introduced by
The type Bdf\Queue\Failer\DbFailedJobStorage was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
use Bdf\Queue\Failer\FailedJobRepositoryAdapter;
23
use Bdf\Queue\Failer\FailedJobStorageInterface;
24
use Bdf\Queue\Failer\MemoryFailedJobRepository;
25
use Bdf\QueueBundle\BdfQueueBundle;
26
use PHPUnit\Framework\TestCase;
27
use Symfony\Bundle\FrameworkBundle\Console\Application;
28
use Symfony\Component\DependencyInjection\ContainerBuilder;
29
30
/**
31
 * BdfSerializerBundleTest
32
 */
33
class BdfQueueBundleTest extends TestCase
34
{
35
    public function test_default_config()
36
    {
37
        $builder = $this->createMock(ContainerBuilder::class);
38
39
        $bundle = new BdfQueueBundle();
40
41
        $this->assertNull($bundle->build($builder));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $bundle->build($builder) targeting Bdf\QueueBundle\BdfQueueBundle::build() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
42
    }
43
44
    /**
45
     *
46
     */
47
    public function test_kernel()
48
    {
49
        $kernel = new \TestKernel();
50
        $kernel->boot();
51
52
        $this->assertInstanceOf(DestinationManager::class, $kernel->getContainer()->get('bdf_queue.destination_manager'));
53
        $this->assertSame($kernel->getContainer()->get('bdf_queue.destination_manager'), $kernel->getContainer()->get(DestinationManager::class));
54
    }
55
56
    /**
57
     *
58
     */
59
    public function test_functional()
60
    {
61
        $kernel = new \TestKernel();
62
        $kernel->boot();
63
64
        /** @var DestinationManager $destinations */
65
        $destinations = $kernel->getContainer()->get('bdf_queue.destination_manager');
66
        $destination = $destinations->create('b2p_bus');
67
68
        $this->assertInstanceOf(DestinationInterface::class, $destination);
69
    }
70
71
    /**
72
     *
73
     */
74
    public function test_connection_options()
75
    {
76
        $kernel = new \TestKernel();
77
        $kernel->boot();
78
79
        $configs = $kernel->getContainer()->getParameter('bdf_queue.connections');
80
81
        $this->assertEquals([
82
            'gearman' => [
83
                'driver' => null,
84
                'host' => null,
85
                'serializer' => ['id' => 'native'],
86
                'queue' => null,
87
                'url' => 'gearman://127.0.0.1',
88
                'options' => ['client_timeout' => 1],
89
                'vendor' => null,
90
                'port' => null,
91
                'user' => null,
92
                'password' => null,
93
                'connection_factory' => null,
94
            ]
95
        ], $configs);
96
    }
97
98
    /**
99
     *
100
     */
101
    public function test_destination_options()
102
    {
103
        $kernel = new \TestKernel();
104
        $kernel->boot();
105
106
        $configs = $kernel->getContainer()->getParameter('bdf_queue.destinations');
107
108
        $this->assertEquals([
109
            'b2p_bus' => 'queue://gearman/b2p_bus'
110
        ], $configs);
111
    }
112
113
    /**
114
     *
115
     */
116
    public function test_commands()
117
    {
118
        $kernel = new \TestKernel();
119
        $kernel->boot();
120
        $console = new Application($kernel);
121
122
        $this->assertInstanceOf(BindCommand::class, $console->get('queue:bind'));
123
        $this->assertInstanceOf(ConsumeCommand::class, $console->get('queue:consume'));
124
        $this->assertInstanceOf(InfoCommand::class, $console->get('queue:info'));
125
        $this->assertInstanceOf(ProduceCommand::class, $console->get('queue:produce'));
126
        $this->assertInstanceOf(SetupCommand::class, $console->get('queue:setup'));
127
128
        $this->assertInstanceOf(DeleteCommand::class, $console->get('queue:failer:delete'));
129
        $this->assertInstanceOf(RetryCommand::class, $console->get('queue:failer:retry'));
130
        $this->assertInstanceOf(ShowCommand::class, $console->get('queue:failer:show'));
131
        $this->assertInstanceOf(FlushCommand::class, $console->get('queue:failer:flush'));
132
        $this->assertInstanceOf(ForgetCommand::class, $console->get('queue:failer:forget'));
133
    }
134
135
    /**
136
     * @return void
137
     */
138
    public function test_failer()
139
    {
140
        $kernel = new \TestKernel();
141
        $kernel->boot();
142
        $console = new Application($kernel);
143
144
        $command = $console->get('queue:failer:delete');
145
146
        $r = new \ReflectionProperty(AbstractFailerCommand::class, 'repository');
147
        $r->setAccessible(true);
148
149
        /** @var FailedJobStorageInterface $failer */
150
        $failer = $r->getValue($command);
151
152
        $this->assertInstanceOf(MemoryFailedJobRepository::class, $failer);
153
    }
154
155
    /**
156
     * @return void
157
     */
158
    public function test_custom_failer()
159
    {
160
        $kernel = new \TestKernel(__DIR__ . '/Fixtures/conf_with_custom_failer.yaml');
161
        $kernel->boot();
162
        $console = new Application($kernel);
163
164
        $command = $console->get('queue:failer:delete');
165
166
        $r = new \ReflectionProperty(AbstractFailerCommand::class, 'repository');
167
        $r->setAccessible(true);
168
169
        /** @var FailedJobStorageInterface $failer */
170
        $failer = $r->getValue($command);
171
172
        $this->assertInstanceOf(MemoryFailedJobRepository::class, $failer);
173
        $this->assertSame($failer, $kernel->getContainer()->get('foo'));
174
    }
175
}
176