forked from mpoiriert/draw
-
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.
- Loading branch information
1 parent
94bffd2
commit b8e3518
Showing
13 changed files
with
297 additions
and
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Message; | ||
|
||
class FailedMessage | ||
{ | ||
} |
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
30 changes: 30 additions & 0 deletions
30
...framework-extra-bundle/DependencyInjection/Compiler/ConsolePathAwareCompilerPassTrait.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,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; | ||
|
||
trait ConsolePathAwareCompilerPassTrait | ||
{ | ||
private function setConsolePathArgument(ContainerBuilder $container, string $definitionId): void | ||
{ | ||
try { | ||
$definition = $container->findDefinition($definitionId); | ||
} catch (ServiceNotFoundException) { | ||
return; | ||
} | ||
|
||
if (null === $symfonyConsolePath = $container->getParameter('draw.symfony_console_path')) { | ||
$symfonyConsolePath = $container->getParameterBag()->resolveValue('%kernel.project_dir%/bin/console'); | ||
} | ||
|
||
if (false === realpath($symfonyConsolePath)) { | ||
throw new \RuntimeException('The draw_framework_extra.symfony_console_path value ['.$symfonyConsolePath.'] is invalid'); | ||
} | ||
|
||
$definition->setArgument('$consolePath', realpath($symfonyConsolePath)); | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
...le/DependencyInjection/Compiler/MessengerRetryFailedMessageMessageHandlerCompilerPass.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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler; | ||
|
||
use Draw\Component\Messenger\MessageHandler\RetryFailedMessageMessageHandler; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
class MessengerRetryFailedMessageMessageHandlerCompilerPass implements CompilerPassInterface | ||
{ | ||
use ConsolePathAwareCompilerPassTrait; | ||
|
||
public function process(ContainerBuilder $container): void | ||
{ | ||
$this->setConsolePathArgument($container, RetryFailedMessageMessageHandler::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
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
64 changes: 64 additions & 0 deletions
64
packages/messenger/Tests/MessageHandler/RetryFailedMessageMessageHandlerTest.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,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Draw\Component\Messenger\Tests\MessageHandler; | ||
|
||
use App\Entity\MessengerMessage; | ||
use Draw\Component\Messenger\Message\RetryFailedMessageMessage; | ||
use Draw\Component\Messenger\MessageHandler\RetryFailedMessageMessageHandler; | ||
use Draw\Contracts\Process\ProcessFactoryInterface; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
use Ramsey\Uuid\Uuid; | ||
use Symfony\Component\Process\Process; | ||
|
||
#[ | ||
CoversClass(RetryFailedMessageMessage::class), | ||
CoversClass(RetryFailedMessageMessageHandler::class), | ||
] | ||
class RetryFailedMessageMessageHandlerTest extends TestCase | ||
{ | ||
private const CONSOLE_PATH = 'bin/console'; | ||
|
||
private RetryFailedMessageMessageHandler $handler; | ||
|
||
private ProcessFactoryInterface&MockObject $processFactory; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->handler = new RetryFailedMessageMessageHandler( | ||
$this->processFactory = $this->createMock(ProcessFactoryInterface::class), | ||
self::CONSOLE_PATH | ||
); | ||
} | ||
|
||
public function testHandleRetryFailedMessageMessage(): void | ||
{ | ||
$this->processFactory | ||
->expects(static::once()) | ||
->method('create') | ||
->with( | ||
[ | ||
self::CONSOLE_PATH, | ||
'messenger:failed:retry', | ||
$messageId = Uuid::uuid6()->toString(), | ||
'--force', | ||
] | ||
) | ||
->willReturn($process = $this->createMock(Process::class)); | ||
|
||
$process | ||
->expects(static::once()) | ||
->method('mustRun'); | ||
|
||
$this->handler->handleRetryFailedMessageMessage( | ||
new RetryFailedMessageMessage( | ||
(new MessengerMessage())->setId($messageId) | ||
) | ||
); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
tests/SonataIntegrationBundle/Messenger/Action/RetryFailedMessageActionTest.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,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SonataIntegrationBundle\Messenger\Action; | ||
|
||
use App\Entity\MessengerMessage; | ||
use App\Message\FailedMessage; | ||
use App\Tests\SonataIntegrationBundle\WebTestCaseTrait; | ||
use Draw\Bundle\TesterBundle\PHPUnit\Extension\SetUpAutowire\AutowiredInterface; | ||
use Draw\Bundle\TesterBundle\PHPUnit\Extension\SetUpAutowire\AutowireService; | ||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
use Symfony\Component\Messenger\MessageBusInterface; | ||
use Symfony\Component\Messenger\Stamp\TransportNamesStamp; | ||
|
||
class RetryFailedMessageActionTest extends WebTestCase implements AutowiredInterface | ||
{ | ||
use WebTestCaseTrait; | ||
|
||
#[AutowireService] | ||
private MessageBusInterface $messageBus; | ||
|
||
public function testRetry(): void | ||
{ | ||
$this->messageBus->dispatch( | ||
new FailedMessage(), | ||
[ | ||
new TransportNamesStamp('failed'), | ||
] | ||
); | ||
|
||
$this->login('[email protected]'); | ||
|
||
static::assertInstanceOf( | ||
MessengerMessage::class, | ||
$failedMessage = $this->entityManager | ||
->getRepository(MessengerMessage::class) | ||
->findOneBy(['queueName' => 'failed']) | ||
); | ||
static::assertSame(FailedMessage::class, $failedMessage->getMessageClass()); | ||
|
||
static::$client->request('GET', sprintf('/admin/app/messengermessage/%s/retry', $failedMessage->getId())); | ||
|
||
static::assertResponseStatusCodeSame(302); | ||
|
||
static::$client->followRedirect(); | ||
|
||
static::assertSelectorTextContains('.alert-success', 'Retry message successfully dispatched.'); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
tests/SonataIntegrationBundle/User/Action/UnlockTraitUserActionTest.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,56 @@ | ||
<?php | ||
|
||
namespace App\Tests\SonataIntegrationBundle\User\Action; | ||
|
||
use App\Tests\SonataIntegrationBundle\WebTestCaseTrait; | ||
use Draw\Bundle\TesterBundle\PHPUnit\Extension\SetUpAutowire\AutowiredInterface; | ||
use Draw\Bundle\UserBundle\Entity\UserLock; | ||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
|
||
class UnlockTraitUserActionTest extends WebTestCase implements AutowiredInterface | ||
{ | ||
use WebTestCaseTrait; | ||
|
||
public function testUnlock(): void | ||
{ | ||
$this->login('[email protected]'); | ||
|
||
$user = $this->getUser('[email protected]'); | ||
|
||
$userLock = $user->getLocks()['manual-lock']; | ||
|
||
$userLock->setUnlockUntil(null); | ||
|
||
static::$client->request('GET', sprintf('/admin/app/user/%s/unlock', $user->getId())); | ||
|
||
static::assertResponseStatusCodeSame(302); | ||
static::assertResponseHeaderSame( | ||
'Location', | ||
sprintf('/admin/app/user/%s/show', $user->getId()) | ||
); | ||
|
||
static::$client->followRedirect(); | ||
|
||
static::assertResponseIsSuccessful(); | ||
|
||
static::assertSelectorTextContains('.alert-success', 'The user lock has been unlock for the next 24 hour'); | ||
|
||
$userLock = $this->entityManager->find( | ||
UserLock::class, | ||
$userLock->getId() | ||
); | ||
|
||
static::assertEqualsWithDelta(new \DateTimeImmutable('+ 24 hours'), $userLock->getUnlockUntil(), 2); | ||
} | ||
|
||
public function testNoAccess(): void | ||
{ | ||
$this->login('[email protected]'); | ||
|
||
$user = $this->getUser('[email protected]'); | ||
|
||
static::$client->request('GET', sprintf('/admin/app/user/%s/unlock', $user->getId())); | ||
|
||
static::assertResponseStatusCodeSame(403); | ||
} | ||
} |
Oops, something went wrong.