funk-spec / symfony-extension
extension that helps using your symfony application's services in your tests
Installs: 22 642
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Type:testwork-extension
Requires
- php: >=5.4
- docteurklein/funk-spec: ^0.1
- symfony/dependency-injection: ^3.3|^4.0
Requires (Dev)
- symfony/http-kernel: ^3.3|^4.0
This package is not auto-updated.
Last update: 2024-10-26 20:37:41 UTC
README
composer require --dev funk-spec/symfony-extension
What ?
A funk-spec extension that integrates your symfony application with your specs.
It will:
- 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.
How ?
In your funk.yml:
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:
<?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:
default: extensions: FunkSpec\Extension\Symfony\Extension: doctrine: rollback: false
This depends on the presence of a doctrine
service in the application Kernel, insanceof ManagerRegistry
.