mirror of
https://github.com/stan220/testcontainers-php.git
synced 2026-09-09 08:29:39 +00:00
34 lines
959 B
PHP
34 lines
959 B
PHP
<?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'));
|
|
}
|
|
}
|
|
}
|
|
}
|