Completed
Pull Request — master (#1340)
by Maksim
06:56
created

PagerPersisterRegistryTest::testShouldBeFinal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the FOSElasticaBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\ElasticaBundle\Persister;
13
14
use Symfony\Component\DependencyInjection\Container;
15
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
16
17
class PagerPersisterRegistryTest extends \PHPUnit_Framework_TestCase
18
{
19
    public function testShouldImplementContainerAwareInterface()
20
    {
21
        $rc = new \ReflectionClass(PagerPersisterRegistry::class);
22
23
        $this->assertTrue($rc->implementsInterface(ContainerAwareInterface::class));
24
    }
25
26
    public function testShouldBeFinal()
27
    {
28
        $rc = new \ReflectionClass(PagerPersisterRegistry::class);
29
30
        $this->assertTrue($rc->isFinal());
31
    }
32
33
    public function testCouldBeConstructedWithNameToServiceIdMap()
34
    {
35
        new PagerPersisterRegistry([]);
36
    }
37
38 View Code Duplication
    public function testThrowsIfThereIsNoSuchEntryInNameToServiceIdMap()
39
    {
40
        $container = new Container();
41
42
        $registry = new PagerPersisterRegistry([
43
            'the_name' => 'the_service_id',
44
        ]);
45
        $registry->setContainer($container);
46
47
        $this->setExpectedException(\InvalidArgumentException::class, 'No pager persister was registered for the give name "the_other_name".');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
48
        $registry->getPagerPersister('the_other_name');
49
    }
50
51 View Code Duplication
    public function testThrowsIfRelatedServiceDoesNotImplementPagerPersisterInterface()
52
    {
53
        $container = new Container();
54
        $container->set('the_service_id', new \stdClass());
55
56
        $registry = new PagerPersisterRegistry([
57
            'the_name' => 'the_service_id',
58
        ]);
59
        $registry->setContainer($container);
60
61
        $this->setExpectedException(\LogicException::class, 'The pager provider service "the_service_id" must implement "FOS\ElasticaBundle\Persister\PagerPersisterInterface" interface but it is an instance of "stdClass" class.');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
62
        $registry->getPagerPersister('the_name');
63
    }
64
65 View Code Duplication
    public function testThrowsIfThereIsServiceWithSuchId()
66
    {
67
        $container = new Container();
68
69
        $registry = new PagerPersisterRegistry([
70
            'the_name' => 'the_service_id',
71
        ]);
72
        $registry->setContainer($container);
73
74
        $this->setExpectedException(\LogicException::class, 'You have requested a non-existent service "the_service_id".');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
75
        $registry->getPagerPersister('the_name');
76
    }
77
78
    public function testShouldReturnPagerPersisterByGivenName()
79
    {
80
        $pagerPersisterMock = $this->createPagerPersisterMock();
81
82
        $container = new Container();
83
        $container->set('the_service_id', $pagerPersisterMock);
84
85
        $registry = new PagerPersisterRegistry([
86
            'the_name' => 'the_service_id',
87
        ]);
88
        $registry->setContainer($container);
89
90
        $actualPagerPersister = $registry->getPagerPersister('the_name');
91
92
        $this->assertSame($pagerPersisterMock, $actualPagerPersister);
93
    }
94
95
    /**
96
     * @return PagerPersisterInterface|\PHPUnit_Framework_MockObject_MockObject
97
     */
98
    private function createPagerPersisterMock()
99
    {
100
        return $this->getMock(PagerPersisterInterface::class);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0; use createMock() or getMockBuilder() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
101
    }
102
}
103