File: TubeCommandTestBase.php

package info (click to toggle)
php-pda-pheanstalk 8.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 836 kB
  • sloc: php: 4,713; xml: 19; makefile: 14
file content (52 lines) | stat: -rw-r--r-- 1,714 bytes parent folder | download
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);
    }
}