forked from php-enqueue/enqueue-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reset services tagged by "kernel.reset".
- Loading branch information
Showing
8 changed files
with
203 additions
and
4 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
27 changes: 27 additions & 0 deletions
27
pkg/enqueue-bundle/Consumption/Extension/ResetServicesExtension.php
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,27 @@ | ||
<?php | ||
|
||
namespace Enqueue\Bundle\Consumption\Extension; | ||
|
||
use Enqueue\Consumption\Context\MessageReceived; | ||
use Enqueue\Consumption\MessageReceivedExtensionInterface; | ||
use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter; | ||
|
||
class ResetServicesExtension implements MessageReceivedExtensionInterface | ||
{ | ||
/** | ||
* @var ServicesResetter | ||
*/ | ||
private $resetter; | ||
|
||
public function __construct(ServicesResetter $resetter) | ||
{ | ||
$this->resetter = $resetter; | ||
} | ||
|
||
public function onMessageReceived(MessageReceived $context): void | ||
{ | ||
$context->getLogger()->debug('[ResetServicesExtension] Resetting services.'); | ||
|
||
$this->resetter->reset(); | ||
} | ||
} |
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
61 changes: 61 additions & 0 deletions
61
pkg/enqueue-bundle/Tests/Unit/Consumption/Extension/ResetServicesExtensionTest.php
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,61 @@ | ||
<?php | ||
|
||
namespace Enqueue\Bundle\Tests\Unit\Consumption\Extension; | ||
|
||
use Doctrine\Common\Persistence\ManagerRegistry; | ||
use Enqueue\Bundle\Consumption\Extension\ResetServicesExtension; | ||
use Enqueue\Consumption\Context\MessageReceived; | ||
use Interop\Queue\Consumer; | ||
use Interop\Queue\Context as InteropContext; | ||
use Interop\Queue\Message; | ||
use Interop\Queue\Processor; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter; | ||
|
||
class ResetServicesExtensionTest extends TestCase | ||
{ | ||
public function testCouldBeConstructedWithRequiredArguments() | ||
{ | ||
new ResetServicesExtension($this->createResetterMock()); | ||
} | ||
|
||
public function testItShouldResetServices() | ||
{ | ||
$resetter = $this->createResetterMock(); | ||
$resetter | ||
->expects($this->once()) | ||
->method('reset') | ||
; | ||
|
||
$context = $this->createContext(); | ||
$context->getLogger() | ||
->expects($this->once()) | ||
->method('debug') | ||
->with('[ResetServicesExtension] Resetting services.') | ||
; | ||
|
||
$extension = new ResetServicesExtension($resetter); | ||
$extension->onMessageReceived($context); | ||
} | ||
|
||
protected function createContext(): MessageReceived | ||
{ | ||
return new MessageReceived( | ||
$this->createMock(InteropContext::class), | ||
$this->createMock(Consumer::class), | ||
$this->createMock(Message::class), | ||
$this->createMock(Processor::class), | ||
1, | ||
$this->createMock(LoggerInterface::class) | ||
); | ||
} | ||
|
||
/** | ||
* @return \PHPUnit_Framework_MockObject_MockObject|ManagerRegistry | ||
*/ | ||
protected function createResetterMock(): ServicesResetter | ||
{ | ||
return $this->createMock(ServicesResetter::class); | ||
} | ||
} |
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