<commit_before><?php
declare(strict_types = 1);

namespace Tests\Innmind\AMQP\Transport;

use Innmind\AMQP\{
    Transport\Connection,
    Transport\Protocol\v091\Protocol,
    Transport\Protocol as ProtocolInterface,
    Transport\Protocol\Version,
    Transport\Protocol\Connection as PConnection,
    Transport\Protocol\Channel as PChannel,
    Transport\Protocol\Exchange,
    Transport\Protocol\Queue,
    Transport\Protocol\Basic,
    Transport\Protocol\Transaction,
    Transport\Protocol\Delegate,
    Transport\Protocol\ArgumentTranslator,
    Transport\Frame,
    Transport\Frame\Channel,
    Transport\Frame\Method,
    Model\Connection\MaxFrameSize,
    Exception\VersionNotUsable
};
use Innmind\Socket\Internet\Transport;
use Innmind\Url\Url;
use Innmind\TimeContinuum\{
    ElapsedPeriod,
    TimeContinuum\Earth
};
use Innmind\Immutable\{
    Str,
    StreamInterface
};
use PHPUnit\Framework\TestCase;

class ConnectionTest extends TestCase
{
    public function testInterface()
    {
        $connection = new Connection(
            Transport::tcp(),
            Url::fromString('//guest:guest@localhost:5672/'),
            $protocol = new Protocol($this->createMock(ArgumentTranslator::class)),
            new ElapsedPeriod(1000),
            new Earth
        );

        $this->assertSame($protocol, $connection->protocol());
        $this->assertInstanceOf(MaxFrameSize::class, $connection->maxFrameSize());
        $this->assertSame(131072, $connection->maxFrameSize()->toInt());
        $this->assertSame(
            $connection,
            $connection->send(
                $protocol->channel()->open(new Channel(1))
            )
        );
        $this->assertInstanceOf(Frame::class, $connection->wait('channel.open-ok'));
        unset($connection); //test it closes without exception
    }

    public function testClose()
    {
        $connection = new Connection(
            Transport::tcp(),
            Url::fromString('//guest:guest@localhost:5672/'),
            $protocol = new Protocol($this->createMock(ArgumentTranslator::class)),
            new ElapsedPeriod(1000),
            new Earth
        );

        $this->assertTrue($connection->opened());
        $this->assertNull($connection->close());
        $this->assertFalse($connection->opened());
    }

    /**
     * @expectedException Innmind\AMQP\Exception\UnexpectedFrame
     */
    public function testThrowWhenReceivedFrameIsNotTheExpectedOne()
    {
        $connection = new Connection(
            Transport::tcp(),
            Url::fromString('//guest:guest@localhost:5672/'),
            $protocol = new Protocol($this->createMock(ArgumentTranslator::class)),
            new ElapsedPeriod(1000),
            new Earth
        );
        $connection
            ->send(
                $protocol->channel()->open(new Channel(2))
            )
            ->wait('connection.open');
    }

    public function testUseCorrectProtocolVersion()
    {
        $top = new class implements ProtocolInterface {
            private $version;

            public function __construct()
            {
                $this->version = new Version(1, 0, 0);
            }

            public function version(): Version
            {
                return $this->version;
            }

            public function use(Version $version): ProtocolInterface
            {
                if (!$version->compatibleWith($this->version)) {
                    throw new VersionNotUsable($version);
                }

                return $this;
            }

            public function read(Method $method, Str $arguments): StreamInterface {}
            public function method(string $name): Method {}
            public function connection(): PConnection {}
            public function channel(): PChannel {}
            public function exchange(): Exchange {}
            public function queue(): Queue {}
            public function basic(): Basic {}
            public function transaction(): Transaction {}
        };
        $connection = new Connection(
            Transport::tcp(),
            Url::fromString('//guest:guest@localhost:5672/'),
            $protocol = new Delegate($top, new Protocol($this->createMock(ArgumentTranslator::class))),
            new ElapsedPeriod(1000),
            new Earth
        );

        $this->assertSame(
            "AMQP\x00\x00\x09\x01",
            (string) $connection->protocol()->version()
        );
        $this->assertSame(
            $connection,
            $connection->send(
                $protocol->channel()->open(new Channel(1))
            )
        );
        $this->assertInstanceOf(Frame::class, $connection->wait('channel.open-ok'));
        unset($connection); //test it closes without exception
    }
}
<commit_msg>fix tests<commit_after><?php
declare(strict_types = 1);

namespace Tests\Innmind\AMQP\Transport;

use Innmind\AMQP\{
    Transport\Connection,
    Transport\Protocol\v091\Protocol,
    Transport\Protocol as ProtocolInterface,
    Transport\Protocol\Version,
    Transport\Protocol\Connection as PConnection,
    Transport\Protocol\Channel as PChannel,
    Transport\Protocol\Exchange,
    Transport\Protocol\Queue,
    Transport\Protocol\Basic,
    Transport\Protocol\Transaction,
    Transport\Protocol\Delegate,
    Transport\Protocol\ArgumentTranslator,
    Transport\Frame,
    Transport\Frame\Channel,
    Transport\Frame\Method,
    Model\Connection\MaxFrameSize,
    Exception\VersionNotUsable
};
use Innmind\Socket\Internet\Transport;
use Innmind\Url\Url;
use Innmind\TimeContinuum\{
    ElapsedPeriod,
    TimeContinuum\Earth
};
use Innmind\Immutable\{
    Str,
    StreamInterface
};
use PHPUnit\Framework\TestCase;

class ConnectionTest extends TestCase
{
    public function testInterface()
    {
        $connection = new Connection(
            Transport::tcp(),
            Url::fromString('//guest:guest@localhost:5672/'),
            $protocol = new Protocol($this->createMock(ArgumentTranslator::class)),
            new ElapsedPeriod(1000),
            new Earth
        );

        $this->assertSame($protocol, $connection->protocol());
        $this->assertInstanceOf(MaxFrameSize::class, $connection->maxFrameSize());
        $this->assertSame(131072, $connection->maxFrameSize()->toInt());
        $this->assertSame(
            $connection,
            $connection->send(
                $protocol->channel()->open(new Channel(1))
            )
        );
        $this->assertInstanceOf(Frame::class, $connection->wait('channel.open-ok'));
        unset($connection); //test it closes without exception
    }

    public function testClose()
    {
        $connection = new Connection(
            Transport::tcp(),
            Url::fromString('//guest:guest@localhost:5672/'),
            $protocol = new Protocol($this->createMock(ArgumentTranslator::class)),
            new ElapsedPeriod(1000),
            new Earth
        );

        $this->assertTrue($connection->opened());
        $this->assertNull($connection->close());
        $this->assertFalse($connection->opened());
    }

    /**
     * @expectedException Innmind\AMQP\Exception\UnexpectedFrame
     */
    public function testThrowWhenReceivedFrameIsNotTheExpectedOne()
    {
        $connection = new Connection(
            Transport::tcp(),
            Url::fromString('//guest:guest@localhost:5672/'),
            $protocol = new Protocol($this->createMock(ArgumentTranslator::class)),
            new ElapsedPeriod(1000),
            new Earth
        );
        $connection
            ->send(
                $protocol->channel()->open(new Channel(2))
            )
            ->wait('connection.open');
    }

    public function testUseCorrectProtocolVersion()
    {
        $top = new class implements ProtocolInterface {
            private $version;

            public function __construct()
            {
                $this->version = new Version(1, 0, 0);
            }

            public function version(): Version
            {
                return $this->version;
            }

            public function use(Version $version): ProtocolInterface
            {
                if (!$version->compatibleWith($this->version)) {
                    throw new VersionNotUsable($version);
                }

                return $this;
            }

            public function read(Method $method, Str $arguments): StreamInterface {}
            public function readHeader(Str $arguments): StreamInterface {}
            public function method(string $name): Method {}
            public function connection(): PConnection {}
            public function channel(): PChannel {}
            public function exchange(): Exchange {}
            public function queue(): Queue {}
            public function basic(): Basic {}
            public function transaction(): Transaction {}
        };
        $connection = new Connection(
            Transport::tcp(),
            Url::fromString('//guest:guest@localhost:5672/'),
            $protocol = new Delegate($top, new Protocol($this->createMock(ArgumentTranslator::class))),
            new ElapsedPeriod(1000),
            new Earth
        );

        $this->assertSame(
            "AMQP\x00\x00\x09\x01",
            (string) $connection->protocol()->version()
        );
        $this->assertSame(
            $connection,
            $connection->send(
                $protocol->channel()->open(new Channel(1))
            )
        );
        $this->assertInstanceOf(Frame::class, $connection->wait('channel.open-ok'));
        unset($connection); //test it closes without exception
    }
}

{'fraction_non_alphanumeric': 0.12271081220900155, 'fraction_numerical': 0.011588204862907398, 'mean_word_length': 2.1796052631578946, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1538851', 'n_tokens_mistral': 2496, 'n_tokens_neox': 2377, 'n_words': 456}