Completed
Pull Request — master (#470)
by
unknown
05:25
created

testSetRepositoryFactory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace DoctrineORMModuleTest\Options;
21
22
use PHPUnit_Framework_TestCase as TestCase;
23
use DoctrineORMModule\Options\Configuration;
24
use Doctrine\ORM\Repository\DefaultRepositoryFactory;
25
26
class ConfigurationOptionsTest extends TestCase
27
{
28
    public function testSetGetNamingStrategy()
29
    {
30
        $options = new Configuration();
31
        $options->setNamingStrategy(null);
32
        $this->assertNull($options->getNamingStrategy());
33
34
        $options->setNamingStrategy('test');
35
        $this->assertSame('test', $options->getNamingStrategy());
36
37
        $namingStrategy = $this->getMock('Doctrine\ORM\Mapping\NamingStrategy');
38
        $options->setNamingStrategy($namingStrategy);
39
        $this->assertSame($namingStrategy, $options->getNamingStrategy());
40
41
        $this->setExpectedException('Zend\Stdlib\Exception\InvalidArgumentException');
42
        $options->setNamingStrategy(new \stdClass());
0 ignored issues
show
Documentation introduced by
new \stdClass() is of type object<stdClass>, but the function expects a string|null|object<Doctr...Mapping\NamingStrategy>.

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...
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->setExpectedException('Zend\Stdlib\Exception\InvalidArgumentException');
59
        $options->setRepositoryFactory(new \stdClass());
0 ignored issues
show
Documentation introduced by
new \stdClass() is of type object<stdClass>, but the function expects a string|null|object<Doctr...tory\RepositoryFactory>.

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...
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->getMock('Doctrine\ORM\Mapping\EntityListenerResolver');
73
74
        $options->setEntityListenerResolver($entityListenerResolver);
75
        $this->assertSame($entityListenerResolver, $options->getEntityListenerResolver());
76
77
        $this->setExpectedException('Zend\Stdlib\Exception\InvalidArgumentException');
78
        $options->setEntityListenerResolver(new \stdClass());
0 ignored issues
show
Documentation introduced by
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
    public function testDefaultQueryHint()
82
    {
83
        $options = new Configuration();
84
85
        $options->setDefaultQueryHints(['test']);
0 ignored issues
show
Bug introduced by
The method setDefaultQueryHints() does not seem to exist on object<DoctrineORMModule\Options\Configuration>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
86
        $this->assertSame(['test'], $options->getDefaultQueryHints());
0 ignored issues
show
Bug introduced by
The method getDefaultQueryHints() does not seem to exist on object<DoctrineORMModule\Options\Configuration>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
87
    }
88
}
89