This file contains hidden or 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
<?php | |
// PreHandlerInterface.php | |
interface PreHandlerInterface | |
{ | |
/** | |
* Should contains what you want to do before handling the message | |
*/ | |
public function preHandle(object $message); | |
This file contains hidden or 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
<?php | |
// Message | |
class MyMessage | |
{ | |
// boring stuff that you should adapt to your fit. | |
public $id = 42; | |
} | |
// Handler |
This file contains hidden or 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
<?php | |
namespace App\Debug; | |
use Symfony\Component\HttpKernel\Event\ResponseEvent; | |
use Symfony\Component\EventDispatcher\Attribute\AsEventListener; | |
use Symfony\Component\DependencyInjection\Attribute\When; | |
#[When(env: 'test')] | |
#[AsEventListener] |
This file contains hidden or 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
<?php | |
namespace App\Tests; | |
use PHPUnit\Framework\TestCase; | |
final class DemoTimeoutTest extends TestCase | |
{ | |
public function testItsTrue(): void | |
{ |
This file contains hidden or 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
# phpunit file configuration, phpunit.xml | |
<phpunit> | |
... | |
<extensions> | |
<extension class="App\Test\TimeoutPHPUnitExtension" /> | |
</extensions> | |
</phpunit> |
This file contains hidden or 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
<?php | |
namespace App\Test; | |
use App\Test\TimeoutMaxDuration; | |
use PHPUnit\Framework\TestCase; | |
use PHPUnit\Runner\AfterTestHook; | |
class TimeoutPHPUnitExtension extends TestCase implements AfterTestHook | |
{ |
This file contains hidden or 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
<?php | |
final class TimeoutMaxDuration | |
{ | |
private const DEFAULT = 10; | |
// let's set 10 seconds by default; | |
public static int $timeout = self::DEFAULT; | |
public static function resetTimeout(): void |
This file contains hidden or 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
<?php | |
/** | |
* @medium | |
* // timeout is 10 seconds by default, | |
* // duration can be configured and the test will be risky if timeout is reached but you can set it to fail. | |
*/ | |
function testItSetANewRecord() {} |
This file contains hidden or 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
// AppFileValidator.php | |
<?php | |
declare(strict_types=1); | |
namespace App\Constraints; | |
use Symfony\Component\HttpFoundation\File\File; | |
use Symfony\Component\HttpFoundation\File\UploadedFile; | |
use Symfony\Component\Mime\MimeTypesInterface; | |
use Symfony\Component\Validator\Constraint; |
This file contains hidden or 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
// AppFileConstraint.php | |
<?php | |
declare(strict_types=1); | |
namespace App\Constraints; | |
use Symfony\Component\Validator\Constraints\File; | |
// This class is used as marker to validate File by guessing the MIME type with the `FileBinaryMimeTypeGuesserDecorator` first. | |
final class AppFile extends File |