THRIFT-5951: Add PHP runtime coverage tests#3405
THRIFT-5951: Add PHP runtime coverage tests#3405sveneld wants to merge 2 commits intoapache:masterfrom
Conversation
967d949 to
4357726
Compare
Client: php Generated-by: Codex GPT-5.4
| $transport->expects($this->exactly(2)) | ||
| ->method('readAll') | ||
| ->withConsecutive([4], [2]) | ||
| ->willReturnOnConsecutiveCalls(pack('N', 2), '12'); |
There was a problem hiding this comment.
There is something weird going on here with mocks. readAll returns strings, but skipBinary() does math on it:
return 4 + $itrans->readAll($len);In this case since we return '12' as a string, 4 + '12' will be 16. Curious how does it even work...
There was a problem hiding this comment.
What happens if you return 'aa' instead of '12'?
Edit:
There was 1 error:
1) Test\Thrift\Unit\Lib\Protocol\TProtocolTest::testSkipBinarySkipsPrimitiveAndContainerValues
TypeError: Unsupported operand types: int + string
/thrift/src/lib/php/lib/Protocol/TProtocol.php:289
/thrift/src/lib/php/test/Unit/Lib/Protocol/TProtocolTest.php:190
ERRORS!
Tests: 222, Assertions: 462, Errors: 1, Skipped: 5.
I think we have a bug in the protocol implementation, and that the test does not actually test the right thing due to mocks and inputs creatively crafted around the bug.
There was a problem hiding this comment.
In PHP, almost anything is possible :)
For example:
4 + '12'=>164 + '12abc'=>16(with a warning / deprecation depending on version)4 + 'abc12'=> TypeError in modern PHP4 + '1e2'=>104
So in the old test this “worked” only because the mock happened to return a numeric-looking string, which accidentally hide the actual bug.
|
You were right, this turned out to be a real issue in the
I fixed the implementation and updated the coverage:
|
Client: php Generated-by: Codex GPT-5
|
forgot to add phpi generation to CI workflow; fixed now |
Summary
lib/php/libTBase,TProtocolskip paths,TMultiplexedProcessor,StoredMessageProtocol, base server/transport abstractions, JSON/SimpleJSON helper contexts,TApplicationException, and constant/type classesNotes
LICENSEandNOTICEare unchangedValidation
docker run --rm -v "$PWD:/src" -w /src php:8.3-cli php vendor/bin/phpunit -c lib/php/phpunit.xml --filter '/(TBaseTest|TProtocolTest|TMultiplexedProcessorTest|StoredMessageProtocolTest|TServerTest|TServerTransportTest|TTransportTest|JsonContextTest|SimpleJsonContextTest|TApplicationExceptionTest|ExceptionTypesTest|TypeConstantsTest)/' lib/php/test/Unit/Libdocker run --rm -v "$PWD:/src" -w /src php:8.3-cli sh -lc 'for f in lib/php/test/Unit/Lib/Base/TBaseTest.php lib/php/test/Unit/Lib/Protocol/TProtocolTest.php lib/php/test/Unit/Lib/TMultiplexedProcessorTest.php lib/php/test/Unit/Lib/StoredMessageProtocolTest.php lib/php/test/Unit/Lib/Server/TServerTest.php lib/php/test/Unit/Lib/Server/TServerTransportTest.php lib/php/test/Unit/Lib/Transport/TTransportTest.php lib/php/test/Unit/Lib/Protocol/JsonContextTest.php lib/php/test/Unit/Lib/Protocol/SimpleJsonContextTest.php lib/php/test/Unit/Lib/Exception/TApplicationExceptionTest.php lib/php/test/Unit/Lib/Exception/ExceptionTypesTest.php lib/php/test/Unit/Lib/Type/TypeConstantsTest.php; do php -l "$f" || exit 1; done'Generated-by: Codex GPT-5.4