2
2
3
3
namespace Codeception \Module ;
4
4
5
+ use Arachne \Codeception \ConfigFilesInterface ;
5
6
use Arachne \Codeception \Connector \Nette as NetteConnector ;
7
+ use Arachne \Codeception \DI \CodeceptionExtension ;
6
8
use Codeception \TestCase ;
7
9
use Codeception \Lib \Framework ;
8
- use Nette \Configurator ;
10
+ use Arachne \Bootstrap \Configurator ;
11
+ use Nette \DI \Compiler ;
9
12
use Nette \DI \Container ;
10
13
use Nette \DI \MissingServiceException ;
11
14
use Nette \InvalidStateException ;
@@ -28,33 +31,25 @@ class Nette extends Framework
28
31
/** @var string */
29
32
private $ suite ;
30
33
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 ;
47
36
48
37
// TODO: separate ArachneTools module (debugContent method)
49
38
public function _beforeSuite ($ settings = array ())
50
39
{
51
40
parent ::_beforeSuite ($ settings );
52
41
53
42
$ 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 );
56
52
57
- self ::purge ($ tempDir );
58
53
$ this ->configurator = new Configurator ();
59
54
$ this ->configurator ->setDebugMode (FALSE );
60
55
$ this ->configurator ->setTempDirectory ($ tempDir );
@@ -63,20 +58,20 @@ public function _beforeSuite($settings = array())
63
58
'class ' => $ this ->getContainerClass (),
64
59
),
65
60
));
61
+ $ this ->configurator ->onCompile [] = function ($ config , Compiler $ compiler ) {
62
+ $ compiler ->addExtension ('arachne.codeception ' , new CodeceptionExtension ());
63
+ };
66
64
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
+ }
71
69
}
72
70
73
71
// Generates and loads the container class.
74
72
// The actual container is created later.
75
73
$ this ->configurator ->createContainer ();
76
- }
77
74
78
- public function _before (TestCase $ test )
79
- {
80
75
$ class = $ this ->getContainerClass ();
81
76
// Cannot use $this->configurator->createContainer() directly beacuse it would call $container->initialize().
82
77
// Container initialization is called laiter by NetteConnector.
@@ -112,8 +107,9 @@ public function grabService($service)
112
107
113
108
public function seeRedirectTo ($ url )
114
109
{
110
+ $ request = $ this ->container ->getByType ('Nette\Http\IRequest ' );
115
111
$ response = $ this ->container ->getByType ('Nette\Http\IResponse ' );
116
- if ($ response ->getHeader ('Location ' ) !== $ url ) {
112
+ if ($ response ->getHeader ('Location ' ) !== $ request -> getUrl ()-> getHostUrl () . $ url ) {
117
113
$ this ->fail ('Couldn \'t confirm redirect target to be " ' . $ url . '", Location header contains " ' . $ response ->getHeader ('Location ' ) . '". ' );
118
114
}
119
115
}
@@ -148,7 +144,7 @@ private function getContainerClass()
148
144
protected static function purge ($ dir )
149
145
{
150
146
if (!is_dir ($ dir )) {
151
- mkdir ( $ dir ) ;
147
+ return ;
152
148
}
153
149
foreach (new RecursiveIteratorIterator (new RecursiveDirectoryIterator ($ dir ), RecursiveIteratorIterator::CHILD_FIRST ) as $ entry ) {
154
150
if (substr ($ entry ->getBasename (), 0 , 1 ) === '. ' ) {
0 commit comments