Code Duplication    Length = 51-51 lines in 2 locations

tests/FwlibTest/Base/ServiceContainerAwareTraitTest.php 1 location

@@ 13-63 (lines=51) @@
10
 * @copyright   Copyright 2014-2015 Fwolf
11
 * @license     http://www.gnu.org/licenses/lgpl.html LGPL-3.0+
12
 */
13
class ServiceContainerAwareTraitTest extends PHPUnitTestCase
14
{
15
    /**
16
     * @return MockObject | ServiceContainerAwareTrait
17
     */
18
    protected function buildMock()
19
    {
20
        $serviceContainerAware = $this->getMockBuilder(
21
            ServiceContainerAwareTrait::class
22
        )
23
            ->disableOriginalConstructor()
24
            ->setMethods(null)
25
            ->getMockForTrait();
26
27
        return $serviceContainerAware;
28
    }
29
30
31
    public function testGetWithServiceContainerPropertyUnset()
32
    {
33
        $serviceContainerAware = $this->buildMock();
34
35
        $this->reflectionCall($serviceContainerAware, 'getServiceContainer');
36
        $this->assertNull(
37
            $this->reflectionGet($serviceContainerAware, 'serviceContainer')
38
        );
39
    }
40
41
42
    public function testGetWithServiceContainerPropertySet()
43
    {
44
        $serviceContainerAware = $this->buildMock();
45
46
        $serviceContainer = ServiceContainer::getInstance();
47
        $serviceContainer->register('FooException', new \Exception);
48
49
        $serviceContainerAware->setServiceContainer($serviceContainer);
50
51
        $this->assertInstanceOf(
52
            'Exception',
53
            $this->reflectionCall(
54
                $this->reflectionCall(
55
                    $serviceContainerAware,
56
                    'getServiceContainer'
57
                ),
58
                'get',
59
                ['FooException']
60
            )
61
        );
62
    }
63
}
64

tests/FwlibTest/Util/UtilContainerAwareTraitTest.php 1 location

@@ 13-63 (lines=51) @@
10
 * @copyright   Copyright 2015 Fwolf
11
 * @license     http://www.gnu.org/licenses/lgpl.html LGPL-3.0+
12
 */
13
class UtilContainerAwareTraitTest extends PHPUnitTestCase
14
{
15
    /**
16
     * @return MockObject | UtilContainerAwareTrait
17
     */
18
    protected function buildMock()
19
    {
20
        $utilContainerAware = $this->getMockBuilder(
21
            UtilContainerAwareTrait::class
22
        )
23
            ->disableOriginalConstructor()
24
            ->setMethods(null)
25
            ->getMockForTrait();
26
27
        return $utilContainerAware;
28
    }
29
30
31
    public function testGetWithUtilContainerPropertyUnset()
32
    {
33
        $utilContainerAware = $this->buildMock();
34
35
        $this->reflectionCall($utilContainerAware, 'getUtilContainer');
36
        $this->assertNull(
37
            $this->reflectionGet($utilContainerAware, 'utilContainer')
38
        );
39
    }
40
41
42
    public function testGetWithUtilContainerPropertySet()
43
    {
44
        $utilContainerAware = $this->buildMock();
45
46
        $utilContainer = UtilContainer::getInstance();
47
        $utilContainer->register('FooUtil', new \Exception);
48
49
        $utilContainerAware->setUtilContainer($utilContainer);
50
51
        $this->assertInstanceOf(
52
            'Exception',
53
            $this->reflectionCall(
54
                $this->reflectionCall(
55
                    $utilContainerAware,
56
                    'getUtilContainer'
57
                ),
58
                'get',
59
                ['FooUtil']
60
            )
61
        );
62
    }
63
}
64