mirror of
https://github.com/stan220/testcontainers-php.git
synced 2026-09-12 11:29:36 +00:00
fix: phpunit tests
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
/vendor/
|
/vendor/
|
||||||
.php-cs-fixer.cache
|
.php-cs-fixer.cache
|
||||||
|
/composer.lock
|
||||||
+2
-1
@@ -23,7 +23,8 @@
|
|||||||
"friendsofphp/php-cs-fixer": "^3.12",
|
"friendsofphp/php-cs-fixer": "^3.12",
|
||||||
"phpstan/phpstan": "^1.8",
|
"phpstan/phpstan": "^1.8",
|
||||||
"phpstan/phpstan-phpunit": "^1.1",
|
"phpstan/phpstan-phpunit": "^1.1",
|
||||||
"phpstan/extension-installer": "^1.2"
|
"phpstan/extension-installer": "^1.2",
|
||||||
|
"predis/predis": "^3.0 || ^2.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ class OpenSearchContainer extends Container
|
|||||||
{
|
{
|
||||||
parent::__construct('opensearchproject/opensearch:' . $version);
|
parent::__construct('opensearchproject/opensearch:' . $version);
|
||||||
$this->withEnvironment('discovery.type', 'single-node');
|
$this->withEnvironment('discovery.type', 'single-node');
|
||||||
|
$this->withEnvironment('OPENSEARCH_INITIAL_ADMIN_PASSWORD', 'c3o_ZPHo!');
|
||||||
$this->withWait(WaitForHttp::make(9200));
|
$this->withWait(WaitForHttp::make(9200));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace Testcontainer\Tests\Integration;
|
namespace Testcontainer\Tests\Integration;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Redis;
|
use Predis\Client;
|
||||||
use Testcontainer\Container\MariaDBContainer;
|
use Testcontainer\Container\MariaDBContainer;
|
||||||
use Testcontainer\Container\MySQLContainer;
|
use Testcontainer\Container\MySQLContainer;
|
||||||
use Testcontainer\Container\OpenSearchContainer;
|
use Testcontainer\Container\OpenSearchContainer;
|
||||||
@@ -66,8 +66,11 @@ class ContainerTest extends TestCase
|
|||||||
|
|
||||||
$container->run();
|
$container->run();
|
||||||
|
|
||||||
$redis = new Redis();
|
$redis = new Client([
|
||||||
$redis->connect($container->getAddress(), 6379, 0.001);
|
'scheme' => 'tcp',
|
||||||
|
'host' => $container->getAddress(),
|
||||||
|
'port' => 6379,
|
||||||
|
]);
|
||||||
|
|
||||||
$redis->ping();
|
$redis->ping();
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ declare(strict_types=1);
|
|||||||
namespace Testcontainer\Tests\Integration;
|
namespace Testcontainer\Tests\Integration;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Predis\Client;
|
||||||
|
use Predis\Connection\ConnectionException;
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
use Testcontainer\Container\Container;
|
use Testcontainer\Container\Container;
|
||||||
use Testcontainer\Wait\WaitForExec;
|
use Testcontainer\Wait\WaitForExec;
|
||||||
@@ -51,8 +53,11 @@ class WaitStrategyTest extends TestCase
|
|||||||
|
|
||||||
$container->run();
|
$container->run();
|
||||||
|
|
||||||
$redis = new \Redis();
|
$redis = new Client([
|
||||||
$redis->connect($container->getAddress(), 6379, 0.001);
|
'scheme' => 'tcp',
|
||||||
|
'host' => $container->getAddress(),
|
||||||
|
'port' => 6379,
|
||||||
|
]);
|
||||||
|
|
||||||
$redis->set('foo', 'bar');
|
$redis->set('foo', 'bar');
|
||||||
|
|
||||||
@@ -60,7 +65,7 @@ class WaitStrategyTest extends TestCase
|
|||||||
|
|
||||||
$container->stop();
|
$container->stop();
|
||||||
|
|
||||||
$this->expectException(\RedisException::class);
|
$this->expectException(ConnectionException::class);
|
||||||
|
|
||||||
$redis->get('foo');
|
$redis->get('foo');
|
||||||
|
|
||||||
@@ -69,27 +74,20 @@ class WaitStrategyTest extends TestCase
|
|||||||
|
|
||||||
public function testWaitForHTTP(): void
|
public function testWaitForHTTP(): void
|
||||||
{
|
{
|
||||||
$container = Container::make('opensearchproject/opensearch')
|
$container = Container::make('nginx:alpine')
|
||||||
->withEnvironment('discovery.type', 'single-node')
|
->withWait(WaitForHttp::make(80));
|
||||||
->withEnvironment('plugins.security.disabled', 'true')
|
|
||||||
->withWait(WaitForHttp::make(9200));
|
|
||||||
|
|
||||||
$container->run();
|
$container->run();
|
||||||
|
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
curl_setopt($ch, CURLOPT_URL, sprintf('http://%s:%d', $container->getAddress(), 9200));
|
curl_setopt($ch, CURLOPT_URL, sprintf('http://%s:%d', $container->getAddress(), 80));
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
|
||||||
$response = (string) curl_exec($ch);
|
$response = (string) curl_exec($ch);
|
||||||
|
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
$this->assertNotEmpty($response);
|
$this->assertNotEmpty($response);
|
||||||
|
|
||||||
/** @var array{cluster_name: string} $data */
|
|
||||||
$data = json_decode($response, true);
|
|
||||||
|
|
||||||
$this->assertArrayHasKey('cluster_name', $data);
|
|
||||||
|
|
||||||
$this->assertEquals('docker-cluster', $data['cluster_name']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWaitForHealthCheck(): void
|
public function testWaitForHealthCheck(): void
|
||||||
@@ -103,7 +101,6 @@ class WaitStrategyTest extends TestCase
|
|||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
|
|
||||||
curl_setopt($ch, CURLOPT_URL, sprintf('http://%s:%d', $container->getAddress(), 80));
|
curl_setopt($ch, CURLOPT_URL, sprintf('http://%s:%d', $container->getAddress(), 80));
|
||||||
|
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
|
||||||
$response = curl_exec($ch);
|
$response = curl_exec($ch);
|
||||||
|
|||||||
Reference in New Issue
Block a user