当前位置: 首页>>代码示例>>PHP>>正文


PHP Assert::Throws方法代码示例

本文整理汇总了PHP中Assert::Throws方法的典型用法代码示例。如果您正苦于以下问题:PHP Assert::Throws方法的具体用法?PHP Assert::Throws怎么用?PHP Assert::Throws使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Assert的用法示例。


在下文中一共展示了Assert::Throws方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testByteBuffer

function testByteBuffer(Assert $assert)
{
    //Test: ByteBuffer_Length_MatchesBufferLength
    $buffer = str_repeat("", 100);
    $uut = Google\FlatBuffers\ByteBuffer::wrap($buffer);
    $assert->Equal($uut->capacity(), strlen($buffer));
    //Test: ByteBuffer_PutBytePopulatesBufferAtZeroOffset
    $buffer = "";
    $uut = Google\FlatBuffers\ByteBuffer::wrap($buffer);
    $uut->putByte(0, "c");
    // 99
    $assert->Equal("c", $uut->_buffer[0]);
    // don't share buffer as php user might confuse reference.
    //Test: ByteBuffer_PutByteCannotPutAtOffsetPastLength
    $buffer = "";
    $uut = Google\FlatBuffers\ByteBuffer::wrap($buffer);
    $assert->Throws(new OutOfRangeException(), function () use($uut) {
        $uut->putByte(1, "c");
        // 99
    });
    //Test: ByteBuffer_PutShortPopulatesBufferCorrectly
    $buffer = str_repeat("", 2);
    $uut = Google\FlatBuffers\ByteBuffer::wrap($buffer);
    $uut->putShort(0, 1);
    // Ensure Endiannes was written correctly
    $assert->Equal(chr(0x1), $uut->_buffer[0]);
    $assert->Equal(chr(0x0), $uut->_buffer[1]);
    $buffer = str_repeat("", 2);
    $uut = Google\FlatBuffers\ByteBuffer::wrap($buffer);
    $uut->putShort(0, -32768);
    // Ensure Endiannes was written correctly
    $assert->Equal(chr(0x0), $uut->_buffer[0]);
    $assert->Equal(chr(0x80), $uut->_buffer[1]);
    //Test: ByteBuffer_PutShortCannotPutAtOffsetPastLength
    $buffer = "";
    $uut = Google\FlatBuffers\ByteBuffer::wrap($buffer);
    $assert->Throws(new OutOfRangeException(), function () use($uut) {
        $uut->putShort(2, "c");
        // 99
    });
    //Test: ByteBuffer_PutShortChecksLength
    $buffer = "";
    $uut = Google\FlatBuffers\ByteBuffer::wrap($buffer);
    $assert->Throws(new OutOfRangeException(), function () use($uut) {
        $uut->putShort(0, "c");
        // 99
    });
    //Test: ByteBuffer_PutShortChecksLengthAndOffset
    $buffer = str_repeat("", 2);
    $uut = Google\FlatBuffers\ByteBuffer::wrap($buffer);
    $assert->Throws(new OutOfRangeException(), function () use($uut) {
        $uut->putShort(1, "c");
        // 99
    });
    //Test: ByteBuffer_PutIntPopulatesBufferCorrectly
    $buffer = str_repeat("", 4);
    $uut = Google\FlatBuffers\ByteBuffer::wrap($buffer);
    $uut->putInt(0, 0xa0b0c0d);
    $assert->Equal(chr(0xd), $uut->_buffer[0]);
    $assert->Equal(chr(0xc), $uut->_buffer[1]);
    $assert->Equal(chr(0xb), $uut->_buffer[2]);
    $assert->Equal(chr(0xa), $uut->_buffer[3]);
    $buffer = str_repeat("", 4);
    $uut = Google\FlatBuffers\ByteBuffer::wrap($buffer);
    $uut->putInt(0, -2147483648);
    $assert->Equal(chr(0x0), $uut->_buffer[0]);
    $assert->Equal(chr(0x0), $uut->_buffer[1]);
    $assert->Equal(chr(0x0), $uut->_buffer[2]);
    $assert->Equal(chr(0x80), $uut->_buffer[3]);
    //Test: ByteBuffer_PutIntCannotPutAtOffsetPastLength
    $buffer = str_repeat("", 4);
    $uut = Google\FlatBuffers\ByteBuffer::wrap($buffer);
    $assert->Throws(new OutOfRangeException(), function () use($uut) {
        $uut->putInt(2, 0xa0b0c0d);
    });
    //Test: ByteBuffer_PutIntChecksLength
    $buffer = str_repeat("", 1);
    $uut = Google\FlatBuffers\ByteBuffer::wrap($buffer);
    $assert->Throws(new OutOfRangeException(), function () use($uut) {
        $uut->putInt(0, 0xa0b0c0d);
    });
    //Test: ByteBuffer_PutIntChecksLengthAndOffset
    $buffer = str_repeat("", 4);
    $uut = Google\FlatBuffers\ByteBuffer::wrap($buffer);
    $assert->Throws(new OutOfRangeException(), function () use($uut) {
        $uut->putInt(2, 0xa0b0c0d);
    });
    if (PHP_INT_SIZE > 4) {
        //Test: ByteBuffer_PutLongPopulatesBufferCorrectly
        $buffer = str_repeat("", 8);
        $uut = Google\FlatBuffers\ByteBuffer::wrap($buffer);
        $uut->putLong(0, 0x10203040a0b0c0d);
        $assert->Equal(chr(0xd), $uut->_buffer[0]);
        $assert->Equal(chr(0xc), $uut->_buffer[1]);
        $assert->Equal(chr(0xb), $uut->_buffer[2]);
        $assert->Equal(chr(0xa), $uut->_buffer[3]);
        $assert->Equal(chr(0x4), $uut->_buffer[4]);
        $assert->Equal(chr(0x3), $uut->_buffer[5]);
        $assert->Equal(chr(0x2), $uut->_buffer[6]);
        $assert->Equal(chr(0x1), $uut->_buffer[7]);
//.........这里部分代码省略.........
开发者ID:ncpenke,项目名称:flatbuffers,代码行数:101,代码来源:phpTest.php


注:本文中的Assert::Throws方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。