-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to use multiple reboot strategies (#96)
- Loading branch information
Showing
9 changed files
with
214 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Baldinof\RoadRunnerBundle\Reboot; | ||
|
||
class ChainRebootStrategy implements KernelRebootStrategyInterface | ||
{ | ||
/** | ||
* @var iterable<KernelRebootStrategyInterface> | ||
*/ | ||
private iterable $strategies; | ||
|
||
/** | ||
* @param iterable<KernelRebootStrategyInterface> $strategies | ||
*/ | ||
public function __construct(iterable $strategies) | ||
{ | ||
$this->strategies = $strategies; | ||
} | ||
|
||
public function shouldReboot(): bool | ||
{ | ||
foreach ($this->strategies as $strategy) { | ||
if ($strategy->shouldReboot()) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public function clear(): void | ||
{ | ||
foreach ($this->strategies as $strategy) { | ||
$strategy->clear(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Baldinof\RoadRunnerBundle\Reboot; | ||
|
||
use Baldinof\RoadRunnerBundle\Reboot\ChainRebootStrategy; | ||
use Baldinof\RoadRunnerBundle\Reboot\KernelRebootStrategyInterface; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ChainRebootStrategyTest extends TestCase | ||
{ | ||
public function test_it_does_not_reboot_by_default() | ||
{ | ||
$strategy = new ChainRebootStrategy([]); | ||
$this->assertFalse($strategy->shouldReboot()); | ||
} | ||
|
||
public function test_it_reboot_if_one_strategy_reboot() | ||
{ | ||
$strategy = new ChainRebootStrategy([ | ||
$this->createStrategy(true), | ||
$this->createStrategy(false), | ||
]); | ||
|
||
$this->assertTrue($strategy->shouldReboot()); | ||
|
||
$strategy = new ChainRebootStrategy([ | ||
$this->createStrategy(false), | ||
$this->createStrategy(true), | ||
]); | ||
} | ||
|
||
public function test_it_does_not_reboot_if_no_strategy_reboot() | ||
{ | ||
$strategy = new ChainRebootStrategy([ | ||
$this->createStrategy(false), | ||
$this->createStrategy(false), | ||
]); | ||
$this->assertFalse($strategy->shouldReboot()); | ||
} | ||
|
||
private function createStrategy(bool $shouldReboot): KernelRebootStrategyInterface | ||
{ | ||
return new class($shouldReboot) implements KernelRebootStrategyInterface { | ||
private bool $shouldReboot; | ||
|
||
public function __construct(bool $shouldReboot) | ||
{ | ||
$this->shouldReboot = $shouldReboot; | ||
} | ||
|
||
public function shouldReboot(): bool | ||
{ | ||
return $this->shouldReboot; | ||
} | ||
|
||
public function clear(): void | ||
{ | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters