3
3
namespace Styde \Enlighten ;
4
4
5
5
use Styde \Enlighten \Models \Run ;
6
- use Styde \Enlighten \Utils \GitInfo ;
6
+ use Styde \Enlighten \Facades \GitInfo ;
7
7
8
8
class TestRun
9
9
{
10
- private static bool $ hasBeenReset = false ;
10
+ private static ? self $ instance = null ;
11
11
12
- private GitInfo $ gitInfo ;
12
+ private Run $ run ;
13
13
14
- private ? Run $ run = null ;
14
+ private bool $ hasBeenReset = false ;
15
15
16
16
private string $ context = 'test ' ;
17
17
@@ -27,14 +27,26 @@ public static function getFailedTestLink(string $signature): string
27
27
return static ::$ failedTestLinks [$ signature ];
28
28
}
29
29
30
- public function __construct ( GitInfo $ gitInfo )
30
+ public static function getInstance (): self
31
31
{
32
- $ this ->gitInfo = $ gitInfo ;
32
+ if (is_null (static ::$ instance )) {
33
+ static ::$ instance = new self ;
34
+ }
35
+
36
+ return static ::$ instance ;
37
+ }
33
38
39
+ public static function resetInstance ()
40
+ {
41
+ static ::$ instance = null ;
42
+ }
43
+
44
+ private function __construct ()
45
+ {
34
46
$ this ->run = Run::firstOrNew ([
35
- 'branch ' => $ this -> gitInfo -> currentBranch (),
36
- 'head ' => $ this -> gitInfo -> head (),
37
- 'modified ' => $ this -> gitInfo -> modified (),
47
+ 'branch ' => GitInfo:: currentBranch (),
48
+ 'head ' => GitInfo:: head (),
49
+ 'modified ' => GitInfo:: modified (),
38
50
]);
39
51
}
40
52
@@ -59,12 +71,12 @@ public function save(): Run
59
71
60
72
public function reset ()
61
73
{
62
- if (static :: $ hasBeenReset ) {
74
+ if ($ this -> hasBeenReset ) {
63
75
return ;
64
76
}
65
77
66
78
$ this ->run ->delete ();
67
79
68
- static :: $ hasBeenReset = true ;
80
+ $ this -> hasBeenReset = true ;
69
81
}
70
82
}
0 commit comments