funk-spec/symfony-extension
composer require --dev funk-spec/symfony-extension
What ?
A funk-spec extension that integrates your symfony application
with your specs., (*1)
It will:, (*2)
- resolve constructor arguments typehinted with
ContainerInterface
- wrap each example with a doctrine transaction and rollback afterwards
Why ?
For the same exact reason than the behat's one exists.
Both are relying on the TestWork framework.
Unfortunately, a lot of duplication exists between both, but no real tentative has been done yet
to abstract away the few differences., (*3)
How ?
In your funk.yml:, (*4)
default:
autoload:
tests: '%paths.base%'
suites:
default: ~
extensions:
FunkSpec\Extension\Symfony\Extension:
kernel:
class: App\Symfony\Kernel # or AppKernel (must be autoloadable)
env: test
Now your spec classes can have the container injected:, (*5)
<?php
namespace tests\Doctrine\Repository;
use Symfony\Component\DependencyInjection\ContainerInterface;
final class Products implements \Funk\Spec
{
public function __construct(ContainerInterface $container)
{
$this->products = $container->get('products'); // this is a repository
}
function it_works()
{
$this->products->find('77c4bb2e-2c18-4164-a899-7f969dec5c9d')->getId();
}
}
automatic transaction wrapping and rollback
Every example is ran in a transaction and rollbacked after each execution, except if you explicitely disable it:, (*6)
default:
extensions:
FunkSpec\Extension\Symfony\Extension:
doctrine:
rollback: false
This depends on the presence of a doctrine
service in the application Kernel, insanceof ManagerRegistry
., (*7)