55use Codeception \Event \Suite ;
66use Codeception \Event \SuiteEvent ;
77use Codeception \Lib \Generator \Actor ;
8+ use Codeception \Lib \Parser ;
89use Codeception \Util \Annotation ;
910use Symfony \Component \EventDispatcher \EventDispatcher ;
1011use Symfony \Component \Finder \Finder ;
@@ -97,7 +98,7 @@ protected function createSuite($name)
9798
9899 public function addTest ($ path )
99100 {
100- $ testClasses = $ this -> getClassesFromFile ($ path );
101+ $ testClasses = Parser:: getClassesFromFile ($ path );
101102
102103 foreach ($ testClasses as $ testClass ) {
103104 $ reflected = new \ReflectionClass ($ testClass );
@@ -124,11 +125,12 @@ public function addCept($file)
124125 $ name = $ this ->relativeName ($ file );
125126 $ this ->tests [$ name ] = $ file ;
126127
127- $ cept = new TestCase \Cept ($ this ->dispatcher , array (
128- 'name ' => $ name ,
129- 'file ' => $ file ,
130- 'bootstrap ' => $ this ->settings ['bootstrap ' ]
131- ));
128+ $ cept = new TestCase \Cept ();
129+ $ cept ->configDispatcher ($ this ->dispatcher )
130+ ->configName ($ name )
131+ ->configFile ($ file )
132+ ->configBootstrap ($ this ->settings ['bootstrap ' ])
133+ ->initConfig ();
132134
133135 $ cept ->preload ();
134136
@@ -143,7 +145,7 @@ public function addCest($file)
143145 $ name = $ this ->relativeName ($ file );
144146 $ this ->tests [$ name ] = $ file ;
145147
146- $ testClasses = $ this -> getClassesFromFile ($ file );
148+ $ testClasses = Parser:: getClassesFromFile ($ file );
147149
148150 foreach ($ testClasses as $ testClass ) {
149151 $ reflected = new \ReflectionClass ($ testClass );
@@ -223,43 +225,6 @@ public function loadTests()
223225 }
224226 }
225227
226- protected function getClassesFromFile ($ file )
227- {
228- $ loaded_classes = get_declared_classes ();
229- require_once $ file ;
230-
231- $ sourceCode = file_get_contents ($ file );
232- $ classes = array ();
233- $ tokens = token_get_all ($ sourceCode );
234- $ namespace = '' ;
235-
236- for ($ i = 0 ; $ i < count ($ tokens ); $ i ++) {
237- if ($ tokens [$ i ][0 ] === T_NAMESPACE ) {
238- $ namespace = '' ;
239- for ($ j = $ i + 1 ; $ j < count ($ tokens ); $ j ++) {
240- if ($ tokens [$ j ][0 ] === T_STRING ) {
241- $ namespace .= $ tokens [$ j ][1 ] . '\\' ;
242- } else {
243- if ($ tokens [$ j ] === '{ ' || $ tokens [$ j ] === '; ' ) {
244- break ;
245- }
246- }
247- }
248- }
249-
250- if ($ tokens [$ i ][0 ] === T_CLASS ) {
251- for ($ j = $ i + 1 ; $ j < count ($ tokens ); $ j ++) {
252- if ($ tokens [$ j ] === '{ ' ) {
253- $ classes [] = $ namespace . $ tokens [$ i + 2 ][1 ];
254- break ;
255- }
256- }
257- }
258- }
259-
260- return $ classes ;
261- }
262-
263228 protected function createTestFromPhpUnitMethod (\ReflectionClass $ class , \ReflectionMethod $ method )
264229 {
265230 if (!\PHPUnit_Framework_TestSuite::isTestMethod ($ method )) {
@@ -296,9 +261,10 @@ protected function enhancePhpunitTest(\PHPUnit_Framework_TestCase $test)
296261 ? $ this ->settings ['namespace ' ] . '\\' . $ this ->settings ['class_name ' ]
297262 : $ this ->settings ['class_name ' ];
298263
299- $ test ->setBootstrap ($ this ->settings ['bootstrap ' ]);
300- $ test ->setDispatcher ($ this ->dispatcher );
301- $ test ->setGuyClass ($ guy );
264+ $ test ->configBootstrap ($ this ->settings ['bootstrap ' ])
265+ ->configDispatcher ($ this ->dispatcher )
266+ ->configActor ($ guy )
267+ ->initConfig ();
302268
303269 $ test ->getScenario ()->groups (\PHPUnit_Util_Test::getGroups ($ className , $ methodName ));
304270 $ test ->getScenario ()->env (Annotation::forMethod ($ className , $ methodName )->fetchAll ('env ' ));
@@ -311,22 +277,15 @@ protected function createTestFromCestMethod($cestInstance, $methodName, $file, $
311277 return ;
312278 }
313279
314- $ overriddenGuy = Annotation::forMethod ($ testClass , $ methodName )->fetch ('guy ' );
315- if (!$ overriddenGuy ) {
316- $ overriddenGuy = Annotation::forClass ($ testClass )->fetch ('guy ' );
317- }
318- if ($ overriddenGuy ) {
319- $ guy = $ overriddenGuy ;
320- }
321-
322- $ cest = new TestCase \Cest ($ this ->dispatcher , array (
323- 'name ' => $ methodName ,
324- 'instance ' => $ cestInstance ,
325- 'method ' => $ methodName ,
326- 'file ' => $ file ,
327- 'bootstrap ' => $ this ->settings ['bootstrap ' ],
328- 'guy ' => $ guy
329- ));
280+ $ cest = new TestCase \Cest ();
281+ $ cest ->configDispatcher ($ this ->dispatcher )
282+ ->configName ($ methodName )
283+ ->configBootstrap ($ this ->settings ['bootstrap ' ])
284+ ->configFile ($ file )
285+ ->config ('testClassInstance ' , $ cestInstance )
286+ ->config ('testMethod ' , $ methodName )
287+ ->configActor ($ guy )
288+ ->initConfig ();
330289
331290 $ cest ->getScenario ()->env (Annotation::forMethod ($ testClass , $ methodName )->fetchAll ('env ' ));
332291 $ cest ->getScenario ()->groups (\PHPUnit_Util_Test::getGroups ($ testClass , $ methodName ));
0 commit comments