Skip to content

Commit

Permalink
Port for php8
Browse files Browse the repository at this point in the history
  • Loading branch information
TeBoring committed Nov 30, 2020
1 parent 9432c99 commit 51b2c4d
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 129 deletions.
4 changes: 2 additions & 2 deletions php/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"homepage": "https://developers.google.com/protocol-buffers/",
"license": "BSD-3-Clause",
"require": {
"php": ">=5.5.0"
"php": ">=7.3.0"
},
"require-dev": {
"phpunit/phpunit": "^5|^4.8.0"
"phpunit/phpunit": "^9"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 2 additions & 0 deletions php/tests/ArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@ public function testArrayElementIsReferenceInSetters()
$sub = new Sub(['a' => $sub]);
}
$m->setRepeatedMessage($subs);

$this->assertTrue(true);
}

#########################################################
Expand Down
10 changes: 4 additions & 6 deletions php/tests/DescriptorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,22 +205,20 @@ public function testFieldDescriptor()
$this->assertSame(self::GPBTYPE_ENUM, $mapDesc->getField(1)->getType());
}

/**
* @expectedException \Exception
*/
public function testFieldDescriptorEnumException()
{
$this->expectException(Exception::class);

$pool = DescriptorPool::getGeneratedPool();
$desc = $pool->getDescriptorByClassName(get_class(new TestDescriptorsMessage()));
$fieldDesc = $desc->getField(0);
$fieldDesc->getEnumType();
}

/**
* @expectedException \Exception
*/
public function testFieldDescriptorMessageException()
{
$this->expectException(Exception::class);

$pool = DescriptorPool::getGeneratedPool();
$desc = $pool->getDescriptorByClassName(get_class(new TestDescriptorsMessage()));
$fieldDesc = $desc->getField(0);
Expand Down
117 changes: 47 additions & 70 deletions php/tests/EncodeDecodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function testEncodeTopLevelBytesValue()
public function generateRandomString($length = 10) {
$randomString = str_repeat("+", $length);
for ($i = 0; $i < $length; $i++) {
$randomString[$i] = rand(0, 255);
$randomString[$i] = chr(rand(0, 255));
}
return $randomString;
}
Expand Down Expand Up @@ -529,200 +529,178 @@ public function testRandomFieldOrder()
$this->assertSame("", $data);
}

/**
* @expectedException Exception
*/
public function testDecodeInvalidInt32()
{
$this->expectException(Exception::class);

$m = new TestMessage();
$m->mergeFromString(hex2bin('08'));
}

/**
* @expectedException Exception
*/
public function testDecodeInvalidSubMessage()
{
$this->expectException(Exception::class);

$m = new TestMessage();
$m->mergeFromString(hex2bin('9A010108'));
}

/**
* @expectedException Exception
*/
public function testDecodeInvalidInt64()
{
$this->expectException(Exception::class);

$m = new TestMessage();
$m->mergeFromString(hex2bin('10'));
}

/**
* @expectedException Exception
*/
public function testDecodeInvalidUInt32()
{
$this->expectException(Exception::class);

$m = new TestMessage();
$m->mergeFromString(hex2bin('18'));
}

/**
* @expectedException Exception
*/
public function testDecodeInvalidUInt64()
{
$this->expectException(Exception::class);

$m = new TestMessage();
$m->mergeFromString(hex2bin('20'));
}

/**
* @expectedException Exception
*/
public function testDecodeInvalidSInt32()
{
$this->expectException(Exception::class);

$m = new TestMessage();
$m->mergeFromString(hex2bin('28'));
}

/**
* @expectedException Exception
*/
public function testDecodeInvalidSInt64()
{
$this->expectException(Exception::class);

$m = new TestMessage();
$m->mergeFromString(hex2bin('30'));
}

/**
* @expectedException Exception
*/
public function testDecodeInvalidFixed32()
{
$this->expectException(Exception::class);

$m = new TestMessage();
$m->mergeFromString(hex2bin('3D'));
}

/**
* @expectedException Exception
*/
public function testDecodeInvalidFixed64()
{
$this->expectException(Exception::class);

$m = new TestMessage();
$m->mergeFromString(hex2bin('41'));
}

/**
* @expectedException Exception
*/
public function testDecodeInvalidSFixed32()
{
$this->expectException(Exception::class);

$m = new TestMessage();
$m->mergeFromString(hex2bin('4D'));
}

/**
* @expectedException Exception
*/
public function testDecodeInvalidSFixed64()
{
$this->expectException(Exception::class);

$m = new TestMessage();
$m->mergeFromString(hex2bin('51'));
}

/**
* @expectedException Exception
*/
public function testDecodeInvalidFloat()
{
$this->expectException(Exception::class);

$m = new TestMessage();
$m->mergeFromString(hex2bin('5D'));
}

/**
* @expectedException Exception
*/
public function testDecodeInvalidDouble()
{
$this->expectException(Exception::class);

$m = new TestMessage();
$m->mergeFromString(hex2bin('61'));
}

/**
* @expectedException Exception
*/
public function testDecodeInvalidBool()
{
$this->expectException(Exception::class);

$m = new TestMessage();
$m->mergeFromString(hex2bin('68'));
}

/**
* @expectedException Exception
*/
public function testDecodeInvalidStringLengthMiss()
{
$this->expectException(Exception::class);

$m = new TestMessage();
$m->mergeFromString(hex2bin('72'));
}

/**
* @expectedException Exception
*/
public function testDecodeInvalidStringDataMiss()
{
$this->expectException(Exception::class);

$m = new TestMessage();
$m->mergeFromString(hex2bin('7201'));
}

/**
* @expectedException Exception
*/
public function testDecodeInvalidBytesLengthMiss()
{
$this->expectException(Exception::class);

$m = new TestMessage();
$m->mergeFromString(hex2bin('7A'));
}

/**
* @expectedException Exception
*/
public function testDecodeInvalidBytesDataMiss()
{
$this->expectException(Exception::class);

$m = new TestMessage();
$m->mergeFromString(hex2bin('7A01'));
}

/**
* @expectedException Exception
*/
public function testDecodeInvalidEnum()
{
$this->expectException(Exception::class);

$m = new TestMessage();
$m->mergeFromString(hex2bin('8001'));
}

/**
* @expectedException Exception
*/
public function testDecodeInvalidMessageLengthMiss()
{
$this->expectException(Exception::class);

$m = new TestMessage();
$m->mergeFromString(hex2bin('8A01'));
}

/**
* @expectedException Exception
*/
public function testDecodeInvalidMessageDataMiss()
{
$this->expectException(Exception::class);

$m = new TestMessage();
$m->mergeFromString(hex2bin('8A0101'));
}

/**
* @expectedException Exception
*/
public function testDecodeInvalidPackedMessageLength()
{
$this->expectException(Exception::class);

$m = new TestPackedMessage();
$m->mergeFromString(hex2bin('D205'));
}
Expand Down Expand Up @@ -1143,11 +1121,10 @@ public function testDecodeAnyWithWellKnownPacked()
$this->assertSame("0801", bin2hex($m1->getAny()->getValue()));
}

/**
* @expectedException Exception
*/
public function testDecodeAnyWithUnknownPacked()
{
$this->expectException(Exception::class);

$m = new TestAny();
$m->mergeFromJsonString(
"{\"any\":" .
Expand Down

0 comments on commit 51b2c4d

Please sign in to comment.