Completed
Push — master ( 20b2e7...221c15 )
by Tom
16:49 queued 06:52
created

Options/ConfigurationOptionsTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace DoctrineORMModuleTest\Options;
4
5
use PHPUnit\Framework\TestCase;
6
use DoctrineORMModule\Options\Configuration;
7
use Doctrine\ORM\Repository\DefaultRepositoryFactory;
8
9
class ConfigurationOptionsTest extends TestCase
10
{
11
    public function testSetGetNamingStrategy()
12
    {
13
        $options = new Configuration();
14
        $options->setNamingStrategy(null);
15
        $this->assertNull($options->getNamingStrategy());
16
17
        $options->setNamingStrategy('test');
18
        $this->assertSame('test', $options->getNamingStrategy());
19
20
        $namingStrategy = $this->createMock(\Doctrine\ORM\Mapping\NamingStrategy::class);
21
        $options->setNamingStrategy($namingStrategy);
22
        $this->assertSame($namingStrategy, $options->getNamingStrategy());
23
24
        $this->expectException(\Zend\Stdlib\Exception\InvalidArgumentException::class);
25
        $options->setNamingStrategy(new \stdClass());
26
    }
27
28
    public function testSetGetQuoteStrategy()
29
    {
30
        $options = new Configuration();
31
        $options->setQuoteStrategy(null);
32
        $this->assertNull($options->getQuoteStrategy());
33
34
        $options->setQuoteStrategy('test');
35
        $this->assertSame('test', $options->getQuoteStrategy());
36
37
        $quoteStrategy = $this->createMock(\Doctrine\ORM\Mapping\QuoteStrategy::class);
38
        $options->setQuoteStrategy($quoteStrategy);
39
        $this->assertSame($quoteStrategy, $options->getQuoteStrategy());
40
41
        $this->expectException(\Zend\Stdlib\Exception\InvalidArgumentException::class);
42
        $options->setQuoteStrategy(new \stdClass());
43
    }
44
45
    public function testSetRepositoryFactory()
46
    {
47
        $options = new Configuration();
48
        $options->setRepositoryFactory(null);
49
        $this->assertNull($options->getRepositoryFactory());
50
51
        $options->setRepositoryFactory('test');
52
        $this->assertSame('test', $options->getRepositoryFactory());
53
54
        $repositoryFactory = new DefaultRepositoryFactory();
55
        $options->setRepositoryFactory($repositoryFactory);
56
        $this->assertSame($repositoryFactory, $options->getRepositoryFactory());
57
58
        $this->expectException(\Zend\Stdlib\Exception\InvalidArgumentException::class);
59
        $options->setRepositoryFactory(new \stdClass());
60
    }
61
62
    public function testSetGetEntityListenerResolver()
63
    {
64
        $options = new Configuration();
65
66
        $options->setEntityListenerResolver(null);
67
        $this->assertNull($options->getEntityListenerResolver());
68
69
        $options->setEntityListenerResolver('test');
70
        $this->assertSame('test', $options->getEntityListenerResolver());
71
72
        $entityListenerResolver = $this->createMock(\Doctrine\ORM\Mapping\EntityListenerResolver::class);
73
74
        $options->setEntityListenerResolver($entityListenerResolver);
75
        $this->assertSame($entityListenerResolver, $options->getEntityListenerResolver());
76
77
        $this->expectException(\Zend\Stdlib\Exception\InvalidArgumentException::class);
78
        $options->setEntityListenerResolver(new \stdClass());
0 ignored issues
show
new \stdClass() is of type object<stdClass>, but the function expects a string|null|object<Doctr...EntityListenerResolver>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
79
    }
80
}
81