-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from shopware/clear-cache-always
feat: add option to always clear cache after deployment, fixes #21
- Loading branch information
Showing
6 changed files
with
101 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopware\Deployment\Integration; | ||
|
||
use Shopware\Deployment\Config\ProjectConfiguration; | ||
use Shopware\Deployment\Event\PostDeploy; | ||
use Shopware\Deployment\Helper\ProcessHelper; | ||
use Symfony\Component\EventDispatcher\Attribute\AsEventListener; | ||
|
||
#[AsEventListener(event: PostDeploy::class, method: '__invoke')] | ||
readonly class ClearAlwaysCacheSubscriber | ||
{ | ||
public function __construct( | ||
private ProjectConfiguration $projectConfiguration, | ||
private ProcessHelper $processHelper, | ||
) { | ||
} | ||
|
||
public function __invoke(PostDeploy $event): void | ||
{ | ||
if (!$this->projectConfiguration->alwaysClearCache) { | ||
return; | ||
} | ||
|
||
$this->processHelper->console(['cache:pool:clear', 'cache.http', 'cache.object']); | ||
} | ||
} |
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
3 changes: 3 additions & 0 deletions
3
tests/Config/_fixtures/always-clear-cache/.shopware-project.yml
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,3 @@ | ||
deployment: | ||
cache: | ||
always_clear: true |
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,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopware\Deployment\Tests\Integration; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
use Shopware\Deployment\Config\ProjectConfiguration; | ||
use Shopware\Deployment\Event\PostDeploy; | ||
use Shopware\Deployment\Helper\ProcessHelper; | ||
use Shopware\Deployment\Integration\ClearAlwaysCacheSubscriber; | ||
use Shopware\Deployment\Struct\RunConfiguration; | ||
use Symfony\Component\Console\Output\NullOutput; | ||
|
||
#[CoversClass(ClearAlwaysCacheSubscriber::class)] | ||
class ClearAlwaysCacheSubscriberTest extends TestCase | ||
{ | ||
private ProjectConfiguration&MockObject $projectConfiguration; | ||
private ProcessHelper&MockObject $processHelper; | ||
private ClearAlwaysCacheSubscriber $subscriber; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->projectConfiguration = $this->createMock(ProjectConfiguration::class); | ||
$this->processHelper = $this->createMock(ProcessHelper::class); | ||
$this->subscriber = new ClearAlwaysCacheSubscriber($this->projectConfiguration, $this->processHelper); | ||
} | ||
|
||
public function testInvokeWithAlwaysClearCacheEnabled(): void | ||
{ | ||
$this->projectConfiguration->alwaysClearCache = true; | ||
|
||
$this->processHelper | ||
->expects($this->once()) | ||
->method('console') | ||
->with(['cache:pool:clear', 'cache.http', 'cache.object']); | ||
|
||
$event = new PostDeploy(new RunConfiguration(), new NullOutput()); | ||
$this->subscriber->__invoke($event); | ||
} | ||
|
||
public function testInvokeWithAlwaysClearCacheDisabled(): void | ||
{ | ||
$this->projectConfiguration->alwaysClearCache = false; | ||
|
||
$this->processHelper | ||
->expects($this->never()) | ||
->method('console'); | ||
|
||
$event = new PostDeploy(new RunConfiguration(), new NullOutput()); | ||
$this->subscriber->__invoke($event); | ||
} | ||
} |