|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the MilioooMessageBundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Michiel boeckaert <[email protected]> |
|
7
|
|
|
* This source file is subject to the MIT license that is bundled |
|
8
|
|
|
* with this source code in the file LICENSE. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Miliooo\MessagingBundle\Tests\DependencyInjection; |
|
12
|
|
|
|
|
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
14
|
|
|
use Symfony\Component\Yaml\Parser; |
|
15
|
|
|
use Miliooo\MessagingBundle\DependencyInjection\MilioooMessagingExtension; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Test file for MilioooMessagingExtensionTest |
|
19
|
|
|
* |
|
20
|
|
|
* @author Michiel Boeckaert <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class MilioooMessagingExtensionTest extends \PHPUnit_Framework_TestCase |
|
23
|
|
|
{ |
|
24
|
|
|
/** @var ContainerBuilder */ |
|
25
|
|
|
protected $containerBuilder; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
|
29
|
|
|
*/ |
|
30
|
|
|
public function testLoadThrowsExceptionUnlessMessageClassSet() |
|
31
|
|
|
{ |
|
32
|
|
|
$loader = new MilioooMessagingExtension(); |
|
33
|
|
|
$config = $this->getEmptyConfig(); |
|
34
|
|
|
unset($config['message_class']); |
|
35
|
|
|
$loader->load([$config], new ContainerBuilder()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
|
40
|
|
|
*/ |
|
41
|
|
|
public function testLoadThrowsExceptionUnlessMessageMetaClassSet() |
|
42
|
|
|
{ |
|
43
|
|
|
$loader = new MilioooMessagingExtension(); |
|
44
|
|
|
$config = $this->getEmptyConfig(); |
|
45
|
|
|
unset($config['message_meta_class']); |
|
46
|
|
|
$loader->load([$config], new ContainerBuilder()); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
|
51
|
|
|
*/ |
|
52
|
|
|
public function testLoadThrowsExceptionUnlessThreadClassSet() |
|
53
|
|
|
{ |
|
54
|
|
|
$loader = new MilioooMessagingExtension(); |
|
55
|
|
|
$config = $this->getEmptyConfig(); |
|
56
|
|
|
unset($config['thread_class']); |
|
57
|
|
|
$loader->load([$config], new ContainerBuilder()); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
|
62
|
|
|
*/ |
|
63
|
|
|
public function testLoadThrowsExceptionUnlessThreadMetaSet() |
|
64
|
|
|
{ |
|
65
|
|
|
$loader = new MilioooMessagingExtension(); |
|
66
|
|
|
$config = $this->getEmptyConfig(); |
|
67
|
|
|
unset($config['thread_meta_class']); |
|
68
|
|
|
$loader->load([$config], new ContainerBuilder()); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testMessagingLoadModelClassesWithDefaults() |
|
72
|
|
|
{ |
|
73
|
|
|
$this->createEmptyConfiguration(); |
|
74
|
|
|
$this->assertParameter('\Acme\MyBundle\Entity\Message', 'miliooo_messaging.message_class'); |
|
75
|
|
|
$this->assertParameter('\Acme\MyBundle\Entity\MessageMeta', 'miliooo_messaging.message_meta_class'); |
|
76
|
|
|
$this->assertParameter('\Acme\MyBundle\Entity\Thread', 'miliooo_messaging.thread_class'); |
|
77
|
|
|
$this->assertParameter('\Acme\MyBundle\Entity\ThreadMeta', 'miliooo_messaging.thread_meta_class'); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function testMessagingLoadsDefinitionsFromBuildersXml() |
|
81
|
|
|
{ |
|
82
|
|
|
$this->createEmptyConfiguration(); |
|
83
|
|
|
$this->assertHasDefinition('miliooo_messaging.abstract_new_message_builder'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
protected function createEmptyConfiguration() |
|
87
|
|
|
{ |
|
88
|
|
|
$this->containerBuilder = new ContainerBuilder(); |
|
89
|
|
|
$loader = new MilioooMessagingExtension(); |
|
90
|
|
|
$config = $this->getEmptyConfig(); |
|
91
|
|
|
$loader->load([$config], $this->containerBuilder); |
|
92
|
|
|
$this->assertTrue($this->containerBuilder instanceof ContainerBuilder); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* gets an empty config |
|
97
|
|
|
* |
|
98
|
|
|
* @return array |
|
|
|
|
|
|
99
|
|
|
*/ |
|
100
|
|
|
protected function getEmptyConfig() |
|
101
|
|
|
{ |
|
102
|
|
|
$yaml = <<<EOF |
|
103
|
|
|
thread_class: \Acme\MyBundle\Entity\Thread |
|
104
|
|
|
thread_meta_class: \Acme\MyBundle\Entity\ThreadMeta |
|
105
|
|
|
message_class: \Acme\MyBundle\Entity\Message |
|
106
|
|
|
message_meta_class: \Acme\MyBundle\Entity\MessageMeta |
|
107
|
|
|
username_object_transformer: acme_my_foo_service |
|
108
|
|
|
EOF; |
|
109
|
|
|
$parser = new Parser(); |
|
110
|
|
|
|
|
111
|
|
|
return $parser->parse($yaml); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Asserts that a parameter key has a certain value |
|
116
|
|
|
* |
|
117
|
|
|
* @param mixed $value |
|
118
|
|
|
* @param string $key |
|
119
|
|
|
*/ |
|
120
|
|
|
private function assertParameter($value, $key) |
|
121
|
|
|
{ |
|
122
|
|
|
$this->assertEquals($value, $this->containerBuilder->getParameter($key)); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Asserts that a definition exists |
|
127
|
|
|
* |
|
128
|
|
|
* @param string $id |
|
129
|
|
|
*/ |
|
130
|
|
|
private function assertHasDefinition($id) |
|
131
|
|
|
{ |
|
132
|
|
|
$this->assertTrue(($this->containerBuilder->hasDefinition($id) || $this->containerBuilder->hasAlias($id))); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.