|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace DAMA\DoctrineTestBundle\Behat; |
| 4 | + |
| 5 | +use Behat\Behat\EventDispatcher\Event\ExampleTested; |
| 6 | +use Behat\Behat\EventDispatcher\Event\ScenarioTested; |
| 7 | +use Behat\Testwork\EventDispatcher\Event\ExerciseCompleted; |
| 8 | +use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver; |
| 9 | +use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
| 10 | + |
| 11 | +class BehatListener implements EventSubscriberInterface |
| 12 | +{ |
| 13 | + public static function getSubscribedEvents(): array |
| 14 | + { |
| 15 | + return [ |
| 16 | + ExerciseCompleted::BEFORE => 'enableStaticConnection', |
| 17 | + ExerciseCompleted::AFTER => 'disableStaticConnection', |
| 18 | + ScenarioTested::BEFORE => ['beginTransaction', 255], |
| 19 | + ExampleTested::BEFORE => ['beginTransaction', 255], |
| 20 | + ScenarioTested::AFTER => ['rollBack', -255], |
| 21 | + ExampleTested::AFTER => ['rollBack', -255], |
| 22 | + ]; |
| 23 | + } |
| 24 | + |
| 25 | + public function enableStaticConnection(): void |
| 26 | + { |
| 27 | + StaticDriver::setKeepStaticConnections(true); |
| 28 | + } |
| 29 | + |
| 30 | + public function disableStaticConnection(): void |
| 31 | + { |
| 32 | + StaticDriver::setKeepStaticConnections(false); |
| 33 | + } |
| 34 | + |
| 35 | + public function beginTransaction(): void |
| 36 | + { |
| 37 | + StaticDriver::beginTransaction(); |
| 38 | + } |
| 39 | + |
| 40 | + public function rollBack(): void |
| 41 | + { |
| 42 | + StaticDriver::rollBack(); |
| 43 | + } |
| 44 | +} |
0 commit comments