當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。