Skip to content

Commit

Permalink
Fix PHP byte validation and reenable builds (google#7670)
Browse files Browse the repository at this point in the history
* Fix PHP byte validation and reenable builds

* Use checkout@v3

Co-authored-by: Derek Bailey <[email protected]>
  • Loading branch information
2 people authored and candhyan committed Jan 2, 2023
1 parent 0f2fc32 commit 6ab16e3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,20 @@ jobs:
working-directory: tests
run: bash GoTest.sh

build-php:
name: Build PHP
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: flatc
# FIXME: make test script not rely on flatc
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF -DFLATBUFFERS_STRICT_MODE=ON . && make -j
- name: test
working-directory: tests
run: |
php phpTest.php
sh phpUnionVectorTest.sh
build-swift:
name: Build Swift
runs-on: ubuntu-latest
Expand Down
7 changes: 6 additions & 1 deletion php/ByteBuffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,12 @@ private static function convertHelper($type, $value, $value2 = null) {
}

private static function validateValue($min, $max, $value, $type, $additional_notes = "") {
if(!($min <= $value && $value <= $max)) {
if (
!(
($type === "byte" && $min <= ord($value) && ord($value) <= $max) ||
($min <= $value && $value <= $max)
)
) {
throw new \InvalidArgumentException(sprintf("bad number %s for type %s.%s", $value, $type, $additional_notes));
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/phpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,21 +371,21 @@ function testByteBuffer(Assert $assert) {
$buffer = "\0";
$uut = Google\FlatBuffers\ByteBuffer::wrap($buffer);
$assert->Throws(new OutOfRangeException(), function() use ($uut) {
$uut->putShort(2, "\x63"); // 99
$uut->putShort(2, 2); // 99
});

//Test: ByteBuffer_PutShortChecksLength
$buffer = "\0";
$uut = Google\FlatBuffers\ByteBuffer::wrap($buffer);
$assert->Throws(new OutOfRangeException(), function() use ($uut) {
$uut->putShort(0, "\x63"); // 99
$uut->putShort(0, 2); // 99
});

//Test: ByteBuffer_PutShortChecksLengthAndOffset
$buffer = str_repeat("\0", 2);
$uut = Google\FlatBuffers\ByteBuffer::wrap($buffer);
$assert->Throws(new OutOfRangeException(), function() use ($uut) {
$uut->putShort(1, "\x63"); // 99
$uut->putShort(1, 2); // 99
});

//Test: ByteBuffer_PutIntPopulatesBufferCorrectly
Expand Down Expand Up @@ -625,7 +625,7 @@ public function Throws($class, Callable $callback) {
throw new \Exception("passed statement don't throw an exception.");
} catch (\Exception $e) {
if (get_class($e) != get_class($class)) {
throw new Exception("passed statement doesn't throw " . get_class($class) . ". throwws " . get_class($e));
throw new Exception("passed statement doesn't throw " . get_class($class) . ". throws " . get_class($e) . ": {$e->getMessage()}");
}
}
}
Expand Down

0 comments on commit 6ab16e3

Please sign in to comment.