initial commit

This commit is contained in:
Soner Sayakci
2022-10-22 23:59:29 +00:00
commit be3be06681
21 changed files with 4942 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace Testcontainer\Wait;
use Symfony\Component\Process\Process;
use Testcontainer\Exception\ContainerNotReadyException;
class WaitForLog implements WaitInterface
{
public function __construct(private string $message, private bool $enableRegex = false)
{
}
public function wait(string $id): void
{
$process = new Process(['docker', 'logs', $id]);
$process->mustRun();
$output = $process->getOutput() . PHP_EOL . $process->getErrorOutput();
if ($this->enableRegex) {
if (!preg_match($this->message, $output)) {
throw new ContainerNotReadyException($id, new \RuntimeException('Message not found in logs'));
}
} else {
if (!str_contains($output, $this->message)) {
throw new ContainerNotReadyException($id, new \RuntimeException('Message not found in logs'));
}
}
}
}