Completed
Push — master ( aaaad2...314663 )
by Craig
06:30
created

BlockFactoryApiTest::testUnsetModuleException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
rs 10
1
<?php
2
3
/*
4
 * This file is part of the Zikula package.
5
 *
6
 * Copyright Zikula Foundation - http://zikula.org/
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 Zikula\BlocksModule\Tests\Api;
13
14
use Symfony\Component\DependencyInjection\Container;
15
use Symfony\Component\DependencyInjection\ContainerInterface;
16
use Zikula\BlocksModule\AbstractBlockHandler;
17
use Zikula\BlocksModule\Api\ApiInterface\BlockFactoryApiInterface;
18
use Zikula\BlocksModule\Api\BlockFactoryApi;
19
use Zikula\BlocksModule\BlockHandlerInterface;
20
use Zikula\BlocksModule\Helper\ServiceNameHelper;
21
use Zikula\BlocksModule\Tests\Api\Fixture\AcmeFooModule;
22
use Zikula\BlocksModule\Tests\Api\Fixture\BarBlock;
23
use Zikula\BlocksModule\Tests\Api\Fixture\FooBlock;
24
use Zikula\BlocksModule\Tests\Api\Fixture\WrongInterfaceBlock;
25
use Zikula\Common\Translator\IdentityTranslator;
26
27
class BlockFactoryApiTest extends \PHPUnit_Framework_TestCase
28
{
29
    /**
30
     * @var BlockFactoryApiInterface
31
     */
32
    private $api;
33
34
    /**
35
     * @var ContainerInterface
36
     */
37
    private $container;
38
39
    /**
40
     * BlockApiTest setup.
41
     */
42
    public function setUp()
43
    {
44
        $this->container = new Container();
1 ignored issue
show
Documentation Bug introduced by
It seems like new \Symfony\Component\D...cyInjection\Container() of type object<Symfony\Component...ncyInjection\Container> is incompatible with the declared type object<Symfony\Component...ion\ContainerInterface> of property $container.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
45
        $this->container->set('translator.default', new IdentityTranslator());
46
        $this->container->set('foo.block', new FooBlock());
47
        $this->container->set('zikula_extensions_module.api.variable', new \stdClass());
48
        $this->api = new BlockFactoryApi($this->container);
49
    }
50
51
    /**
52
     * @covers BlockFactoryApiInterface::getInstance()
53
     */
54
    public function testGetBlockDefinedAsService()
55
    {
56
        $this->assertEquals($this->container->get('foo.block'), $this->api->getInstance('foo.block', new AcmeFooModule()));
57
    }
58
59
    /**
60
     * @expectedException \RuntimeException
61
     */
62
    public function testDoesNotExistException()
63
    {
64
        $this->api->getInstance('BarModule\ZedBlock', new AcmeFooModule());
65
    }
66
67
    /**
68
     * @expectedException \RuntimeException
69
     */
70
    public function testWrongInterfaceException()
71
    {
72
        $this->api->getInstance(WrongInterfaceBlock::class, new AcmeFooModule());
73
    }
74
75
    /**
76
     * @covers BlockFactoryApiInterface::getInstance()
77
     */
78 View Code Duplication
    public function testGetInstanceOfAbstractExtensionBlock()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79
    {
80
        $blockInstance = $this->api->getInstance(BarBlock::class, new AcmeFooModule());
81
        $this->assertNotEmpty($blockInstance);
82
        $this->assertInstanceOf(AbstractBlockHandler::class, $blockInstance);
83
        $this->assertEquals('Bar', $blockInstance->getType());
84
        $serviceNameHelper = new ServiceNameHelper();
85
        $blockServiceName = $serviceNameHelper->generateServiceNameFromClassName(BarBlock::class);
86
        $this->assertTrue($this->container->has($blockServiceName));
87
        $retrievedBlockService = $this->container->get($blockServiceName);
88
        $this->assertInstanceOf(BlockHandlerInterface::class, $retrievedBlockService);
89
    }
90
91
    /**
92
     * @covers BlockFactoryApiInterface::getInstance()
93
     */
94 View Code Duplication
    public function testGetInstanceOfInterfaceExtensionBlock()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
95
    {
96
        $blockInstance = $this->api->getInstance(FooBlock::class, new AcmeFooModule());
97
        $this->assertNotEmpty($blockInstance);
98
        $this->assertInstanceOf(BlockHandlerInterface::class, $blockInstance);
99
        $this->assertEquals('FooType', $blockInstance->getType());
100
        $serviceNameHelper = new ServiceNameHelper();
101
        $blockServiceName = $serviceNameHelper->generateServiceNameFromClassName(FooBlock::class);
102
        $this->assertTrue($this->container->has($blockServiceName));
103
        $retrievedBlockService = $this->container->get($blockServiceName);
104
        $this->assertInstanceOf(BlockHandlerInterface::class, $retrievedBlockService);
105
    }
106
}
107