File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 6666 */
6767class Deployer extends Container
6868{
69- private static Deployer $ instance ;
69+ private static ? self $ instance = null ;
7070
7171 public function __construct (Application $ console )
7272 {
@@ -167,9 +167,26 @@ public function __construct(Application $console)
167167
168168 public static function get (): self
169169 {
170+ if (self ::$ instance === null ) {
171+ throw new \RuntimeException ('Deployer is not initialized. ' );
172+ }
173+
170174 return self ::$ instance ;
171175 }
172176
177+ public static function hasInstance (): bool
178+ {
179+ return self ::$ instance !== null ;
180+ }
181+
182+ /**
183+ * @internal For tests that need a clean Deployer singleton between cases.
184+ */
185+ public static function resetInstance (): void
186+ {
187+ self ::$ instance = null ;
188+ }
189+
173190 public function init (): void
174191 {
175192 $ this ->addTaskCommands ();
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ class Host
2929 public function __construct (string $ hostname )
3030 {
3131 $ parent = null ;
32- if (Deployer::get ()) {
32+ if (Deployer::hasInstance ()) {
3333 $ parent = Deployer::get ()->config ;
3434 }
3535 $ this ->config = new Configuration ($ parent );
Original file line number Diff line number Diff line change 88namespace Deployer \Host ;
99
1010use Deployer \Configuration ;
11+ use Deployer \Deployer ;
1112use PHPUnit \Framework \TestCase ;
1213
1314class HostTest extends TestCase
1415{
16+ protected function tearDown (): void
17+ {
18+ Deployer::resetInstance ();
19+ }
20+
1521 public function testHost ()
1622 {
1723 $ host = new Host ('host ' );
You can’t perform that action at this time.
0 commit comments