-
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
14 changed files
with
190 additions
and
50 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,98 @@ | ||
<?php | ||
|
||
namespace Tests\Functional; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use PHPUnit\Framework\Assert; | ||
use Symfony\Component\HttpKernel\KernelInterface; | ||
use Tests\Functional\app\AppKernel; | ||
|
||
trait FunctionalTestTrait | ||
{ | ||
/** | ||
* @var KernelInterface | ||
*/ | ||
private $kernel; | ||
|
||
/** | ||
* @var Connection | ||
*/ | ||
protected $connection; | ||
|
||
/** | ||
* @BeforeScenario | ||
*/ | ||
public function setUp(): void | ||
{ | ||
$this->kernel = new AppKernel('test', true); | ||
$this->kernel->boot(); | ||
$this->connection = $this->kernel->getContainer()->get('doctrine.dbal.default_connection'); | ||
} | ||
|
||
/** | ||
* @AfterScenario | ||
*/ | ||
public function tearDown(): void | ||
{ | ||
$this->kernel->shutdown(); | ||
} | ||
|
||
/** | ||
* @Then there are :count rows | ||
* @Then there is :count row | ||
*/ | ||
public function assertRowCount($count): void | ||
{ | ||
Assert::assertEquals($count, $this->connection->fetchColumn('SELECT COUNT(*) FROM test')); | ||
} | ||
|
||
/** | ||
* @When I insert a new row | ||
*/ | ||
public function insertRow(): void | ||
{ | ||
$this->connection->insert('test', [ | ||
'test' => 'foo', | ||
]); | ||
} | ||
|
||
/** | ||
* @When I begin a transaction | ||
*/ | ||
public function beginTransaction(): void | ||
{ | ||
$this->connection->beginTransaction(); | ||
} | ||
|
||
/** | ||
* @When I rollback the transaction | ||
*/ | ||
public function rollbackTransaction(): void | ||
{ | ||
$this->connection->rollBack(); | ||
} | ||
|
||
/** | ||
* @When I commit the transaction | ||
*/ | ||
public function commitTransaction(): void | ||
{ | ||
$this->connection->commit(); | ||
} | ||
|
||
/** | ||
* @When I create a savepoint named :name | ||
*/ | ||
public function createSavepoint(string $name): void | ||
{ | ||
$this->connection->createSavepoint($name); | ||
} | ||
|
||
/** | ||
* @When I rollback the savepoint named :name | ||
*/ | ||
public function rollbackSavepoint(string $name): void | ||
{ | ||
$this->connection->rollbackSavepoint($name); | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
tests/Functional/AppKernel.php → tests/Functional/app/AppKernel.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
File renamed without changes.
File renamed without changes.
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,5 @@ | ||
parameters: | ||
db_host: 127.0.0.1 | ||
db_name: doctrine_test_bundle | ||
db_user: root | ||
db_password: ~ |
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,31 @@ | ||
Feature:: Behat integration | ||
In order to improve database usage in behat tests | ||
developers need to be able to use DamaDoctrineTestBundle with Behat | ||
|
||
Scenario: Changing DB state | ||
Given there are 0 rows | ||
When I insert a new row | ||
Then there is 1 row | ||
|
||
Scenario: Change db state within rolled back transaction | ||
Given there are 0 rows | ||
When I begin a transaction | ||
And I insert a new row | ||
Then there is 1 row | ||
When I rollback the transaction | ||
Then there are 0 rows | ||
|
||
Scenario: Change db state within committed transaction | ||
Given there are 0 rows | ||
When I begin a transaction | ||
And I insert a new row | ||
And I commit the transaction | ||
Then there is 1 row | ||
|
||
Scenario: Change db state with savepoint | ||
Given there are 0 rows | ||
When I create a savepoint named "foo" | ||
And I insert a new row | ||
Then there is 1 row | ||
When I rollback the savepoint named "foo" | ||
Then there are 0 rows |
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,22 @@ | ||
<?php | ||
|
||
use Behat\Behat\Context\Context; | ||
use Symfony\Component\Process\PhpExecutableFinder; | ||
use Symfony\Component\Process\Process; | ||
use Tests\Functional\FunctionalTestTrait; | ||
|
||
class FeatureContext implements Context | ||
{ | ||
use FunctionalTestTrait; | ||
|
||
/** | ||
* @BeforeSuite | ||
*/ | ||
public static function bootstrap(): void | ||
{ | ||
$executableFinder = new PhpExecutableFinder(); | ||
$php = $executableFinder->find(false); | ||
|
||
(new Process([$php, __DIR__.'/../../../bootstrap.php']))->mustRun(); | ||
} | ||
} |
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,10 @@ | ||
default: | ||
autoload: | ||
'': '%paths.base%/Functional/features/bootstrap' | ||
|
||
suites: | ||
functional: | ||
paths: ['%paths.base%/Functional/features'] | ||
|
||
extensions: | ||
DAMA\DoctrineTestBundle\Behat\ServiceContainer\DoctrineExtension: ~ |
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