11<?php
22namespace Codeception \Module ;
33
4- use Codeception \Exception \ModuleConfigException ;
4+ use Codeception \Exception \ModuleConfig ;
55use Codeception \Lib \Connector \Laravel5 as LaravelConnector ;
66use Codeception \Lib \Framework ;
77use Codeception \Lib \Interfaces \ActiveRecord ;
88use Codeception \Lib \Interfaces \PartedModule ;
99use Codeception \Lib \ModuleContainer ;
10- use Codeception \TestCase ;
11- use Codeception \Step ;
12- use Codeception \Configuration ;
13- use Illuminate \Support \ClassLoader ;
14- use Illuminate \Support \Facades \Facade ;
1510use Codeception \Subscriber \ErrorHandler ;
1611use Illuminate \Contracts \Auth \Authenticatable ;
12+ use Illuminate \Support \Facades \Facade ;
1713
1814/**
1915 *
@@ -77,21 +73,20 @@ public function __construct(ModuleContainer $container, $config = null)
7773 {
7874 $ this ->config = array_merge (
7975 [
80- 'cleanup ' => true ,
76+ 'cleanup ' => true ,
8177 'environment_file ' => '.env ' ,
8278 'bootstrap ' => 'bootstrap ' . DIRECTORY_SEPARATOR . 'app.php ' ,
8379 'root ' => '' ,
8480 'packages ' => 'workbench ' ,
8581 ],
86- (array ) $ config
82+ (array )$ config
8783 );
8884
8985 $ projectDir = explode ($ this ->config ['packages ' ], \Codeception \Configuration::projectDir ())[0 ];
9086 $ projectDir .= $ this ->config ['root ' ];
9187
9288 $ this ->config ['project_dir ' ] = $ projectDir ;
9389 $ this ->config ['bootstrap_file ' ] = $ projectDir . $ this ->config ['bootstrap ' ];
94-
9590
9691 parent ::__construct ($ container );
9792 }
@@ -111,9 +106,8 @@ public function _initialize()
111106 * Before hook.
112107 *
113108 * @param \Codeception\TestCase $test
114- * @throws ModuleConfigException
115109 */
116- public function _before (TestCase $ test )
110+ public function _before (\ Codeception \ TestCase $ test )
117111 {
118112 if ($ this ->app ['db ' ] && $ this ->config ['cleanup ' ]) {
119113 $ this ->app ['db ' ]->beginTransaction ();
@@ -134,48 +128,52 @@ public function _before(TestCase $test)
134128 *
135129 * @param \Codeception\TestCase $test
136130 */
137- public function _after (TestCase $ test )
131+ public function _after (\ Codeception \ TestCase $ test )
138132 {
139133 if ($ this ->app ['db ' ] && $ this ->config ['cleanup ' ]) {
140134 $ this ->app ['db ' ]->rollback ();
141135 }
142136 }
143137
144- public function _parts ()
145- {
146- return ['orm ' ];
147- }
148-
149138 /**
150139 * After step hook.
151140 *
152141 * @param \Codeception\Step $step
153142 */
154- public function _afterStep (Step $ step )
143+ public function _afterStep (\ Codeception \ Step $ step )
155144 {
156145 parent ::_afterStep ($ step );
157146
158147 Facade::clearResolvedInstances ();
159148 }
160149
161150 /**
162- * Revert back to the Codeception error handler,
163- * becauses Laravel registers it's own error handler.
151+ * Initialize the Laravel framework.
152+ *
153+ * @throws ModuleConfigException
164154 */
165- protected function revertErrorHandler ()
155+ protected function initializeLaravel ()
166156 {
167- $ handler = new ErrorHandler ();
168- set_error_handler ([$ handler , 'errorHandler ' ]);
157+ $ this ->app = $ this ->bootApplication ();
158+ $ this ->app ->instance ('request ' , new Request ());
159+ $ this ->client = new LaravelConnector ($ this ->app );
169160 }
170161
171162 /**
172- * Make sure the Laravel bootstrap file exists .
163+ * Boot the Laravel application object .
173164 *
174- * @throws ModuleConfigException
165+ * @return \Illuminate\Foundation\Application
166+ * @throws \Codeception\Exception\ModuleConfigException
175167 */
176- protected function checkBootstrapFileExists ()
168+ protected function bootApplication ()
177169 {
178- $ bootstrapFile = $ this ->config ['bootstrap_file ' ];
170+ $ projectDir = explode ($ this ->config ['packages ' ], Configuration::projectDir ())[0 ];
171+ $ projectDir .= $ this ->config ['root ' ];
172+ require $ projectDir . 'vendor ' . DIRECTORY_SEPARATOR . 'autoload.php ' ;
173+
174+ ClassLoader::register ();
175+
176+ $ bootstrapFile = $ projectDir . $ this ->config ['bootstrap ' ];
179177
180178 if (!file_exists ($ bootstrapFile )) {
181179 throw new ModuleConfig (
@@ -197,6 +195,16 @@ protected function registerAutoloaders()
197195
198196
199197
198+ /**
199+ * Revert back to the Codeception error handler,
200+ * becauses Laravel registers it's own error handler.
201+ */
202+ protected function revertErrorHandler ()
203+ {
204+ $ handler = new ErrorHandler ();
205+ set_error_handler (array ($ handler , 'errorHandler ' ));
206+ }
207+
200208 /**
201209 * Provides access the Laravel application object.
202210 *
@@ -310,7 +318,7 @@ protected function getRootControllerNamespace()
310318 * @param $route
311319 * @param array $params
312320 */
313- public function seeCurrentRouteIs ($ route , $ params = [] )
321+ public function seeCurrentRouteIs ($ route , $ params = array () )
314322 {
315323 $ this ->seeCurrentUrlEquals ($ this ->app ['url ' ]->route ($ route , $ params , false ));
316324 }
@@ -327,7 +335,7 @@ public function seeCurrentRouteIs($route, $params = [])
327335 * @param $action
328336 * @param array $params
329337 */
330- public function seeCurrentActionIs ($ action , $ params = [] )
338+ public function seeCurrentActionIs ($ action , $ params = array () )
331339 {
332340 $ this ->seeCurrentUrlEquals ($ this ->app ['url ' ]->action ($ action , $ params , false ));
333341 }
@@ -444,6 +452,7 @@ public function seeFormErrorMessages(array $bindings)
444452 public function seeFormErrorMessage ($ key , $ errorMessage )
445453 {
446454 $ viewErrorBag = $ this ->app ['view ' ]->shared ('errors ' );
455+
447456 $ this ->assertEquals ($ errorMessage , $ viewErrorBag ->first ($ key ));
448457 }
449458
@@ -574,6 +583,7 @@ public function seeRecord($tableName, $attributes = [])
574583 *
575584 * @param $tableName
576585 * @param array $attributes
586+ * @part orm
577587 */
578588 public function dontSeeRecord ($ tableName , $ attributes = [])
579589 {
@@ -607,7 +617,6 @@ public function grabRecord($tableName, $attributes = [])
607617 * @param $tableName
608618 * @param array $attributes
609619 * @return mixed
610- * @part orm
611620 */
612621 protected function findRecord ($ tableName , $ attributes = [])
613622 {
@@ -618,4 +627,5 @@ protected function findRecord($tableName, $attributes = [])
618627
619628 return $ query ->first ();
620629 }
621- }
630+
631+ }
0 commit comments