File: ServerErrorExceptionTest.php

package info (click to toggle)
php-pda-pheanstalk 4.0.5-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 608 kB
  • sloc: php: 2,658; xml: 60; makefile: 15
file content (77 lines) | stat: -rw-r--r-- 2,322 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php

namespace Pheanstalk;

use Pheanstalk\Contract\SocketFactoryInterface;
use Pheanstalk\Contract\SocketInterface;
use PHPUnit\Framework\TestCase;

/**
 * Tests exceptions thrown to represent non-command-specific error responses.
 */
class ServerErrorExceptionTest extends TestCase
{
    private $command;

    public function setUp(): void
    {
        $this->command = new Command\UseCommand('tube5');
    }

    /**
     * A connection with a mock socket, configured to return the given line.
     */
    private function connection(string $line): Connection
    {
        $socket = $this->getMockBuilder(\Pheanstalk\Contract\SocketInterface::class)
            ->getMock();

        $socket->expects($this->any())
            ->method('getLine')
            ->willReturn($line);

        $connection = new Connection(new class($socket) implements SocketFactoryInterface {
            private $socket;
            public function __construct($socket)
            {
                $this->socket = $socket;
            }

            public function create(): SocketInterface
            {
                return $this->socket;
            }
        });
        return $connection;
    }

    public function testCommandsHandleOutOfMemory()
    {
        $this->expectException('\Pheanstalk\Exception\ServerOutOfMemoryException');
        $this->connection('OUT_OF_MEMORY')->dispatchCommand($this->command);
    }

    public function testCommandsHandleInternalError()
    {
        $this->expectException('\Pheanstalk\Exception\ServerInternalErrorException');
        $this->connection('INTERNAL_ERROR')->dispatchCommand($this->command);
    }

    public function testCommandsHandleDraining()
    {
        $this->expectException('\Pheanstalk\Exception\ServerDrainingException');
        $this->connection('DRAINING')->dispatchCommand($this->command);
    }

    public function testCommandsHandleBadFormat()
    {
        $this->expectException('\Pheanstalk\Exception\ServerBadFormatException');
        $this->connection('BAD_FORMAT')->dispatchCommand($this->command);
    }

    public function testCommandsHandleUnknownCommand()
    {
        $this->expectException('\Pheanstalk\Exception\ServerUnknownCommandException');
        $this->connection('UNKNOWN_COMMAND')->dispatchCommand($this->command);
    }
}