Passed
Pull Request — master (#2)
by Vincent
04:15 queued 01:21
created

PrimeFailerFactoryTest::setUp()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 13
rs 9.9666
1
<?php
2
3
namespace Bdf\QueueBundle\Tests\FailerFactory;
4
5
use Bdf\Dsn\Dsn;
6
use Bdf\Prime\Prime;
7
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...
8
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...
9
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...
10
use Bdf\Queue\Failer\FailedJobRepositoryAdapter;
11
use Bdf\QueueBundle\FailerFactory\PrimeFailerFactory;
12
use PHPUnit\Framework\TestCase;
13
14
class PrimeFailerFactoryTest extends TestCase
15
{
16
    protected function setUp(): void
17
    {
18
        if (!class_exists(PrimeConnection::class)) {
19
            $this->markTestSkipped('b2pweb/bdf-queue-prime-adapter not installed');
20
        }
21
22
        if (!Prime::isConfigured()) {
23
            Prime::configure([
24
                'connection' => [
25
                    'config' => [
26
                        'test' => [
27
                            'adapter' => 'sqlite',
28
                            'memory' => true
29
                        ],
30
                    ]
31
                ],
32
            ]);
33
        }
34
    }
35
36
    protected function tearDown(): void
37
    {
38
        Prime::configure(null);
39
    }
40
41
    /**
42
     * @return void
43
     */
44
    public function test_scheme()
45
    {
46
        $factory = new PrimeFailerFactory(Prime::service());
47
48
        $this->assertSame('prime', $factory->scheme());
49
    }
50
51
    /**
52
     * @return void
53
     */
54
    public function test_create_success()
55
    {
56
        $factory = new PrimeFailerFactory(Prime::service());
57
58
        $repository = $factory->create(Dsn::parse('prime://test/failed_jobs?maxRows=15'));
59
60
        if (class_exists(DbFailedJobRepository::class)) {
61
            $this->assertInstanceOf(DbFailedJobRepository::class, $repository);
62
            $this->assertEquals(DbFailedJobRepository::make(Prime::service(), ['connection' => 'test', '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

62
            $this->/** @scrutinizer ignore-call */ 
63
                   assertEquals(DbFailedJobRepository::make(Prime::service(), ['connection' => 'test', '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...
63
        } else {
64
            $this->assertInstanceOf(FailedJobRepositoryAdapter::class, $repository);
65
            $this->assertEquals(
66
                FailedJobRepositoryAdapter::adapt(DbFailedJobStorage::make(Prime::service(), ['connection' => 'test', 'table' => 'failed_jobs'], 15)),
67
                $repository
68
            );
69
        }
70
    }
71
72
    /**
73
     * @return void
74
     */
75
    public function test_create_missing_host()
76
    {
77
        $this->expectException(\InvalidArgumentException::class);
78
        $this->expectExceptionMessage('The connection name is required on prime failer DSN');
79
80
        $factory = new PrimeFailerFactory(Prime::service());
81
82
        $factory->create(Dsn::parse('prime:'));
83
    }
84
85
    /**
86
     * @return void
87
     */
88
    public function test_create_missing_table()
89
    {
90
        $this->expectException(\InvalidArgumentException::class);
91
        $this->expectExceptionMessage('The table name is required on prime failer DSN');
92
93
        $factory = new PrimeFailerFactory(Prime::service());
94
95
        $factory->create(Dsn::parse('prime://connection/'));
96
    }
97
}
98