diff --git a/composer.json b/composer.json index 25f6af25..f878cdc9 100644 --- a/composer.json +++ b/composer.json @@ -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" } + } } diff --git a/src/Services/DatabaseTools/ORMDatabaseTool.php b/src/Services/DatabaseTools/ORMDatabaseTool.php index e30acd4e..3fd6d29b 100644 --- a/src/Services/DatabaseTools/ORMDatabaseTool.php +++ b/src/Services/DatabaseTools/ORMDatabaseTool.php @@ -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; @@ -157,6 +158,9 @@ protected function getPurger(): ORMPurger return $purger; } + /** + * @throws Exception + */ protected function createDatabaseIfNotExists(): void { $params = $this->connection->getParams(); @@ -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(); diff --git a/src/Services/DatabaseTools/ORMSqliteDatabaseTool.php b/src/Services/DatabaseTools/ORMSqliteDatabaseTool.php index 9b3f4f54..be665ab5 100644 --- a/src/Services/DatabaseTools/ORMSqliteDatabaseTool.php +++ b/src/Services/DatabaseTools/ORMSqliteDatabaseTool.php @@ -53,6 +53,7 @@ public function loadFixtures(array $classNames = [], bool $append = false): Abst $cacheDriver->clear(); } } else { + # legacy $cacheDriver = $config->getMetadataCacheImpl(); if ($cacheDriver) { @@ -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'); } @@ -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'); } diff --git a/tests/App/Entity/User.php b/tests/App/Entity/User.php index 78053129..73137ffd 100644 --- a/tests/App/Entity/User.php +++ b/tests/App/Entity/User.php @@ -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() diff --git a/tests/App/config.yml b/tests/App/config.yml index 55682168..7b3bc723 100644 --- a/tests/App/config.yml +++ b/tests/App/config.yml @@ -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: