22
33namespace Codeception \Module ;
44
5+ use Arachne \Codeception \ConfigFilesInterface ;
56use Arachne \Codeception \Connector \Nette as NetteConnector ;
7+ use Arachne \Codeception \DI \CodeceptionExtension ;
68use Codeception \TestCase ;
79use Codeception \Lib \Framework ;
8- use Nette \Configurator ;
10+ use Arachne \Bootstrap \Configurator ;
11+ use Nette \DI \Compiler ;
912use Nette \DI \Container ;
1013use Nette \DI \MissingServiceException ;
1114use Nette \InvalidStateException ;
@@ -28,33 +31,25 @@ class Nette extends Framework
2831 /** @var string */
2932 private $ suite ;
3033
31- /**
32- * @var array $config
33- */
34- public function __construct ($ config = array ())
35- {
36- $ this ->config = array (
37- 'configFiles ' => array (),
38- );
39- parent ::__construct ($ config );
40- }
41-
42- protected function validateConfig ()
43- {
44- parent ::validateConfig ();
45- Validators::assertField ($ this ->config , 'configFiles ' , 'array ' );
46- }
34+ /** @var string */
35+ private $ path ;
4736
4837 // TODO: separate ArachneTools module (debugContent method)
4938 public function _beforeSuite ($ settings = array ())
5039 {
5140 parent ::_beforeSuite ($ settings );
5241
5342 $ this ->detectSuiteName ($ settings );
54- $ path = pathinfo ($ settings ['path ' ], PATHINFO_DIRNAME );
55- $ tempDir = $ path . DIRECTORY_SEPARATOR . '_temp ' . DIRECTORY_SEPARATOR . $ this ->suite ;
43+ $ this ->path = pathinfo ($ settings ['path ' ], PATHINFO_DIRNAME );
44+
45+ self ::purge ($ this ->path . DIRECTORY_SEPARATOR . '_temp ' . DIRECTORY_SEPARATOR . $ this ->suite );
46+ }
47+
48+ public function _before (TestCase $ test )
49+ {
50+ $ tempDir = $ this ->path . DIRECTORY_SEPARATOR . '_temp ' . DIRECTORY_SEPARATOR . $ this ->suite . DIRECTORY_SEPARATOR . (new \ReflectionClass ($ test ))->getShortName () . '_ ' . $ test ->getName ();
51+ @mkdir ($ tempDir , 0777 , TRUE );
5652
57- self ::purge ($ tempDir );
5853 $ this ->configurator = new Configurator ();
5954 $ this ->configurator ->setDebugMode (FALSE );
6055 $ this ->configurator ->setTempDirectory ($ tempDir );
@@ -63,20 +58,20 @@ public function _beforeSuite($settings = array())
6358 'class ' => $ this ->getContainerClass (),
6459 ),
6560 ));
61+ $ this ->configurator ->onCompile [] = function ($ config , Compiler $ compiler ) {
62+ $ compiler ->addExtension ('arachne.codeception ' , new CodeceptionExtension ());
63+ };
6664
67- $ files = $ this -> config [ ' configFiles ' ];
68- $ files [] = __DIR__ . ' /config.neon ' ;
69- foreach ( $ files as $ file ) {
70- $ this -> configurator -> addConfig ( $ file );
65+ if ( $ test instanceof ConfigFilesInterface) {
66+ foreach ( $ test -> getConfigFiles () as $ file ) {
67+ $ this -> configurator -> addConfig ( $ this -> path . DIRECTORY_SEPARATOR . $ this -> suite . DIRECTORY_SEPARATOR . $ file );
68+ }
7169 }
7270
7371 // Generates and loads the container class.
7472 // The actual container is created later.
7573 $ this ->configurator ->createContainer ();
76- }
7774
78- public function _before (TestCase $ test )
79- {
8075 $ class = $ this ->getContainerClass ();
8176 // Cannot use $this->configurator->createContainer() directly beacuse it would call $container->initialize().
8277 // Container initialization is called laiter by NetteConnector.
@@ -112,8 +107,9 @@ public function grabService($service)
112107
113108 public function seeRedirectTo ($ url )
114109 {
110+ $ request = $ this ->container ->getByType ('Nette\Http\IRequest ' );
115111 $ response = $ this ->container ->getByType ('Nette\Http\IResponse ' );
116- if ($ response ->getHeader ('Location ' ) !== $ url ) {
112+ if ($ response ->getHeader ('Location ' ) !== $ request -> getUrl ()-> getHostUrl () . $ url ) {
117113 $ this ->fail ('Couldn \'t confirm redirect target to be " ' . $ url . '", Location header contains " ' . $ response ->getHeader ('Location ' ) . '". ' );
118114 }
119115 }
@@ -148,7 +144,7 @@ private function getContainerClass()
148144 protected static function purge ($ dir )
149145 {
150146 if (!is_dir ($ dir )) {
151- mkdir ( $ dir ) ;
147+ return ;
152148 }
153149 foreach (new RecursiveIteratorIterator (new RecursiveDirectoryIterator ($ dir ), RecursiveIteratorIterator::CHILD_FIRST ) as $ entry ) {
154150 if (substr ($ entry ->getBasename (), 0 , 1 ) === '. ' ) {
0 commit comments