From 3079a872f8bce01caa861c1cc500595033155506 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Mon, 15 Jul 2024 15:33:19 +0300 Subject: [PATCH] Testcontainer dev dependency --- composer.json | 3 ++- .../RevokeTokenByAuthCodeIdTraitTest.php | 22 ++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 70936b32..2957a775 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,8 @@ "simplesamlphp/simplesamlphp": "2.2.*", "simplesamlphp/simplesamlphp-test-framework": "^1.5", "squizlabs/php_codesniffer": "^3", - "vimeo/psalm": "^5" + "vimeo/psalm": "^5", + "shyim/testcontainer": "^0.1" }, "config": { "preferred-install": { diff --git a/tests/src/Repositories/Traits/RevokeTokenByAuthCodeIdTraitTest.php b/tests/src/Repositories/Traits/RevokeTokenByAuthCodeIdTraitTest.php index 429b6a78..b2af8509 100644 --- a/tests/src/Repositories/Traits/RevokeTokenByAuthCodeIdTraitTest.php +++ b/tests/src/Repositories/Traits/RevokeTokenByAuthCodeIdTraitTest.php @@ -21,6 +21,8 @@ use SimpleSAML\Module\oidc\Repositories\UserRepository; use SimpleSAML\Module\oidc\Services\DatabaseMigration; use SimpleSAML\Module\oidc\Utils\TimestampGenerator; +use Testcontainer\Container\PostgresContainer; +use Testcontainer\Wait\WaitForHealthCheck; /** * @covers \SimpleSAML\Module\oidc\Repositories\Traits\RevokeTokenByAuthCodeIdTrait @@ -62,18 +64,28 @@ class RevokeTokenByAuthCodeIdTraitTest extends TestCase public static function setUpBeforeClass(): void { + $container = PostgresContainer::make('15.0', 'password'); + $container->withPostgresDatabase('database'); + $container->withPostgresUser('username'); + + $container->run(); + // Wait until the docker heartcheck is green + $container->withWait(new WaitForHealthCheck()); + $config = [ - 'database.dsn' => 'sqlite::memory:', - 'database.username' => null, - 'database.password' => null, + 'database.dsn' => sprintf('pgsql:host=%s;port=5432;dbname=database', $container->getAddress()), + 'database.username' => 'username', + 'database.password' => 'password', 'database.prefix' => 'phpunit_', 'database.persistent' => true, 'database.secondaries' => [], ]; - Configuration::loadFromArray($config, '', 'simplesaml'); + $configuration = Configuration::loadFromArray($config, '', 'simplesaml'); Configuration::setConfigDir(__DIR__ . '/../../../../config-templates'); - (new DatabaseMigration())->migrate(); + + $database = Database::getInstance($configuration); + (new DatabaseMigration($database))->migrate(); $moduleConfig = new ModuleConfig();