Skip to content

Instantly share code, notes, and snippets.

View ismail1432's full-sized avatar
🏠
Looking for remote job

Smaine Milianni ismail1432

🏠
Looking for remote job
View GitHub Profile
<?php
// PreHandlerInterface.php
interface PreHandlerInterface
{
/**
* Should contains what you want to do before handling the message
*/
public function preHandle(object $message);
<?php
// Message
class MyMessage
{
// boring stuff that you should adapt to your fit.
public $id = 42;
}
// Handler
<?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]
<?php
namespace App\Tests;
use PHPUnit\Framework\TestCase;
final class DemoTimeoutTest extends TestCase
{
public function testItsTrue(): void
{
# phpunit file configuration, phpunit.xml
<phpunit>
...
<extensions>
<extension class="App\Test\TimeoutPHPUnitExtension" />
</extensions>
</phpunit>
<?php
namespace App\Test;
use App\Test\TimeoutMaxDuration;
use PHPUnit\Framework\TestCase;
use PHPUnit\Runner\AfterTestHook;
class TimeoutPHPUnitExtension extends TestCase implements AfterTestHook
{
<?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
<?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() {}
// 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;
// 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