1414 *
1515 * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
1616 * @author Ryan Albon <ryanalbon@gmail.com>
17+ * @author John Cartwright <jcartdev@gmail.com>
1718 */
1819abstract class ExtensionTestCase extends ContainerAwareTestCase
1920{
@@ -61,24 +62,24 @@ public function assertParameter($expected, $key)
6162 */
6263 public function assertHasDefinition ($ id )
6364 {
64- $ actual = $ this ->container ->hasDefinition ($ id ) ?: $ this ->containerBuilder ->hasAlias ($ id );
65+ $ actual = $ this ->container ->hasDefinition ($ id ) ?: $ this ->container ->hasAlias ($ id );
6566
66- $ this ->assertTrue ($ actual );
67+ $ this ->assertTrue ($ actual, sprintf ( ' Expected definition "%s" to exist ' , $ id ) );
6768 }
6869
6970 /**
7071 * Assertion on the Constructor Arguments of a DIC Service Definition.
7172 *
7273 * @param \Symfony\Component\DependencyInjection\Definition $definition
73- * @param array $arguments
74+ * @param array $argumentList
7475 */
75- public function assertDICConstructorArguments (Definition $ definition , array $ arguments )
76+ public function assertDICConstructorArguments (Definition $ definition , array $ argumentList )
7677 {
7778 $ this ->assertEquals (
78- $ arguments ,
79+ $ argumentList ,
7980 $ definition ->getArguments (),
8081 sprintf (
81- 'Expected and actual DIC Service constructor arguments of definition "%s" do not match. ' ,
82+ 'Expected and actual DIC Service constructor argumentList of definition "%s" do not match. ' ,
8283 $ definition ->getClass ()
8384 )
8485 );
@@ -99,19 +100,54 @@ public function assertDICDefinitionClass(Definition $definition, $expectedClass)
99100 );
100101 }
101102
103+ /**
104+ * Assertion on the called Method of a DIC Service Definition.
105+ *
106+ * @param \Symfony\Component\DependencyInjection\Definition $definition
107+ * @param string $methodName
108+ * @param array $parameterList
109+ */
110+ public function assertDICDefinitionMethodCall (Definition $ definition , $ methodName , array $ parameterList = null )
111+ {
112+ $ callList = $ definition ->getMethodCalls ();
113+ $ matchedCall = null ;
114+
115+ foreach ($ callList as $ call ) {
116+ if ($ call [0 ] === $ methodName ) {
117+ $ matchedCall = $ call ;
118+
119+ break ;
120+ }
121+ }
122+
123+ if ( ! $ matchedCall ) {
124+ $ this ->fail (
125+ sprintf ('Method "%s" is was expected to be called. ' , $ methodName )
126+ );
127+ }
128+
129+ if ($ parameterList !== null ) {
130+ $ this ->assertEquals (
131+ $ parameterList ,
132+ $ matchedCall [1 ],
133+ sprintf ('Expected parameters to method "%s" do not match the actual parameters. ' , $ methodName )
134+ );
135+ }
136+ }
137+
102138 /**
103139 * Assertion on the called Method position of a DIC Service Definition.
104140 *
105141 * @param integer $position
106142 * @param \Symfony\Component\DependencyInjection\Definition $definition
107143 * @param string $methodName
108- * @param array $params
144+ * @param array $parameterList
109145 */
110- public function assertDICDefinitionMethodCallAt ($ position , Definition $ definition , $ methodName , array $ params = null )
146+ public function assertDICDefinitionMethodCallAt ($ position , Definition $ definition , $ methodName , array $ parameterList = null )
111147 {
112- $ calls = $ definition ->getMethodCalls ();
148+ $ callList = $ definition ->getMethodCalls ();
113149
114- if ( ! isset ($ calls [$ position ][0 ])) {
150+ if ( ! isset ($ callList [$ position ][0 ])) {
115151 // Throws an Exception
116152 $ this ->fail (
117153 sprintf ('Method "%s" is expected to be called at position %s. ' , $ methodName , $ position )
@@ -120,16 +156,35 @@ public function assertDICDefinitionMethodCallAt($position, Definition $definitio
120156
121157 $ this ->assertEquals (
122158 $ methodName ,
123- $ calls [$ position ][0 ],
159+ $ callList [$ position ][0 ],
124160 sprintf ('Method "%s" is expected to be called at position %s. ' , $ methodName , $ position )
125161 );
126162
127- if ($ params !== null ) {
163+ if ($ parameterList !== null ) {
128164 $ this ->assertEquals (
129- $ params ,
130- $ calls [$ position ][1 ],
165+ $ parameterList ,
166+ $ callList [$ position ][1 ],
131167 sprintf ('Expected parameters to methods "%s" do not match the actual parameters. ' , $ methodName )
132168 );
133169 }
134170 }
171+
172+ /**
173+ * Assertion on the Definition that a method is not called for a DIC Service Definition.
174+ *
175+ * @param \Symfony\Component\DependencyInjection\Definition $definition
176+ * @param string $methodName
177+ */
178+ public function assertDICDefinitionMethodNotCalled (Definition $ definition , $ methodName )
179+ {
180+ $ callList = $ definition ->getMethodCalls ();
181+
182+ foreach ($ callList as $ call ) {
183+ if ($ call [0 ] === $ methodName ) {
184+ $ this ->fail (
185+ sprintf ('Method "%s" is not expected to be called. ' , $ methodName )
186+ );
187+ }
188+ }
189+ }
135190}
0 commit comments