Completed
Push — master ( 979a3e...45792c )
by Vítor
01:55
created

test_it_exposes_its_extension_id()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of the Noiselabs ZfTestCase Behat Extension.
4
 *
5
 * (c) Vítor Brandão <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Noiselabs\Behat\ZfTestCaseExtensionTest\ServiceContainer;
12
13
use Behat\Testwork\ServiceContainer\Configuration\ConfigurationTree;
14
use Noiselabs\Behat\ZfTestCaseExtension\Context\Initializer\ZfTestCaseAwareInitializer;
15
use Noiselabs\Behat\ZfTestCaseExtension\ServiceContainer\ZfTestCaseExtension;
16
use Noiselabs\Behat\ZfTestCaseExtension\TestCase\HttpControllerTestCase;
17
use PHPUnit_Framework_TestCase;
18
use Symfony\Component\Config\Definition\Processor;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
20
21
/**
22
 * @group integration
23
 */
24
class ZfTestCaseExtensionTest extends PHPUnit_Framework_TestCase
25
{
26
    /**
27
     * @var ContainerBuilder
28
     */
29
    private $container;
30
31
    /**
32
     * @var ZfTestCaseExtension
33
     */
34
    private $extension;
35
36
    protected function setUp()
37
    {
38
        $this->container = new ContainerBuilder();
39
        $this->extension = new ZfTestCaseExtension();
40
    }
41
42
    public function test_it_is_a_testwork_extension()
43
    {
44
        $this->assertInstanceOf(ZfTestCaseExtension::class, $this->extension);
45
    }
46
47
    public function test_it_exposes_its_extension_id()
48
    {
49
        $this->assertSame(ZfTestCaseExtension::EXTENSION_ID, $this->extension->getConfigKey());
50
    }
51
52
    public function test_it_loads_the_http_controller_test_case()
53
    {
54
        $this->loadExtension(['configuration' => __DIR__ . '/../Fixtures/application.config.php']);
55
        $this->assertServiceRegistered(ZfTestCaseExtension::EXTENSION_ID . '.http_controller_test_case',
56
            HttpControllerTestCase::class);
57
    }
58
59
    public function test_it_loads_the_context_initializer()
60
    {
61
        $this->loadExtension(['configuration' => __DIR__ . '/../Fixtures/application.config.php']);
62
        $this->assertServiceRegistered(ZfTestCaseExtension::EXTENSION_ID . '.context_initializer',
63
            ZfTestCaseAwareInitializer::class);
64
    }
65
66
    private function assertServiceRegistered($id, $class)
67
    {
68
        $this->assertTrue($this->container->has($id));
69
        $this->assertInstanceOf($class, $this->container->get($id));
70
    }
71
72
    private function loadExtension(array $config = [])
73
    {
74
        $this->extension->load($this->container, $this->processConfiguration($config));
75
        $this->container->compile();
76
    }
77
78
    private function processConfiguration(array $config = [])
79
    {
80
        $configurationTree = new ConfigurationTree();
81
        $configTree = $configurationTree->getConfigTree([$this->extension]);
82
        $key = $this->extension->getConfigKey();
83
        $config = (new Processor())->process($configTree, ['testwork' => [$key => $config]]);
84
85
        return $config[$key];
86
    }
87
}
88