Skip to content

Commit

Permalink
Testcontainer dev dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
ioigoume committed Jul 15, 2024
1 parent 02be53a commit 3079a87
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
22 changes: 17 additions & 5 deletions tests/src/Repositories/Traits/RevokeTokenByAuthCodeIdTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 3079a87

Please sign in to comment.