File: StreamIOTest.php

package info (click to toggle)
php-amqplib 3.7.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,060 kB
  • sloc: php: 13,145; makefile: 77; sh: 27
file content (62 lines) | stat: -rw-r--r-- 1,526 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
<?php

namespace PhpAmqpLib\Tests\Unit\Wire\IO;

use PhpAmqpLib\Exception\AMQPConnectionClosedException;
use PhpAmqpLib\Wire\IO\StreamIO;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

/**
 * @group connection
 */
class StreamIOTest extends TestCase
{
    /**
     * @expectedException \InvalidArgumentException
     * @expectedExceptionMessage read_write_timeout must be at least 2x the heartbeat
     * TODO FUTURE re-enable this test
    #[Test]
    public function read_write_timeout_must_be_at_least_2x_the_heartbeat()
    {
        new StreamIO(
            'localhost',
            '5512',
            1,
            1,
            null,
            false,
            1
        );
    }
     */

    /**
     * @group linux
     * @requires OS Linux
     */
    #[Test]
    public function select_must_throw_io_exception()
    {
        $this->expectException(AMQPConnectionClosedException::class);
        $property = new \ReflectionProperty(StreamIO::class, 'sock');
        $property->setAccessible(true);

        $resource = fopen('php://temp', 'r');
        fclose($resource);

        $stream = new StreamIO('0.0.0.0', PORT, 0.1, 0.1, null, false, 0);
        $property->setValue($stream, $resource);

        $stream->select(0, 0);
    }

    #[Test]
    public function connect_ipv6()
    {
        $streamIO = new StreamIO(HOST6, PORT, 0.1, 0.1, null, false, 0);
        $streamIO->connect();
        $ready = $streamIO->select(0, 0);
        $this->assertEquals(0, $ready);
    }
}