22
33namespace Codeception \Module ;
44
5+ use Codeception \TestCase ;
6+ use Codeception \Util \Connector \Nette as NetteConnector ;
57use Codeception \Util \Framework ;
68use Nette \Configurator ;
7- use Nette \InvalidStateException ;
89use Nette \DI \Container ;
910use Nette \DI \MissingServiceException ;
11+ use Nette \Diagnostics \Debugger ;
12+ use Nette \Environment ;
13+ use Nette \InvalidStateException ;
1014use Nette \Loaders \RobotLoader ;
1115use Nette \Utils \Validators ;
1216use RecursiveDirectoryIterator ;
1822class Nette extends Framework
1923{
2024
25+ /** @var Configurator */
26+ protected $ configurator ;
27+
2128 /** @var Container */
2229 protected $ container ;
2330
2431 /** @var RobotLoader */
2532 private $ robotLoader ;
2633
34+ /** @var string */
35+ private $ suite ;
36+
2737 /**
2838 * @var array $config
2939 */
@@ -49,35 +59,63 @@ public function _beforeSuite($settings = array())
4959 {
5060 parent ::_beforeSuite ($ settings );
5161
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 ' ;
5466
5567 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 (
5972 'container ' => array (
60- 'class ' => ucfirst ( $ suite ) . ' SuiteContainer ' ,
73+ 'class ' => $ this -> getContainerClass () ,
6174 ),
6275 ));
76+
6377 $ files = $ this ->config ['configFiles ' ];
6478 $ files [] = __DIR__ . '/config.neon ' ;
6579 foreach ($ files as $ file ) {
66- $ configurator ->addConfig ($ file );
80+ $ this -> configurator ->addConfig ($ file );
6781 }
68- $ this ->robotLoader = $ configurator ->createRobotLoader ();
82+
83+ $ this ->robotLoader = $ this ->configurator ->createRobotLoader ();
6984 foreach ($ this ->config ['robotLoader ' ] as $ dir ) {
7085 $ this ->robotLoader ->addDirectory ($ dir );
7186 }
7287 $ this ->robotLoader ->register ();
73- $ this ->container = $ configurator ->createContainer ();
7488 }
7589
7690 public function _afterSuite ()
7791 {
7892 $ this ->robotLoader ->unregister ();
7993 }
8094
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+
81119 /**
82120 * @param string $service
83121 * @return object
@@ -101,7 +139,12 @@ private function detectSuiteName($settings)
101139 if ($ position === FALSE ) {
102140 throw new InvalidStateException ('Could not detect suite name, path is invalid. ' );
103141 }
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 ' ;
105148 }
106149
107150 /**
0 commit comments