Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Deployer.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
*/
class Deployer extends Container
{
private static Deployer $instance;
private static ?self $instance = null;

public function __construct(Application $console)
{
Expand Down Expand Up @@ -167,9 +167,21 @@ public function __construct(Application $console)

public static function get(): self
{
if (self::$instance === null) {
throw new \RuntimeException('Deployer is not initialized.');
}

return self::$instance;
}

/**
* @internal For tests that need a clean Deployer singleton between cases.
*/
public static function resetInstance(): void
{
self::$instance = null;
}

public function init(): void
{
$this->addTaskCommands();
Expand Down
5 changes: 1 addition & 4 deletions src/Host/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ class Host

public function __construct(string $hostname)
{
$parent = null;
if (Deployer::get()) {
$parent = Deployer::get()->config;
}
$parent = Deployer::get()->config;
$this->config = new Configuration($parent);
$this->set('#alias', $hostname);
$this->set('hostname', preg_replace('/\/.+$/', '', $hostname));
Expand Down
5 changes: 0 additions & 5 deletions tests/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ parameters:
count: 1
path: ../src/Command/BlackjackCommand.php

-
message: "#^If condition is always true\\.$#"
count: 1
path: ../src/Host/Host.php

-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 1
Expand Down
12 changes: 12 additions & 0 deletions tests/src/Host/HostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,22 @@
namespace Deployer\Host;

use Deployer\Configuration;
use Deployer\Deployer;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;

class HostTest extends TestCase
{
protected function setUp(): void
{
new Deployer(new Application());
}

protected function tearDown(): void
{
Deployer::resetInstance();
}

public function testHost()
{
$host = new Host('host');
Expand Down
12 changes: 12 additions & 0 deletions tests/src/Selector/SelectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@

namespace Deployer\Selector;

use Deployer\Deployer;
use Deployer\Host\Host;
use Deployer\Host\HostCollection;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;

class SelectorTest extends TestCase
{
protected function setUp(): void
{
new Deployer(new Application());
}

protected function tearDown(): void
{
Deployer::resetInstance();
}

public function testSelectHosts()
{
$prod = (new Host('prod.domain.com'))->set('labels', ['stage' => 'prod']);
Expand Down
13 changes: 13 additions & 0 deletions tests/src/Task/TaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@

namespace Deployer\Task;

use Deployer\Deployer;
use Deployer\Host\Host;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\Input;
use Symfony\Component\Console\Output\Output;

use function Deployer\invoke;
use function Deployer\task;
Expand All @@ -20,9 +24,18 @@ public function callback(): void;

class TaskTest extends TestCase
{
protected function setUp(): void
{
$console = new Application();
$deployer = new Deployer($console);
$deployer['input'] = $this->createStub(Input::class);
$deployer['output'] = $this->createStub(Output::class);
}

protected function tearDown(): void
{
StubTask::$runned = 0;
Deployer::resetInstance();
}

public function testTask()
Expand Down
Loading