From bf762350e94417cc6fab368d39b083290698ffbf Mon Sep 17 00:00:00 2001 From: Soner Sayakci Date: Tue, 30 Jul 2024 21:22:22 +0200 Subject: [PATCH 1/2] feat: rename package name --- .github/workflows/php.yml | 8 +++--- .gitignore | 3 ++- README.md | 18 ++++++-------- composer.json | 12 ++++----- phpstan.neon => phpstan.neon.dist | 0 phpunit.xml.dist | 26 ++++++++++++++++++++ src/Container/Container.php | 12 ++++----- src/Container/MariaDBContainer.php | 4 +-- src/Container/MySQLContainer.php | 4 +-- src/Container/OpenSearchContainer.php | 4 +-- src/Container/PostgresContainer.php | 4 +-- src/Container/RedisContainer.php | 4 +-- src/Exception/ContainerNotReadyException.php | 2 +- src/Registry.php | 4 +-- src/Trait/DockerContainerAwareTrait.php | 4 +-- src/Wait/WaitForExec.php | 4 +-- src/Wait/WaitForHealthCheck.php | 4 +-- src/Wait/WaitForHttp.php | 6 ++--- src/Wait/WaitForLog.php | 4 +-- src/Wait/WaitForNothing.php | 2 +- src/Wait/WaitForTcpPortOpen.php | 6 ++--- src/Wait/WaitInterface.php | 2 +- tests/Integration/ContainerTest.php | 12 ++++----- tests/Integration/WaitStrategyTest.php | 20 +++++++-------- 24 files changed, 98 insertions(+), 71 deletions(-) rename phpstan.neon => phpstan.neon.dist (100%) create mode 100644 phpunit.xml.dist diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 623a45f..8fdd08e 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -2,9 +2,11 @@ name: PHP on: push: - branches: [ "main" ] + branches: + - main pull_request: - branches: [ "main" ] + branches: + - main permissions: contents: read @@ -14,7 +16,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup PHP with PECL extension uses: shivammathur/setup-php@v2 diff --git a/.gitignore b/.gitignore index adfa2e0..b00febc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /vendor/ -.php-cs-fixer.cache +/.php-cs-fixer.cache +/.phpunit.cache /composer.lock \ No newline at end of file diff --git a/README.md b/README.md index 6dccfd0..ab5a7fd 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,12 @@ Testcontainers is a PHP package that makes it simple to create and clean up container-based dependencies for automated integration/smoke tests. The package is inspired by the [Testcontainers](https://www.testcontainers.org/) project for Java. -[@sironheart](https://github.com/sironheart) has annoyed me to test testcontainers, but it didn't existed in PHP yet. - ## Installation Add this to your project with composer ```bash -composer req --dev shyim/testcontainer +composer req --dev testcontainers/testcontainers ``` ## Usage/Examples @@ -19,7 +17,7 @@ composer req --dev shyim/testcontainer ```php withWait(new WaitForHealthCheck()); ```php withMySQLDatabase('foo'); @@ -82,7 +80,7 @@ $pdo = new \PDO( ```php withMariaDBDatabase('foo'); @@ -104,7 +102,7 @@ $pdo = new \PDO( ```php withPostgresDatabase('database'); @@ -125,7 +123,7 @@ $pdo = new \PDO( ```php -use Testcontainer\Container\RedisContainer; +use Testcontainers\Container\RedisContainer; $container = RedisContainer::make('6.0'); @@ -141,7 +139,7 @@ $redis->connect($container->getAddress()); ```php -use Testcontainer\Container\OpenSearchContainer; +use Testcontainers\Container\OpenSearchContainer; $container = OpenSearchContainer::make('2'); $container->disableSecurityPlugin(); @@ -168,7 +166,7 @@ use Doctrine\Bundle\DoctrineBundle\ConnectionFactory; use Doctrine\Common\EventManager; use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Tools\DsnParser; -use Testcontainer\Container\PostgresContainer; +use Testcontainers\Container\PostgresContainer; class TestConnectionFactory extends ConnectionFactory { diff --git a/composer.json b/composer.json index e3d909d..dc070bd 100644 --- a/composer.json +++ b/composer.json @@ -1,10 +1,10 @@ { - "name": "shyim/testcontainer", - "description": "Testcontainer implementation in PHP", + "name": "testcontainers/testcontainers", + "description": "Testcontainers implementation in PHP", "license": "MIT", "keywords": [ "docker", - "testcontainer" + "testcontainers" ], "type": "library", "authors": [ @@ -15,7 +15,7 @@ ], "require": { "php": ">= 8.1", - "symfony/process": "^5.3|^6.0|^7.0" + "symfony/process": "^5.0|^6.0|^7.0" }, "require-dev": { "phpunit/phpunit": "^9.5", @@ -28,12 +28,12 @@ }, "autoload": { "psr-4": { - "Testcontainer\\": "src/" + "Testcontainers\\": "src/" } }, "autoload-dev": { "psr-4": { - "Testcontainer\\Tests\\": "tests/" + "Testcontainers\\Tests\\": "tests/" } }, "scripts": { diff --git a/phpstan.neon b/phpstan.neon.dist similarity index 100% rename from phpstan.neon rename to phpstan.neon.dist diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..9993376 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,26 @@ + + + + + tests + + + + + + src + + + diff --git a/src/Container/Container.php b/src/Container/Container.php index 3e67d71..0ea8ebf 100644 --- a/src/Container/Container.php +++ b/src/Container/Container.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace Testcontainer\Container; +namespace Testcontainers\Container; use Symfony\Component\Process\Process; -use Testcontainer\Exception\ContainerNotReadyException; -use Testcontainer\Registry; -use Testcontainer\Trait\DockerContainerAwareTrait; -use Testcontainer\Wait\WaitForNothing; -use Testcontainer\Wait\WaitInterface; +use Testcontainers\Exception\ContainerNotReadyException; +use Testcontainers\Registry; +use Testcontainers\Trait\DockerContainerAwareTrait; +use Testcontainers\Wait\WaitForNothing; +use Testcontainers\Wait\WaitInterface; /** * @phpstan-type ContainerInspectSingleNetwork array diff --git a/src/Container/MariaDBContainer.php b/src/Container/MariaDBContainer.php index 526f290..4ff9c4e 100644 --- a/src/Container/MariaDBContainer.php +++ b/src/Container/MariaDBContainer.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace Testcontainer\Container; +namespace Testcontainers\Container; -use Testcontainer\Wait\WaitForExec; +use Testcontainers\Wait\WaitForExec; class MariaDBContainer extends Container { diff --git a/src/Container/MySQLContainer.php b/src/Container/MySQLContainer.php index d9bfb42..7b1fdbb 100644 --- a/src/Container/MySQLContainer.php +++ b/src/Container/MySQLContainer.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace Testcontainer\Container; +namespace Testcontainers\Container; -use Testcontainer\Wait\WaitForExec; +use Testcontainers\Wait\WaitForExec; class MySQLContainer extends Container { diff --git a/src/Container/OpenSearchContainer.php b/src/Container/OpenSearchContainer.php index e122264..783edb3 100644 --- a/src/Container/OpenSearchContainer.php +++ b/src/Container/OpenSearchContainer.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace Testcontainer\Container; +namespace Testcontainers\Container; -use Testcontainer\Wait\WaitForHttp; +use Testcontainers\Wait\WaitForHttp; class OpenSearchContainer extends Container { diff --git a/src/Container/PostgresContainer.php b/src/Container/PostgresContainer.php index 15f3553..46a912f 100644 --- a/src/Container/PostgresContainer.php +++ b/src/Container/PostgresContainer.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace Testcontainer\Container; +namespace Testcontainers\Container; -use Testcontainer\Wait\WaitForExec; +use Testcontainers\Wait\WaitForExec; class PostgresContainer extends Container { diff --git a/src/Container/RedisContainer.php b/src/Container/RedisContainer.php index f6aef9f..a219e57 100644 --- a/src/Container/RedisContainer.php +++ b/src/Container/RedisContainer.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace Testcontainer\Container; +namespace Testcontainers\Container; -use Testcontainer\Wait\WaitForLog; +use Testcontainers\Wait\WaitForLog; class RedisContainer extends Container { diff --git a/src/Exception/ContainerNotReadyException.php b/src/Exception/ContainerNotReadyException.php index deb9b34..1b5f677 100644 --- a/src/Exception/ContainerNotReadyException.php +++ b/src/Exception/ContainerNotReadyException.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Testcontainer\Exception; +namespace Testcontainers\Exception; class ContainerNotReadyException extends \RuntimeException { diff --git a/src/Registry.php b/src/Registry.php index 0cdac28..0d1d95a 100644 --- a/src/Registry.php +++ b/src/Registry.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace Testcontainer; +namespace Testcontainers; -use Testcontainer\Container\Container; +use Testcontainers\Container\Container; class Registry { diff --git a/src/Trait/DockerContainerAwareTrait.php b/src/Trait/DockerContainerAwareTrait.php index 274d91a..79323bc 100644 --- a/src/Trait/DockerContainerAwareTrait.php +++ b/src/Trait/DockerContainerAwareTrait.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace Testcontainer\Trait; +namespace Testcontainers\Trait; use JsonException; use Symfony\Component\Process\Process; -use Testcontainer\Container\Container; +use Testcontainers\Container\Container; use UnexpectedValueException; /** diff --git a/src/Wait/WaitForExec.php b/src/Wait/WaitForExec.php index cdf6ba0..0c5c5c9 100644 --- a/src/Wait/WaitForExec.php +++ b/src/Wait/WaitForExec.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace Testcontainer\Wait; +namespace Testcontainers\Wait; use Closure; use Symfony\Component\Process\Process; -use Testcontainer\Exception\ContainerNotReadyException; +use Testcontainers\Exception\ContainerNotReadyException; class WaitForExec implements WaitInterface { diff --git a/src/Wait/WaitForHealthCheck.php b/src/Wait/WaitForHealthCheck.php index 7971ac1..2836346 100644 --- a/src/Wait/WaitForHealthCheck.php +++ b/src/Wait/WaitForHealthCheck.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace Testcontainer\Wait; +namespace Testcontainers\Wait; use RuntimeException; use Symfony\Component\Process\Process; -use Testcontainer\Exception\ContainerNotReadyException; +use Testcontainers\Exception\ContainerNotReadyException; class WaitForHealthCheck implements WaitInterface { diff --git a/src/Wait/WaitForHttp.php b/src/Wait/WaitForHttp.php index 7de3f1e..d65ff04 100644 --- a/src/Wait/WaitForHttp.php +++ b/src/Wait/WaitForHttp.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace Testcontainer\Wait; +namespace Testcontainers\Wait; -use Testcontainer\Exception\ContainerNotReadyException; -use Testcontainer\Trait\DockerContainerAwareTrait; +use Testcontainers\Exception\ContainerNotReadyException; +use Testcontainers\Trait\DockerContainerAwareTrait; class WaitForHttp implements WaitInterface { diff --git a/src/Wait/WaitForLog.php b/src/Wait/WaitForLog.php index 119e533..63f5ace 100644 --- a/src/Wait/WaitForLog.php +++ b/src/Wait/WaitForLog.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace Testcontainer\Wait; +namespace Testcontainers\Wait; use Symfony\Component\Process\Process; -use Testcontainer\Exception\ContainerNotReadyException; +use Testcontainers\Exception\ContainerNotReadyException; class WaitForLog implements WaitInterface { diff --git a/src/Wait/WaitForNothing.php b/src/Wait/WaitForNothing.php index b0da69d..741df17 100644 --- a/src/Wait/WaitForNothing.php +++ b/src/Wait/WaitForNothing.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Testcontainer\Wait; +namespace Testcontainers\Wait; class WaitForNothing implements WaitInterface { diff --git a/src/Wait/WaitForTcpPortOpen.php b/src/Wait/WaitForTcpPortOpen.php index 52e7d72..4c89828 100644 --- a/src/Wait/WaitForTcpPortOpen.php +++ b/src/Wait/WaitForTcpPortOpen.php @@ -2,12 +2,12 @@ declare(strict_types=1); -namespace Testcontainer\Wait; +namespace Testcontainers\Wait; use JsonException; use RuntimeException; -use Testcontainer\Exception\ContainerNotReadyException; -use Testcontainer\Trait\DockerContainerAwareTrait; +use Testcontainers\Exception\ContainerNotReadyException; +use Testcontainers\Trait\DockerContainerAwareTrait; final class WaitForTcpPortOpen implements WaitInterface { diff --git a/src/Wait/WaitInterface.php b/src/Wait/WaitInterface.php index dfa02ae..4e75ce5 100644 --- a/src/Wait/WaitInterface.php +++ b/src/Wait/WaitInterface.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Testcontainer\Wait; +namespace Testcontainers\Wait; interface WaitInterface { diff --git a/tests/Integration/ContainerTest.php b/tests/Integration/ContainerTest.php index b673c07..30de7b2 100644 --- a/tests/Integration/ContainerTest.php +++ b/tests/Integration/ContainerTest.php @@ -2,15 +2,15 @@ declare(strict_types=1); -namespace Testcontainer\Tests\Integration; +namespace Testcontainers\Tests\Integration; use PHPUnit\Framework\TestCase; use Predis\Client; -use Testcontainer\Container\MariaDBContainer; -use Testcontainer\Container\MySQLContainer; -use Testcontainer\Container\OpenSearchContainer; -use Testcontainer\Container\PostgresContainer; -use Testcontainer\Container\RedisContainer; +use Testcontainers\Container\MariaDBContainer; +use Testcontainers\Container\MySQLContainer; +use Testcontainers\Container\OpenSearchContainer; +use Testcontainers\Container\PostgresContainer; +use Testcontainers\Container\RedisContainer; class ContainerTest extends TestCase { diff --git a/tests/Integration/WaitStrategyTest.php b/tests/Integration/WaitStrategyTest.php index 551e531..09abdf7 100644 --- a/tests/Integration/WaitStrategyTest.php +++ b/tests/Integration/WaitStrategyTest.php @@ -2,21 +2,21 @@ declare(strict_types=1); -namespace Testcontainer\Tests\Integration; +namespace Testcontainers\Tests\Integration; use PHPUnit\Framework\TestCase; use Predis\Client; use Predis\Connection\ConnectionException; use Symfony\Component\Process\Process; -use Testcontainer\Container\Container; -use Testcontainer\Exception\ContainerNotReadyException; -use Testcontainer\Registry; -use Testcontainer\Trait\DockerContainerAwareTrait; -use Testcontainer\Wait\WaitForExec; -use Testcontainer\Wait\WaitForHealthCheck; -use Testcontainer\Wait\WaitForHttp; -use Testcontainer\Wait\WaitForLog; -use Testcontainer\Wait\WaitForTcpPortOpen; +use Testcontainers\Container\Container; +use Testcontainers\Exception\ContainerNotReadyException; +use Testcontainers\Registry; +use Testcontainers\Trait\DockerContainerAwareTrait; +use Testcontainers\Wait\WaitForExec; +use Testcontainers\Wait\WaitForHealthCheck; +use Testcontainers\Wait\WaitForHttp; +use Testcontainers\Wait\WaitForLog; +use Testcontainers\Wait\WaitForTcpPortOpen; class WaitStrategyTest extends TestCase { From 38f5049d8973f239c8b3ba0e0f9c895578f801eb Mon Sep 17 00:00:00 2001 From: Soner Sayakci Date: Tue, 30 Jul 2024 21:38:29 +0200 Subject: [PATCH 2/2] ci: split CI --- .github/workflows/php.yml | 45 +++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 8fdd08e..23c29bf 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -12,26 +12,57 @@ permissions: contents: read jobs: - build: + cs: runs-on: ubuntu-latest + name: Code Style steps: - uses: actions/checkout@v4 - - name: Setup PHP with PECL extension + - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: '8.1' - extensions: redis, pgsql - name: Install dependencies run: composer install --prefer-dist --no-progress - - name: Run test suite - run: composer run integration - - name: Run cs run: composer run cs - + + phpstan: + runs-on: ubuntu-latest + name: Static Analysis + + steps: + - uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.1' + + - name: Install dependencies + run: composer install --prefer-dist --no-progress + - name: Run phpstan run: composer run phpstan + + phpunit: + runs-on: ubuntu-latest + name: Integration Tests + + steps: + - uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.1' + extensions: redis, pgsql + + - name: Install dependencies + run: composer install --prefer-dist --no-progress + + - name: Run test suite + run: composer run integration