|
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 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
|
|
|
|