@@ -17,8 +17,9 @@ use Magento\FunctionalTestingFramework\DataGenerator\Persist\DataPersistenceHand
17
17
class { {suiteName} } extends \Codeception\GroupObject
18
18
{
19
19
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;
22
23
private static $HOOK_EXECUTION_INIT = "\n/******** Beginning execution of { {suiteName} } suite %s block ********/\n";
23
24
private static $HOOK_EXECUTION_END = "\n/******** Execution of { {suiteName} } suite %s block complete ********/\n";
24
25
{ {#var} }
@@ -29,15 +30,25 @@ class {{suiteName}} extends \Codeception\GroupObject
29
30
public function _before(\Codeception\Event\TestEvent $e)
30
31
{
31
32
// increment test count per execution
32
- self::$CURRENT_TEST_RUN ++;
33
+ $this -> currentTestRun ++;
34
+ $this -> executePreConditions ();
33
35
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) {
35
46
print sprintf(self::$HOOK_EXECUTION_INIT , " before" );
36
47
37
48
try {
38
49
{{> testActions} }
39
- } catch (\Exception $e ) {
40
- print $ e -> getMessage ();
50
+ } catch (\Exception $exception ) {
51
+ $ this -> preconditionFailure = $ exception -> getMessage ();
41
52
}
42
53
43
54
print sprintf(self::$HOOK_EXECUTION_END, "before");
@@ -48,16 +59,21 @@ class {{suiteName}} extends \Codeception\GroupObject
48
59
{ {#after} }
49
60
public function _after(\Codeception\Event\TestEvent $e)
50
61
{
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 ) {
52
69
print sprintf(self::$HOOK_EXECUTION_INIT , " after" );
53
70
54
71
try {
55
72
{{> testActions} }
56
- } catch (\Exception $e ) {
57
- print $e -> getMessage ();
73
+ } catch (\Exception $exception ) {
74
+ print $exception -> getMessage ();
58
75
}
59
76
60
-
61
77
print sprintf(self::$HOOK_EXECUTION_END, "after");
62
78
}
63
79
}
0 commit comments