From ac45c7631e8a01f66d140c8ec033578c69aa01a8 Mon Sep 17 00:00:00 2001 From: David Maicher Date: Tue, 19 Sep 2023 12:41:38 +0200 Subject: [PATCH] allow symfony 7.0 (#261) --- .github/workflows/ci.yml | 9 +++++ composer.json | 8 ++-- .../Doctrine/DBAL/MockDriver.php | 38 ++++++++++--------- .../Doctrine/DBAL/StaticDriverTest.php | 20 ++++++++-- 4 files changed, 49 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 17bc845..91a7f6e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,6 +38,10 @@ jobs: - php: 8.2 symfony_require: 6.3.* test_make_target: test + - php: 8.2 + symfony_require: 7.0.* + stability: dev + test_make_target: test steps: - uses: actions/checkout@v2 @@ -52,6 +56,10 @@ jobs: if: matrix.stability run: composer config minimum-stability ${{ matrix.stability }} + - name: Remove behat/behat + if: matrix.symfony_require == '7.0.*' + run: composer remove behat/behat --no-update --dev + - name: Install symfony/flex run: composer global config allow-plugins.symfony/flex true && composer global require symfony/flex @@ -62,6 +70,7 @@ jobs: run: make ${{ matrix.test_make_target }} - name: Behat + if: matrix.symfony_require != '7.0.*' run: make behat php-stan: diff --git a/composer.json b/composer.json index 87accc7..5c5c43f 100644 --- a/composer.json +++ b/composer.json @@ -23,8 +23,8 @@ "doctrine/dbal": "^3.3", "doctrine/doctrine-bundle": "^2.2.2", "psr/cache": "^1.0 || ^2.0 || ^3.0", - "symfony/cache": "^5.4 || ^6.2", - "symfony/framework-bundle": "^5.4 || ^6.2" + "symfony/cache": "^5.4 || ^6.2 || ^7.0", + "symfony/framework-bundle": "^5.4 || ^6.2 || ^7.0" }, "require-dev": { "behat/behat": "^3.0", @@ -32,8 +32,8 @@ "phpstan/phpstan": "^1.2", "phpunit/phpunit": "^8.0 || ^9.0 || ^10.0", "symfony/phpunit-bridge": "^6.2", - "symfony/process": "^5.4 || ^6.2", - "symfony/yaml": "^5.4 || ^6.2" + "symfony/process": "^5.4 || ^6.2 || ^7.0", + "symfony/yaml": "^5.4 || ^6.2 || ^7.0" }, "autoload": { "psr-4": { diff --git a/tests/DAMA/DoctrineTestBundle/Doctrine/DBAL/MockDriver.php b/tests/DAMA/DoctrineTestBundle/Doctrine/DBAL/MockDriver.php index 05c0f0c..b9542f8 100644 --- a/tests/DAMA/DoctrineTestBundle/Doctrine/DBAL/MockDriver.php +++ b/tests/DAMA/DoctrineTestBundle/Doctrine/DBAL/MockDriver.php @@ -11,29 +11,31 @@ class MockDriver implements Driver { - private function getMock(string $class) - { - // TODO: remove this once we drop support for PHPUnit < 10 - $generatorClass = class_exists('PHPUnit\Framework\MockObject\Generator') - ? 'PHPUnit\Framework\MockObject\Generator' - : 'PHPUnit\Framework\MockObject\Generator\Generator'; + private $connection; + private $schemaManager; + private $exceptionConverter; - /** @phpstan-ignore-next-line */ - return (new $generatorClass())->getMock( - $class, - [], - [], - '', - false - ); + /** + * @param Driver\Connection $connection + * @param AbstractSchemaManager $schemaManager + * @param ExceptionConverter $exceptionConverter + */ + public function __construct( + $connection, + $schemaManager, + $exceptionConverter + ) { + $this->connection = $connection; + $this->schemaManager = $schemaManager; + $this->exceptionConverter = $exceptionConverter; } /** * {@inheritdoc} */ - public function connect(array $params): \Doctrine\DBAL\Driver\Connection + public function connect(array $params): Driver\Connection { - return $this->getMock(Driver\Connection::class); + return clone $this->connection; } /** @@ -49,7 +51,7 @@ public function getDatabasePlatform(): AbstractPlatform */ public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager { - return $this->getMock(AbstractSchemaManager::class); + return $this->schemaManager; } /** @@ -70,6 +72,6 @@ public function getDatabase(Connection $conn): string public function getExceptionConverter(): ExceptionConverter { - return $this->getMock(ExceptionConverter::class); + return $this->exceptionConverter; } } diff --git a/tests/DAMA/DoctrineTestBundle/Doctrine/DBAL/StaticDriverTest.php b/tests/DAMA/DoctrineTestBundle/Doctrine/DBAL/StaticDriverTest.php index f8d0ae6..3b31947 100644 --- a/tests/DAMA/DoctrineTestBundle/Doctrine/DBAL/StaticDriverTest.php +++ b/tests/DAMA/DoctrineTestBundle/Doctrine/DBAL/StaticDriverTest.php @@ -9,9 +9,21 @@ class StaticDriverTest extends TestCase { + private $driver; + + protected function setUp(): void + { + parent::setUp(); + $this->driver = new MockDriver( + $this->createMock('Doctrine\DBAL\Driver\Connection'), + $this->createMock('Doctrine\DBAL\Schema\AbstractSchemaManager'), + $this->createMock('Doctrine\DBAL\Driver\API\ExceptionConverter') + ); + } + public function testConnect(): void { - $driver = new StaticDriver(new MockDriver()); + $driver = new StaticDriver($this->driver); $driver::setKeepStaticConnections(true); @@ -36,7 +48,7 @@ public function testConnect(): void $this->assertInstanceOf(StaticConnection::class, $connection1); $this->assertNotSame($connection1->getWrappedConnection(), $connection2->getWrappedConnection()); - $driver = new StaticDriver(new MockDriver()); + $driver = new StaticDriver($this->driver); /** @var StaticConnection $connectionNew1 */ $connectionNew1 = $driver->connect(['dama.connection_name' => 'foo'] + $params); @@ -59,7 +71,7 @@ public function testConnect(): void public function testConnectWithPlatform(): void { - $driver = new StaticDriver(new MockDriver()); + $driver = new StaticDriver($this->driver); $driver::setKeepStaticConnections(true); @@ -92,7 +104,7 @@ public function testConnectWithPlatform(): void $this->assertInstanceOf(StaticConnection::class, $connection1); $this->assertNotSame($connection1->getWrappedConnection(), $connection2->getWrappedConnection()); - $driver = new StaticDriver(new MockDriver()); + $driver = new StaticDriver($this->driver); /** @var StaticConnection $connectionNew1 */ $connectionNew1 = $driver->connect(['dama.connection_name' => 'foo'] + $params);