Skip to content

Commit

Permalink
fixing php 8.2 deprecations (#30997)
Browse files Browse the repository at this point in the history
* fixing php8.2 test deprecations
fixes various dynamic property deprecations in the tests themselves

* fixing phpunit9 deprecation
at() matcher is deprecated, to be removed in phpunit 10. switch to withConsecutive

* adding channel property to Grpc\Call
this resolves "Creation of dynamic property Grpc\Call::$channel is deprecated" in php 8.2

* skip implicit cast test in 8.1+
implicit casting from float to int is deprecated from 8.1, so users would receive a deprecation warning if trying to do this

* php8.2rc4
  • Loading branch information
brettmc committed Oct 26, 2022
1 parent 9d71633 commit 14d1403
Show file tree
Hide file tree
Showing 18 changed files with 127 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/php/bin/build_all_docker_images.sh
Expand Up @@ -17,7 +17,7 @@ set -e
cd $(dirname $0)/../../..

ALL_IMAGES=( grpc-ext grpc-src alpine centos7 php-src php-future php-zts
fork-support i386 php8 )
fork-support i386 php8 php8.2 )

if [[ "$1" == "--cmds" ]]; then
for arg in "${ALL_IMAGES[@]}"
Expand Down
2 changes: 1 addition & 1 deletion src/php/bin/run_all_docker_images.sh
Expand Up @@ -17,7 +17,7 @@ set -e
cd $(dirname $0)/../../..

ALL_IMAGES=( grpc-ext grpc-src alpine centos7 php-src php-future php-zts
fork-support i386 php8 )
fork-support i386 php8 php8.2 )

if [[ "$1" == "--cmds" ]]; then
for arg in "${ALL_IMAGES[@]}"
Expand Down
45 changes: 45 additions & 0 deletions src/php/docker/php8.2/Dockerfile
@@ -0,0 +1,45 @@
# Copyright 2020 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM php:8.2.0RC4-zts-buster

RUN apt-get -qq update && apt-get -qq -y upgrade && apt-get -qq install -y \
autoconf automake git libtool pkg-config \
valgrind wget zlib1g-dev

ARG MAKEFLAGS=-j8


WORKDIR /tmp

# install pear
RUN apt-get install expect -y && \
curl -LO http://pear.php.net/go-pear.phar && \
expect -c 'spawn php ./go-pear.phar; expect "or Enter to continue:"; send "\n"; expect "Currently used php.ini"; send "\n"; expect eof' && \
rm go-pear.phar

RUN wget https://phar.phpunit.de/phpunit-9.5.9.phar && \
mv phpunit-9.5.9.phar /usr/local/bin/phpunit && \
chmod +x /usr/local/bin/phpunit


WORKDIR /github/grpc

COPY . .

RUN pear package && \
find . -name grpc-*.tgz | xargs -I{} pecl install {}


CMD ["/github/grpc/src/php/bin/run_tests.sh", "--skip-persistent-channel-tests", "--ignore-valgrind-undef-errors"]
5 changes: 5 additions & 0 deletions src/php/ext/grpc/call.c
Expand Up @@ -624,5 +624,10 @@ void grpc_init_call(TSRMLS_D) {
INIT_CLASS_ENTRY(ce, "Grpc\\Call", call_methods);
ce.create_object = create_wrapped_grpc_call;
grpc_ce_call = zend_register_internal_class(&ce TSRMLS_CC);
zval property_channel_default_value;
ZVAL_NULL(&property_channel_default_value);
zend_string *property_channel_name = zend_string_init("channel", sizeof("channel") - 1, 1);
zend_declare_property_ex(grpc_ce_call, property_channel_name, &property_channel_default_value, ZEND_ACC_PROTECTED, NULL);
zend_string_release(property_channel_name);
PHP_GRPC_INIT_HANDLER(wrapped_grpc_call, call_ce_handlers);
}
5 changes: 5 additions & 0 deletions src/php/tests/unit_tests/CallCredentials2Test.php
Expand Up @@ -19,6 +19,11 @@

class CallCredentials2Test extends \PHPUnit\Framework\TestCase
{
private $server;
private $port;
private $host_override;
private $channel;

public function setUp(): void
{
$credentials = Grpc\ChannelCredentials::createSsl(
Expand Down
7 changes: 7 additions & 0 deletions src/php/tests/unit_tests/CallCredentialsTest.php
Expand Up @@ -19,6 +19,13 @@

class CallCredentialsTest extends \PHPUnit\Framework\TestCase
{
private $credentials;
private $call_credentials;
private $server;
private $port;
private $host_override;
private $channel;

public function setUp(): void
{
$this->credentials = Grpc\ChannelCredentials::createSsl(
Expand Down
3 changes: 3 additions & 0 deletions src/php/tests/unit_tests/CallInvokerTest.php
Expand Up @@ -161,6 +161,9 @@ public function wait()

class CallInvokerTest extends \PHPUnit\Framework\TestCase
{
private $server;
private $port;

public function setUp(): void
{
$this->server = new Grpc\Server([]);
Expand Down
2 changes: 2 additions & 0 deletions src/php/tests/unit_tests/CallTest.php
Expand Up @@ -20,6 +20,8 @@ class CallTest extends \PHPUnit\Framework\TestCase
{
public static $server;
public static $port;
private $channel;
private $call;

public static function setUpBeforeClass(): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/php/tests/unit_tests/ChannelCredentialsTest.php
Expand Up @@ -17,7 +17,7 @@
*
*/

class ChanellCredentialsTest extends \PHPUnit\Framework\TestCase
class ChannelCredentialsTest extends \PHPUnit\Framework\TestCase
{
public function setUp(): void
{
Expand Down
10 changes: 8 additions & 2 deletions src/php/tests/unit_tests/ChannelTest.php
Expand Up @@ -19,14 +19,20 @@

class ChannelTest extends \PHPUnit\Framework\TestCase
{
private $channel;
private $channel1;
private $channel2;
private $channel3;

public function setUp(): void
{
}

public function tearDown(): void
{
if (!empty($this->channel)) {
$this->channel->close();
foreach ([$this->channel, $this->channel1, $this->channel2, $this->channel3] as $channel)
if (!empty($channel)) {
$channel->close();
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/php/tests/unit_tests/EndToEndTest.php
Expand Up @@ -18,6 +18,10 @@
*/
class EndToEndTest extends \PHPUnit\Framework\TestCase
{
private $server;
private $port;
private $channel;

public function setUp(): void
{
$this->server = new Grpc\Server([]);
Expand Down
4 changes: 4 additions & 0 deletions src/php/tests/unit_tests/InterceptorTest.php
Expand Up @@ -217,6 +217,10 @@ public function interceptStreamUnary($method,

class InterceptorTest extends \PHPUnit\Framework\TestCase
{
private $server;
private $port;
private $channel;

public function setUp(): void
{
$this->server = new Grpc\Server([]);
Expand Down
Expand Up @@ -20,7 +20,7 @@
/**
* @group persistent_list_bound_tests
*/
class PersistentListTest extends \PHPUnit\Framework\TestCase
class PersistentChannelTest extends \PHPUnit\Framework\TestCase
{
public function setUp(): void
{
Expand Down
3 changes: 3 additions & 0 deletions src/php/tests/unit_tests/RpcServerTest.php
Expand Up @@ -25,6 +25,9 @@

class RpcServerTest extends \PHPUnit\Framework\TestCase
{
private $server;
private $mockService;

public function setUp(): void
{
$this->server = new \Grpc\RpcServer();
Expand Down
5 changes: 5 additions & 0 deletions src/php/tests/unit_tests/SecureEndToEndTest.php
Expand Up @@ -18,6 +18,11 @@
*/
class SecureEndToEndTest extends \PHPUnit\Framework\TestCase
{
private $server;
private $port;
private $host_override;
private $channel;

public function setUp(): void
{
$credentials = Grpc\ChannelCredentials::createSsl(
Expand Down
48 changes: 25 additions & 23 deletions src/php/tests/unit_tests/ServerCallTest.php
Expand Up @@ -58,6 +58,9 @@ public function mergeFromString(string $value)

class ServerCallTest extends \PHPUnit\Framework\TestCase
{
private $mockCall;
private $serverContext;

public function setUp(): void
{
$this->mockCall = $this->getMockBuilder(stdClass::class)
Expand Down Expand Up @@ -279,37 +282,36 @@ public function testFinishWithMetadataAndMessage()
$serverCallWriter->finish($message, ['flags' => 0x02]);
}

/**
* @todo `at` is deprecated and will be removed in phpunit 10
*/
public function testStartWriteFinish()
{
$metadata = ['a' => 1];
$metadata2 = ['a' => 2];
$message1 = $this->newStringMessage();
$message2 = $this->newStringMessage('another string');

$this->mockCall->expects($this->at(0))
->method('startBatch')
->with($this->identicalTo([
\Grpc\OP_SEND_INITIAL_METADATA => $metadata,
]));
$this->mockCall->expects($this->at(1))
->method('startBatch')
->with($this->identicalTo([
\Grpc\OP_SEND_MESSAGE => ['message' => $message1->serializeToString()],
]));
$this->mockCall->expects($this->at(2))
$this->mockCall->expects($this->exactly(4))
->method('startBatch')
->with($this->identicalTo([
\Grpc\OP_SEND_MESSAGE => [
'message' => $message2->serializeToString(),
'flags' => 0x02,
]
]));
$this->mockCall->expects($this->at(3))
->method('startBatch')
->with($this->identicalTo([
\Grpc\OP_SEND_STATUS_FROM_SERVER => \Grpc\Status::ok(),
\Grpc\OP_RECV_CLOSE_ON_SERVER => true,
]));
->withConsecutive(
[$this->identicalTo([
\Grpc\OP_SEND_INITIAL_METADATA => $metadata,
])],
[$this->identicalTo([
\Grpc\OP_SEND_MESSAGE => ['message' => $message1->serializeToString()],
])],
[$this->identicalTo([
\Grpc\OP_SEND_MESSAGE => [
'message' => $message2->serializeToString(),
'flags' => 0x02,
]
])],
[$this->identicalTo([
\Grpc\OP_SEND_STATUS_FROM_SERVER => \Grpc\Status::ok(),
\Grpc\OP_RECV_CLOSE_ON_SERVER => true,
])]
);

$serverCallWriter = new \Grpc\ServerCallWriter(
$this->mockCall,
Expand Down
2 changes: 2 additions & 0 deletions src/php/tests/unit_tests/ServerTest.php
Expand Up @@ -19,6 +19,8 @@

class ServerTest extends \PHPUnit\Framework\TestCase
{
private $server;

public function setUp(): void
{
$this->server = null;
Expand Down
5 changes: 5 additions & 0 deletions src/php/tests/unit_tests/TimevalTest.php
Expand Up @@ -18,6 +18,8 @@
*/
class TimevalTest extends \PHPUnit\Framework\TestCase
{
private $time;

public function setUp(): void
{
}
Expand Down Expand Up @@ -64,6 +66,9 @@ public function testConstructorWithHex()

public function testConstructorWithFloat()
{
if (version_compare(PHP_VERSION, '8.1.0') >= 0) {
$this->markTestSkipped('implicit float to int cast deprecated in 8.1+');
}
$this->time = new Grpc\Timeval(123.456);
$this->assertNotNull($this->time);
$this->assertSame('Grpc\Timeval', get_class($this->time));
Expand Down

0 comments on commit 14d1403

Please sign in to comment.