Personal library of Symfony utilities: Doctrine ID traits and reusable Behat contexts.
- PHP >= 8.4
- Symfony 7 or 8
- Doctrine ORM 3
composer require barlito/utilsAdd a UUID or ULID primary key to an entity (generated by the Symfony bridge generators):
use Barlito\Utils\Traits\IdUuidTrait; // or IdUlidTrait
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
class MyEntity
{
use IdUuidTrait;
}Register the contexts in your behat.yml suite and wire them as services:
Barlito\Utils\Behat\Component\EntityManagerContext— assert on database state:
Given a "User" entity found by "[email protected]" should match:
| name | Foo |
Given a "User" entity found by "deletedAt:date=2024-01-01" should not exist
Given I should find 3 "User" entity found by "status=active"
Then I create a "User" entity with data:
"""
{"email": "[email protected]"}
"""Barlito\Utils\Behat\Component\LoggerContext+Barlito\Utils\Behat\Mock\LoggerMock— decorate the logger in test env withLoggerMock, then:
Then the logger logged the error with message "Something went wrong"
Then the logger logged an error containing "went wrong"The config/ directory ships ready-to-use QA configs for consuming projects (install the tools in your own require-dev):
PHPStan — phpstan.dist.neon:
includes:
- vendor/barlito/utils/config/phpstan.neon
parameters:
paths:
- srcRector — rector.php:
$builder = require 'vendor/barlito/utils/config/rector.php';
return $builder
->withPaths([__DIR__ . '/src'])
->withCache(__DIR__ . '/var/cache/rector');PHP-CS-Fixer — run with the shipped config (paths resolve from your project root):
vendor/bin/php-cs-fixer fix --config=vendor/barlito/utils/config/.php-cs-fixer.dist.phpPHPCS (PSR-12):
vendor/bin/phpcs --standard=vendor/barlito/utils/config/phpcs.xml.dist srcPHPMD:
vendor/bin/phpmd src text vendor/barlito/utils/config/phpmd.xmlmake deploy # start the dev container
make phpstan # static analysis (level 8)
make cs # coding standards check (php-cs-fixer, @Symfony)
make cs-fix # apply coding standards
make rector # rector dry-run
make rector-fix # apply rector rules
make phpcs # PSR-12 check (phpcs)
make phpmd # mess detection (phpmd, isolated via vendor-bin)
make qa # run the whole QA suiteThe same commands are available as composer scripts (composer phpstan, composer cs, composer rector, ...).