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

WithPrimeTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 38
c 1
b 0
f 0
dl 0
loc 90
rs 10
wmc 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 2
A test_host_missing() 0 7 1
A isPrimeFailer() 0 14 3
A test_prime_failer() 0 24 2
A test_init_command() 0 7 1
A test_table_name_missing() 0 7 1
1
<?php
2
namespace Bdf\QueueBundle\Tests;
3
4
require_once __DIR__.'/TestKernel.php';
5
6
use Bdf\Queue\Connection\Prime\PrimeConnection;
0 ignored issues
show
Bug introduced by
The type Bdf\Queue\Connection\Prime\PrimeConnection 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...
7
use Bdf\Queue\Console\Command\Failer\AbstractFailerCommand;
8
use Bdf\Queue\Console\Command\Failer\InitCommand;
0 ignored issues
show
Bug introduced by
The type Bdf\Queue\Console\Command\Failer\InitCommand 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...
9
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...
10
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...
11
use Bdf\Queue\Failer\FailedJobRepositoryAdapter;
12
use Bdf\Queue\Failer\FailedJobStorageInterface;
13
use PHPUnit\Framework\TestCase;
14
use Symfony\Bundle\FrameworkBundle\Console\Application;
15
16
class WithPrimeTest extends TestCase
17
{
18
    protected function setUp(): void
19
    {
20
        if (!class_exists(PrimeConnection::class)) {
21
            $this->markTestSkipped('b2pweb/bdf-queue-prime-adapter not installed');
22
        }
23
    }
24
25
    /**
26
     * @return void
27
     */
28
    public function test_prime_failer()
29
    {
30
        $kernel = new \TestKernel(__DIR__ . '/Fixtures/conf_with_prime_failer.yaml');
31
        $kernel->boot();
32
        $console = new Application($kernel);
33
34
        $command = $console->get('queue:failer:delete');
35
36
        $r = new \ReflectionProperty(AbstractFailerCommand::class, 'repository');
37
        $r->setAccessible(true);
38
39
        /** @var FailedJobStorageInterface $failer */
40
        $failer = $r->getValue($command);
41
42
        $this->assertTrue($this->isPrimeFailer($failer));
43
44
        if (class_exists(DbFailedJobRepository::class)) {
45
            $this->assertInstanceOf(DbFailedJobRepository::class, $failer);
46
            $this->assertEquals(DbFailedJobRepository::make($kernel->getContainer()->get('prime'), ['connection' => 'my_connection', 'table' => 'failed_jobs'], 15));
0 ignored issues
show
Bug introduced by
The call to PHPUnit\Framework\Assert::assertEquals() has too few arguments starting with actual. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
            $this->/** @scrutinizer ignore-call */ 
47
                   assertEquals(DbFailedJobRepository::make($kernel->getContainer()->get('prime'), ['connection' => 'my_connection', 'table' => 'failed_jobs'], 15));

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
47
        } else {
48
            $this->assertInstanceOf(FailedJobRepositoryAdapter::class, $failer);
49
            $this->assertEquals(
50
                FailedJobRepositoryAdapter::adapt(DbFailedJobStorage::make($kernel->getContainer()->get('prime'), ['connection' => 'my_connection', 'table' => 'failed_jobs'], 15)),
51
                $failer
52
            );
53
        }
54
    }
55
56
    /**
57
     * @return void
58
     */
59
    public function test_host_missing()
60
    {
61
        $this->expectException(\InvalidArgumentException::class);
62
        $this->expectExceptionMessage('The connection name is required on prime failer DSN');
63
64
        $kernel = new \TestKernel(__DIR__ . '/Fixtures/conf_with_prime_failer_missing_host.yaml');
65
        $kernel->boot();
66
    }
67
68
    /**
69
     * @return void
70
     */
71
    public function test_table_name_missing()
72
    {
73
        $this->expectException(\InvalidArgumentException::class);
74
        $this->expectExceptionMessage('The table name is required on prime failer DSN');
75
76
        $kernel = new \TestKernel(__DIR__ . '/Fixtures/conf_with_prime_failer_missing_table.yaml');
77
        $kernel->boot();
78
    }
79
80
    /**
81
     *
82
     */
83
    public function test_init_command()
84
    {
85
        $kernel = new \TestKernel(__DIR__ . '/Fixtures/conf_with_prime_failer.yaml');
86
        $kernel->boot();
87
        $console = new Application($kernel);
88
89
        $this->assertInstanceOf(InitCommand::class, $console->get('queue:prime:failer:init'));
90
    }
91
92
    private function isPrimeFailer($storage): bool
93
    {
94
        if ($storage instanceof DbFailedJobRepository) {
95
            return true;
96
        }
97
98
        if ($storage instanceof FailedJobRepositoryAdapter) {
99
            $r = new \ReflectionProperty(FailedJobRepositoryAdapter::class, 'storage');
100
            $r->setAccessible(true);
101
102
            return $r->getValue($storage) instanceof DbFailedJobStorage;
103
        }
104
105
        return false;
106
    }
107
}
108