-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
102 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace DAMA\DoctrineTestBundle\Behat; | ||
|
||
use Behat\Behat\EventDispatcher\Event\ExampleTested; | ||
use Behat\Behat\EventDispatcher\Event\ScenarioTested; | ||
use Behat\Testwork\EventDispatcher\Event\ExerciseCompleted; | ||
use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
class BehatListener implements EventSubscriberInterface | ||
{ | ||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
ExerciseCompleted::BEFORE => 'enableStaticConnection', | ||
ExerciseCompleted::AFTER => 'disableStaticConnection', | ||
ScenarioTested::BEFORE => ['beginTransaction', 255], | ||
ExampleTested::BEFORE => ['beginTransaction', 255], | ||
ScenarioTested::AFTER => ['rollBack', -255], | ||
ExampleTested::AFTER => ['rollBack', -255], | ||
]; | ||
} | ||
|
||
public function enableStaticConnection(): void | ||
{ | ||
StaticDriver::setKeepStaticConnections(true); | ||
} | ||
|
||
public function disableStaticConnection(): void | ||
{ | ||
StaticDriver::setKeepStaticConnections(false); | ||
} | ||
|
||
public function beginTransaction(): void | ||
{ | ||
StaticDriver::beginTransaction(); | ||
} | ||
|
||
public function rollBack(): void | ||
{ | ||
StaticDriver::rollBack(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/DAMA/DoctrineTestBundle/Behat/ServiceContainer/DoctrineExtension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace DAMA\DoctrineTestBundle\Behat\ServiceContainer; | ||
|
||
use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension; | ||
use Behat\Testwork\ServiceContainer\Extension; | ||
use Behat\Testwork\ServiceContainer\ExtensionManager; | ||
use DAMA\DoctrineTestBundle\Behat\BehatListener; | ||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
class DoctrineExtension implements Extension | ||
{ | ||
public function getConfigKey(): string | ||
{ | ||
return 'dama_doctrine'; | ||
} | ||
|
||
public function initialize(ExtensionManager $extensionManager): void | ||
{ | ||
} | ||
|
||
public function configure(ArrayNodeDefinition $builder): void | ||
{ | ||
} | ||
|
||
public function load(ContainerBuilder $container, array $config): void | ||
{ | ||
$container->register('dama_doctrine_test.listener', BehatListener::class) | ||
->addTag(EventDispatcherExtension::SUBSCRIBER_TAG); | ||
} | ||
|
||
public function process(ContainerBuilder $container): void | ||
{ | ||
} | ||
} |