From 54c5d34886efeebe7dc558b33736d535d510382f Mon Sep 17 00:00:00 2001 From: Steffen Beisenherz <13799656+Sironheart@users.noreply.github.com> Date: Sun, 23 Oct 2022 15:04:30 +0200 Subject: [PATCH] fix: Tests and postgres image --- .github/workflows/php.yml | 2 +- src/Container/PostgresContainer.php | 5 ++++- tests/Integration/ContainerTest.php | 5 +++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 5cf1afb..623a45f 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -20,7 +20,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: '8.1' - extensions: redis + extensions: redis, pgsql - name: Install dependencies run: composer install --prefer-dist --no-progress diff --git a/src/Container/PostgresContainer.php b/src/Container/PostgresContainer.php index cccb20c..9d14a33 100644 --- a/src/Container/PostgresContainer.php +++ b/src/Container/PostgresContainer.php @@ -4,12 +4,15 @@ declare(strict_types=1); namespace Testcontainer\Container; +use Testcontainer\Wait\WaitForExec; + class PostgresContainer extends Container { private function __construct(string $version, string $rootPassword) { - parent::__construct('mariadb:' . $version); + parent::__construct('postgres:' . $version); $this->withEnvironment('POSTGRES_PASSWORD', $rootPassword); + $this->withWait(new WaitForExec(["pg_isready", "-h", "127.0.0.1"])); } public static function make(string $version = 'latest', string $mysqlRootPassword = 'root'): self diff --git a/tests/Integration/ContainerTest.php b/tests/Integration/ContainerTest.php index 3550670..a647024 100644 --- a/tests/Integration/ContainerTest.php +++ b/tests/Integration/ContainerTest.php @@ -101,11 +101,12 @@ class ContainerTest extends TestCase { $container = PostgresContainer::make('latest', 'test') ->withPostgresUser('test') - ->withPostgresDatabase('foo'); + ->withPostgresDatabase('foo') + ->run(); $pdo = new \PDO( - sprintf('postgres:host=%s;port=3306', $container->getAddress()), + sprintf('postgres:host=%s;port=5432', $container->getAddress()), 'test', 'test', );