Skip to content

Commit

Permalink
feat: allow doctrine/orm 3 and doctrine/dbal 4 (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris8934 committed Feb 17, 2024
1 parent 6eaf304 commit b75c271
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 86 deletions.
150 changes: 76 additions & 74 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,78 +1,80 @@
{
"name": "liip/test-fixtures-bundle",
"description": "This bundles enables efficient loading of Doctrine fixtures in functional test-cases for Symfony applications",
"keywords": ["symfony", "testing", "fixtures"],
"type": "symfony-bundle",
"license": "MIT",
"authors": [
{
"name": "Liip AG",
"homepage": "http://www.liip.ch/"
},
{
"name": "Community contributions",
"homepage": "https://github.com/liip/LiipTestFixturesBundle/contributors"
}
],
"require": {
"php": "^7.4 || ^8.0",
"doctrine/common": "^2.13 || ^3.0",
"doctrine/persistence": "^1.3.3 || ^2.0 || ^3.0",
"symfony/deprecation-contracts": "^2.1 || ^3.0",
"symfony/event-dispatcher": "^5.4 || ^6.3 || ^7.0",
"symfony/event-dispatcher-contracts": "^1 || ^2 || ^3",
"symfony/framework-bundle": "^5.4 || ^6.3 || ^7.0",
"symfony/yaml": "^5.4 || ^6.3 || ^7.0"
"name": "liip/test-fixtures-bundle",
"description": "This bundles enables efficient loading of Doctrine fixtures in functional test-cases for Symfony applications",
"keywords": ["symfony", "testing", "fixtures"],
"type": "symfony-bundle",
"license": "MIT",
"authors": [
{
"name": "Liip AG",
"homepage": "http://www.liip.ch/"
},
"require-dev": {
"doctrine/annotations": "^1.8.0 || ^2.0",
"doctrine/data-fixtures": "^1.7",
"doctrine/doctrine-bundle": "^2.11",
"doctrine/doctrine-fixtures-bundle": "^3.5.1 || ^4.0",
"doctrine/orm": "^2.7 || ^3.0",
"doctrine/phpcr-bundle": "^2.4.3 || ^3.0",
"doctrine/phpcr-odm": "^1.7.2 || 2.x-dev as 2.0",
"jackalope/jackalope-doctrine-dbal": "^1.10.1 || 2.x-dev as 2.0",
"monolog/monolog": "^1.25.1 || ^2.0 || ^3.0",
"phpunit/phpunit": "^9.6 || ^10.4",
"symfony/doctrine-bridge": "^5.4 || ^6.3 || ^7.0",
"symfony/monolog-bridge": "^5.4 || ^6.3 || ^7.0",
"symfony/monolog-bundle": "^3.2",
"symfony/phpunit-bridge": "^5.4 || ^6.3 || ^7.0",
"theofidry/alice-data-fixtures": "^1.5.2"
},
"conflict": {
"doctrine/annotations": "<1.2.7 || >=3.0",
"doctrine/dbal": "<2.11"
},
"suggest": {
"doctrine/dbal": "Required when using the fixture loading functionality with an ORM and SQLite",
"doctrine/doctrine-fixtures-bundle": "Required when using the fixture loading functionality",
"doctrine/orm": "Required when using the fixture loading functionality with an ORM and SQLite",
"hautelook/alice-bundle": "Required when using loadFixtureFiles functionality with custom providers",
"theofidry/alice-data-fixtures": "Required when using loadFixtureFiles functionality"
},
"autoload": {
"psr-4": {
"Liip\\TestFixturesBundle\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Liip\\Acme\\Tests\\": "tests/"
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
"composer/package-versions-deprecated": true,
"symfony/flex": true,
"ocramius/package-versions": true
}
},
"extra": {
"branch-alias": {
"dev-master": "2.x-dev"
}
{
"name": "Community contributions",
"homepage": "https://github.com/liip/LiipTestFixturesBundle/contributors"
}
],
"require": {
"php": "^7.4 || ^8.0",
"doctrine/common": "^2.13 || ^3.0",
"doctrine/persistence": "^1.3.3 || ^2.0 || ^3.0",
"symfony/deprecation-contracts": "^2.1 || ^3.0",
"symfony/event-dispatcher": "^5.4 || ^6.3 || ^7.0",
"symfony/event-dispatcher-contracts": "^1 || ^2 || ^3",
"symfony/framework-bundle": "^5.4 || ^6.3 || ^7.0",
"symfony/yaml": "^5.4 || ^6.3 || ^7.0"
},
"require-dev": {
"doctrine/annotations": "^1.8.0 || ^2.0",
"doctrine/data-fixtures": "^1.7",
"doctrine/doctrine-bundle": "^2.11",
"doctrine/doctrine-fixtures-bundle": "^3.5.1 || ^4.0",
"doctrine/orm": "^2.7 || ^3.0",
"doctrine/phpcr-bundle": "^2.4.3 || 3.x-dev as 3.0",
"doctrine/phpcr-odm": "^1.7.2 || 2.x-dev as 2.0",
"jackalope/jackalope-doctrine-dbal": "2.0.0-RC1 @dev",
"monolog/monolog": "^1.25.1 || ^2.0 || ^3.0",
"phpunit/phpunit": "^9.6 || ^10.4",
"symfony/doctrine-bridge": "^5.4 || ^6.3 || ^7.0",
"symfony/monolog-bridge": "^5.4 || ^6.3 || ^7.0",
"symfony/monolog-bundle": "^3.2",
"symfony/phpunit-bridge": "^5.4 || ^6.3 || ^7.0",
"theofidry/alice-data-fixtures": "^1.5.2"
},
"conflict": {
"doctrine/annotations": "<1.2.7 || >=3.0",
"doctrine/dbal": "<2.11"
},
"suggest": {
"doctrine/dbal": "Required when using the fixture loading functionality with an ORM and SQLite",
"doctrine/doctrine-fixtures-bundle": "Required when using the fixture loading functionality",
"doctrine/orm": "Required when using the fixture loading functionality with an ORM and SQLite",
"hautelook/alice-bundle": "Required when using loadFixtureFiles functionality with custom providers",
"theofidry/alice-data-fixtures": "Required when using loadFixtureFiles functionality"
},
"autoload": {
"psr-4": {
"Liip\\TestFixturesBundle\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Liip\\Acme\\Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"sort-packages": true,
"allow-plugins": {
"composer/package-versions-deprecated": true,
"symfony/flex": true,
"ocramius/package-versions": true
}
},
"extra": {
"branch-alias": {
"dev-master": "2.x-dev"
}
}
}
10 changes: 7 additions & 3 deletions src/Services/DatabaseTools/ORMDatabaseTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Doctrine\Common\DataFixtures\ProxyReferenceRepository;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
Expand Down Expand Up @@ -157,6 +158,9 @@ protected function getPurger(): ORMPurger
return $purger;
}

/**
* @throws Exception
*/
protected function createDatabaseIfNotExists(): void
{
$params = $this->connection->getParams();
Expand All @@ -177,10 +181,10 @@ protected function createDatabaseIfNotExists(): void
// “An exception occurred in driver: SQLSTATE[HY000] [1049] Unknown database 'test'”

$tmpConnection = DriverManager::getConnection($params);
$tmpConnection->connect();

if (!\in_array($dbName, $tmpConnection->getSchemaManager()->listDatabases(), true)) {
$tmpConnection->getSchemaManager()->createDatabase($dbName);
if (!\in_array($dbName, $tmpConnection->createSchemaManager()->listDatabases(), true)) {

$tmpConnection->createSchemaManager()->createDatabase($dbName);
}

$tmpConnection->close();
Expand Down
3 changes: 3 additions & 0 deletions src/Services/DatabaseTools/ORMSqliteDatabaseTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function loadFixtures(array $classNames = [], bool $append = false): Abst
$cacheDriver->clear();
}
} else {
# legacy
$cacheDriver = $config->getMetadataCacheImpl();

if ($cacheDriver) {
Expand Down Expand Up @@ -139,6 +140,7 @@ protected function disableForeignKeyChecksIfApplicable(): void
if (method_exists($this->connection, 'executeQuery')) {
$this->connection->executeQuery('PRAGMA foreign_keys = 0');
} else {
# legacy
$this->connection->query('PRAGMA foreign_keys = 0');
}

Expand All @@ -158,6 +160,7 @@ protected function enableForeignKeyChecksIfApplicable(): void
if (method_exists($this->connection, 'executeQuery')) {
$this->connection->executeQuery('PRAGMA foreign_keys = 1');
} else {
# legacy
$this->connection->query('PRAGMA foreign_keys = 1');
}

Expand Down
15 changes: 12 additions & 3 deletions tests/App/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,28 @@

namespace Liip\Acme\Tests\App\Entity;

/**
* User.
*/
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(name: 'app_users')]
class User
{
#[ORM\Id]
#[ORM\Column(type: Types::INTEGER)]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private ?int $id = null;

#[ORM\Column(nullable: true)]
private string $name;

#[ORM\Column(nullable: true)]
private string $salt;

#[ORM\Column(nullable: true)]
private string $email;

#[ORM\Column(nullable: true)]
private ?string $dummyText = null;

public function __construct()
Expand Down
7 changes: 1 addition & 6 deletions tests/App/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,10 @@ doctrine:
connection: default
mappings:
LiipAcme:
type: php
type: attribute
dir: "%kernel.project_dir%/Entity"
prefix: 'Liip\Acme\Tests\App\Entity'
is_bundle: false
LiipAcmeYml:
type: "yml"
dir: "%kernel.project_dir%/Resources/config/doctrine"
prefix: 'Liip\Acme\Tests\App\Entity'
is_bundle: false

services:
_defaults:
Expand Down

0 comments on commit b75c271

Please sign in to comment.