@@ -17,8 +17,9 @@ use Magento\FunctionalTestingFramework\DataGenerator\Persist\DataPersistenceHand
1717class { {suiteName} } extends \Codeception\GroupObject
1818{
1919 public static $group = ' {{suiteName}}' ;
20- private static $TEST_COUNT = {{testCount} };
21- private static $CURRENT_TEST_RUN = 0;
20+ private $testCount = {{testCount} };
21+ private $preconditionFailure = null;
22+ private $currentTestRun = 0;
2223 private static $HOOK_EXECUTION_INIT = "\n/******** Beginning execution of { {suiteName} } suite %s block ********/\n";
2324 private static $HOOK_EXECUTION_END = "\n/******** Execution of { {suiteName} } suite %s block complete ********/\n";
2425 { {#var} }
@@ -29,15 +30,25 @@ class {{suiteName}} extends \Codeception\GroupObject
2930 public function _before(\Codeception\Event\TestEvent $e)
3031 {
3132 // increment test count per execution
32- self::$CURRENT_TEST_RUN ++;
33+ $this -> currentTestRun ++;
34+ $this -> executePreConditions ();
3335
34- if (self::$CURRENT_TEST_RUN == 1) {
36+ if ($this -> preconditionFailure != null) {
37+ //if our preconditions fail, we need to mark all the tests as incomplete.
38+ $e -> getTest ()-> getMetadata ()-> setIncomplete ($this -> preconditionFailure );
39+ }
40+ }
41+
42+
43+ private function executePreConditions()
44+ {
45+ if ($this -> currentTestRun == 1) {
3546 print sprintf(self::$HOOK_EXECUTION_INIT , " before" );
3647
3748 try {
3849 {{> testActions} }
39- } catch (\Exception $e ) {
40- print $ e -> getMessage ();
50+ } catch (\Exception $exception ) {
51+ $ this -> preconditionFailure = $ exception -> getMessage ();
4152 }
4253
4354 print sprintf(self::$HOOK_EXECUTION_END, "before");
@@ -48,16 +59,21 @@ class {{suiteName}} extends \Codeception\GroupObject
4859 { {#after} }
4960 public function _after(\Codeception\Event\TestEvent $e)
5061 {
51- if (self::$CURRENT_TEST_RUN == self::$TEST_COUNT ) {
62+ $this -> executePostConditions ();
63+ }
64+
65+
66+ private function executePostConditions()
67+ {
68+ if ($this -> currentTestRun == $this -> testCount ) {
5269 print sprintf(self::$HOOK_EXECUTION_INIT , " after" );
5370
5471 try {
5572 {{> testActions} }
56- } catch (\Exception $e ) {
57- print $e -> getMessage ();
73+ } catch (\Exception $exception ) {
74+ print $exception -> getMessage ();
5875 }
5976
60-
6177 print sprintf(self::$HOOK_EXECUTION_END, "after");
6278 }
6379 }
0 commit comments