1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
<?php
declare(strict_types=1);
namespace Pheanstalk\Tests\Unit\Command;
use Pheanstalk\Command\TubeCommand;
use Pheanstalk\Exception\TubeNotFoundException;
use Pheanstalk\Values\RawResponse;
use Pheanstalk\Values\ResponseType;
use Pheanstalk\Values\TubeName;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\Attributes\DataProvider;
abstract class TubeCommandTestBase extends CommandTestBase
{
abstract protected function getSubject(?TubeName $tube = null): TubeCommand;
public function testInterpretNotFound(): void
{
if (in_array(ResponseType::NotFound, static::getSupportedResponses(), true)) {
$command = $this->getSubject();
$this->expectException(TubeNotFoundException::class);
$this->expectExceptionMessage('Tube "default" not found.');
$command->interpret(new RawResponse(ResponseType::NotFound));
} else {
$this->expectNotToPerformAssertions();
}
}
/**
* @phpstan-return iterable<array{0: string}>
*/
public static function tubeNameProvider(): iterable
{
yield ["5"];
yield ["12345678901234562222222323112312312312312312312312312312312312321312312313212378900"];
yield ["00001123"];
yield ["ab-cdef"];
yield ["\$abc"];
yield ["ab(14\$--_.4"];
}
#[DataProvider('tubeNameProvider')]
public function testCommandLineIncludesTubeName(string $tubeName): void
{
$commandLine = $this->getSubject(new TubeName($tubeName))->getCommandLine();
Assert::assertStringContainsString($tubeName, $commandLine);
Assert::assertMatchesRegularExpression('/^[a-z\-]+\s+.+(\s+.+)?$/', $commandLine);
}
}
|