Passed
Push — main ( 3b40c1...b711d3 )
by Peter
07:24
created

CasbinDatabaseAdapterBootstrapperTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace AbterPhp\Framework\Bootstrappers\Vendor;
4
5
use AbterPhp\Framework\Environments\Environment;
6
use Opulence\Databases\Adapters\Pdo\MySql\Driver as MySqlDriver;
7
use Opulence\Ioc\Container;
8
use Opulence\Ioc\IocException;
9
use PHPUnit\Framework\TestCase;
10
11
class CasbinDatabaseAdapterBootstrapperTest extends TestCase
12
{
13
    /** @var CasbinCombinedAdapterBootstrapper */
14
    protected CasbinCombinedAdapterBootstrapper $sut;
15
16
    public function setUp(): void
17
    {
18
        $this->sut = new CasbinCombinedAdapterBootstrapper();
19
    }
20
21
    protected function tearDown(): void
22
    {
23
        Environment::unsetVar('DB_DRIVER');
24
    }
25
26
    public function testRegisterBindingsPostgresTriesToConnectToDB()
27
    {
28
        $this->expectException(IocException::class);
29
30
        $container = new Container();
31
32
        $this->sut->registerBindings($container);
33
    }
34
35
    public function testRegisterBindingsMySQLTriesToConnectToDB()
36
    {
37
        Environment::setVar('DB_DRIVER', MySqlDriver::class);
38
39
        $this->expectException(IocException::class);
40
41
        $container = new Container();
42
43
        $this->sut->registerBindings($container);
44
    }
45
46
    public function testRegisterBindingsThrowsInvalidDriverException()
47
    {
48
        Environment::setVar('DB_DRIVER', MySqlDriver::class);
49
50
        $this->expectException(IocException::class);
51
52
        $this->getExpectedExceptionMessageRegExp(MySqlDriver::class);
0 ignored issues
show
Unused Code introduced by
The call to PHPUnit\Framework\TestCa...xceptionMessageRegExp() has too many arguments starting with Opulence\Databases\Adapt...Pdo\MySql\Driver::class. ( Ignorable by Annotation )

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

52
        $this->/** @scrutinizer ignore-call */ 
53
               getExpectedExceptionMessageRegExp(MySqlDriver::class);

This check compares calls to functions or methods with their respective definitions. If the call has more 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...
53
54
        $container = new Container();
55
56
        $this->sut->registerBindings($container);
57
    }
58
}
59