fix: phpunit tests

This commit is contained in:
Soner Sayakci
2024-07-13 11:21:19 +09:00
parent 1b158157f7
commit 3ddc75e717
5 changed files with 24 additions and 21 deletions
+2 -1
View File
@@ -1,2 +1,3 @@
/vendor/
.php-cs-fixer.cache
.php-cs-fixer.cache
/composer.lock
+2 -1
View File
@@ -23,7 +23,8 @@
"friendsofphp/php-cs-fixer": "^3.12",
"phpstan/phpstan": "^1.8",
"phpstan/phpstan-phpunit": "^1.1",
"phpstan/extension-installer": "^1.2"
"phpstan/extension-installer": "^1.2",
"predis/predis": "^3.0 || ^2.0"
},
"autoload": {
"psr-4": {
+1
View File
@@ -12,6 +12,7 @@ class OpenSearchContainer extends Container
{
parent::__construct('opensearchproject/opensearch:' . $version);
$this->withEnvironment('discovery.type', 'single-node');
$this->withEnvironment('OPENSEARCH_INITIAL_ADMIN_PASSWORD', 'c3o_ZPHo!');
$this->withWait(WaitForHttp::make(9200));
}
+6 -3
View File
@@ -5,7 +5,7 @@ declare(strict_types=1);
namespace Testcontainer\Tests\Integration;
use PHPUnit\Framework\TestCase;
use Redis;
use Predis\Client;
use Testcontainer\Container\MariaDBContainer;
use Testcontainer\Container\MySQLContainer;
use Testcontainer\Container\OpenSearchContainer;
@@ -66,8 +66,11 @@ class ContainerTest extends TestCase
$container->run();
$redis = new Redis();
$redis->connect($container->getAddress(), 6379, 0.001);
$redis = new Client([
'scheme' => 'tcp',
'host' => $container->getAddress(),
'port' => 6379,
]);
$redis->ping();
+13 -16
View File
@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace Testcontainer\Tests\Integration;
use PHPUnit\Framework\TestCase;
use Predis\Client;
use Predis\Connection\ConnectionException;
use Symfony\Component\Process\Process;
use Testcontainer\Container\Container;
use Testcontainer\Wait\WaitForExec;
@@ -51,8 +53,11 @@ class WaitStrategyTest extends TestCase
$container->run();
$redis = new \Redis();
$redis->connect($container->getAddress(), 6379, 0.001);
$redis = new Client([
'scheme' => 'tcp',
'host' => $container->getAddress(),
'port' => 6379,
]);
$redis->set('foo', 'bar');
@@ -60,7 +65,7 @@ class WaitStrategyTest extends TestCase
$container->stop();
$this->expectException(\RedisException::class);
$this->expectException(ConnectionException::class);
$redis->get('foo');
@@ -69,27 +74,20 @@ class WaitStrategyTest extends TestCase
public function testWaitForHTTP(): void
{
$container = Container::make('opensearchproject/opensearch')
->withEnvironment('discovery.type', 'single-node')
->withEnvironment('plugins.security.disabled', 'true')
->withWait(WaitForHttp::make(9200));
$container = Container::make('nginx:alpine')
->withWait(WaitForHttp::make(80));
$container->run();
$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);
$response = (string) curl_exec($ch);
curl_close($ch);
$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
@@ -103,7 +101,6 @@ class WaitStrategyTest extends TestCase
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, sprintf('http://%s:%d', $container->getAddress(), 80));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);