2
2
3
3
namespace Codeception \Module ;
4
4
5
+ use Codeception \TestCase ;
6
+ use Codeception \Util \Connector \Nette as NetteConnector ;
5
7
use Codeception \Util \Framework ;
6
8
use Nette \Configurator ;
7
- use Nette \InvalidStateException ;
8
9
use Nette \DI \Container ;
9
10
use Nette \DI \MissingServiceException ;
11
+ use Nette \Diagnostics \Debugger ;
12
+ use Nette \Environment ;
13
+ use Nette \InvalidStateException ;
10
14
use Nette \Loaders \RobotLoader ;
11
15
use Nette \Utils \Validators ;
12
16
use RecursiveDirectoryIterator ;
18
22
class Nette extends Framework
19
23
{
20
24
25
+ /** @var Configurator */
26
+ protected $ configurator ;
27
+
21
28
/** @var Container */
22
29
protected $ container ;
23
30
24
31
/** @var RobotLoader */
25
32
private $ robotLoader ;
26
33
34
+ /** @var string */
35
+ private $ suite ;
36
+
27
37
/**
28
38
* @var array $config
29
39
*/
@@ -49,35 +59,63 @@ public function _beforeSuite($settings = array())
49
59
{
50
60
parent ::_beforeSuite ($ settings );
51
61
52
- $ suite = $ this ->detectSuiteName ($ settings );
53
- $ tempDir = $ this ->config ['tempDir ' ] . DIRECTORY_SEPARATOR . $ suite ;
62
+ $ this ->detectSuiteName ($ settings );
63
+ $ path = pathinfo ($ settings ['path ' ], PATHINFO_DIRNAME );
64
+ $ tempDir = $ path . DIRECTORY_SEPARATOR . '_temp ' . DIRECTORY_SEPARATOR . $ this ->suite ;
65
+ Debugger::$ logDirectory = $ path . DIRECTORY_SEPARATOR . '_log ' ;
54
66
55
67
self ::purge ($ tempDir );
56
- $ configurator = new Configurator ();
57
- $ configurator ->setTempDirectory ($ tempDir );
58
- $ configurator ->addParameters (array (
68
+ $ this ->configurator = new Configurator ();
69
+ $ this ->configurator ->setDebugMode (FALSE );
70
+ $ this ->configurator ->setTempDirectory ($ tempDir );
71
+ $ this ->configurator ->addParameters (array (
59
72
'container ' => array (
60
- 'class ' => ucfirst ( $ suite ) . ' SuiteContainer ' ,
73
+ 'class ' => $ this -> getContainerClass () ,
61
74
),
62
75
));
76
+
63
77
$ files = $ this ->config ['configFiles ' ];
64
78
$ files [] = __DIR__ . '/config.neon ' ;
65
79
foreach ($ files as $ file ) {
66
- $ configurator ->addConfig ($ file );
80
+ $ this -> configurator ->addConfig ($ file );
67
81
}
68
- $ this ->robotLoader = $ configurator ->createRobotLoader ();
82
+
83
+ $ this ->robotLoader = $ this ->configurator ->createRobotLoader ();
69
84
foreach ($ this ->config ['robotLoader ' ] as $ dir ) {
70
85
$ this ->robotLoader ->addDirectory ($ dir );
71
86
}
72
87
$ this ->robotLoader ->register ();
73
- $ this ->container = $ configurator ->createContainer ();
74
88
}
75
89
76
90
public function _afterSuite ()
77
91
{
78
92
$ this ->robotLoader ->unregister ();
79
93
}
80
94
95
+ public function _before (TestCase $ test )
96
+ {
97
+ $ class = $ this ->getContainerClass ();
98
+ if (!class_exists ($ class , FALSE )) {
99
+ $ this ->container = $ this ->configurator ->createContainer ();
100
+ } else {
101
+ $ this ->container = new $ class ;
102
+ $ this ->container ->initialize ();
103
+ Environment::setContext ($ this ->container );
104
+ }
105
+ $ this ->client = new NetteConnector ();
106
+ $ this ->client ->setContainer ($ this ->container );
107
+ parent ::_before ($ test );
108
+ }
109
+
110
+ public function _after (TestCase $ test )
111
+ {
112
+ parent ::_after ($ test );
113
+ $ _SESSION = array ();
114
+ $ _GET = array ();
115
+ $ _POST = array ();
116
+ $ _COOKIE = array ();
117
+ }
118
+
81
119
/**
82
120
* @param string $service
83
121
* @return object
@@ -101,7 +139,12 @@ private function detectSuiteName($settings)
101
139
if ($ position === FALSE ) {
102
140
throw new InvalidStateException ('Could not detect suite name, path is invalid. ' );
103
141
}
104
- return substr ($ directory , $ position + 1 );
142
+ $ this ->suite = substr ($ directory , $ position + 1 );
143
+ }
144
+
145
+ private function getContainerClass ()
146
+ {
147
+ return ucfirst ($ this ->suite ) . 'SuiteContainer ' ;
105
148
}
106
149
107
150
/**
0 commit comments