mirror of
https://github.com/stan220/testcontainers-php.git
synced 2026-09-08 19:29:39 +00:00
initial commit
This commit is contained in:
@@ -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'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user