Skip to content

Commit 1c59323

Browse files
authored
THRIFT-5961: Migrate PHPUnit tests to attributes and upgrade to PHPUnit 10+ (#3438)
Client: php THRIFT-5962 PHPUnit major upgrade THRIFT-5961 attribute syntax migration
1 parent 9d4d6f0 commit 1c59323

45 files changed

Lines changed: 801 additions & 575 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"php": "^8.1"
2222
},
2323
"require-dev": {
24-
"phpunit/phpunit": "^9.5",
24+
"phpunit/phpunit": "^10.5 || ^11.0 || ^12.0 || ^13.0",
2525
"squizlabs/php_codesniffer": "^3.10",
2626
"php-mock/php-mock-phpunit": "^2.10",
2727
"phpstan/phpstan": "^1.12",

lib/php/lib/Server/TForkingServer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ private function handleChild(TTransport $transport)
101101
*/
102102
private function collectChildren()
103103
{
104+
$status = null;
104105
foreach ($this->children_ as $pid => $transport) {
105106
if (pcntl_waitpid($pid, $status, WNOHANG) > 0) {
106107
unset($this->children_[$pid]);

lib/php/phpunit.xml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,15 @@
2121
bootstrap="test/bootstrap.php"
2222
cacheResult="false"
2323
colors="true"
24-
convertErrorsToExceptions="true"
25-
convertNoticesToExceptions="true"
26-
convertWarningsToExceptions="true"
2724
stopOnWarning="true"
2825
stopOnFailure="true"
2926
processIsolation="true"
30-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd">
31-
<filter>
32-
<whitelist processUncoveredFilesFromWhitelist="true">
27+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd">
28+
<source>
29+
<include>
3330
<directory suffix=".php">./lib</directory>
34-
</whitelist>
35-
</filter>
31+
</include>
32+
</source>
3633
<testsuites>
3734
<testsuite name="Thrift PHP Unit Test Suite">
3835
<directory>./test/Unit</directory>

lib/php/test/Integration/BaseValidatorTest.php renamed to lib/php/test/Integration/AbstractValidatorTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
use Thrift\Protocol\TBinaryProtocol;
2727
use Thrift\Transport\TMemoryBuffer;
2828

29-
abstract class BaseValidatorTest extends TestCase
29+
abstract class AbstractValidatorTestCase extends TestCase
3030
{
3131
abstract public function getNsGlobal();
3232

lib/php/test/Integration/Lib/ClassLoader/ThriftClassLoaderTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
use phpmock\phpunit\PHPMock;
2525
use PHPUnit\Framework\TestCase;
26+
use PHPUnit\Framework\Attributes\DataProvider;
2627
use Thrift\ClassLoader\ThriftClassLoader;
2728

2829
/***
@@ -33,9 +34,7 @@ class ThriftClassLoaderTest extends TestCase
3334
{
3435
use PHPMock;
3536

36-
/**
37-
* @dataProvider registerDefinitionDataProvider
38-
*/
37+
#[DataProvider('registerDefinitionDataProvider')]
3938
public function testRegisterDefinition(
4039
$definitions,
4140
$class,
@@ -67,7 +66,7 @@ public function testRegisterDefinition(
6766
}
6867
}
6968

70-
public function registerDefinitionDataProvider()
69+
public static function registerDefinitionDataProvider()
7170
{
7271
yield 'loadType' => [
7372
'definitions' => [

lib/php/test/Integration/Lib/Protocol/TJSONProtocolTest.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
namespace Test\Thrift\Integration\Lib\Protocol;
2323

2424
use PHPUnit\Framework\TestCase;
25+
use PHPUnit\Framework\Attributes\DataProvider;
2526
use Thrift\Protocol\TJSONProtocol;
2627
use Thrift\Transport\TMemoryBuffer;
2728
use Basic\ThriftTest\Insanity;
@@ -64,9 +65,7 @@ public function testMessageReadWrite()
6465
$this->assertSame('successResponse', $result);
6566
}
6667

67-
/**
68-
* @dataProvider writeDataProvider
69-
*/
68+
#[DataProvider('writeDataProvider')]
7069
public function testWrite(
7170
$argsClassName,
7271
$argsValues,
@@ -80,7 +79,7 @@ public function testWrite(
8079
$this->assertEquals($expected, $actual);
8180
}
8281

83-
public function writeDataProvider()
82+
public static function writeDataProvider()
8483
{
8584
if (!is_dir(__DIR__ . '/../../../Resources/packages/php')) {
8685
throw new \RuntimeException(
@@ -316,9 +315,7 @@ public function writeDataProvider()
316315
];
317316
}
318317

319-
/**
320-
* @dataProvider readDataProvider
321-
*/
318+
#[DataProvider('readDataProvider')]
322319
public function testRead(
323320
$buffer,
324321
$argsClassName,
@@ -343,7 +340,7 @@ public function testRead(
343340
}
344341
}
345342

346-
public function readDataProvider()
343+
public static function readDataProvider()
347344
{
348345
yield 'void' => [
349346
'buffer' => '{}',

lib/php/test/Integration/Lib/Protocol/TSimpleJSONProtocolTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
namespace Test\Thrift\Integration\Lib\Protocol;
2323

2424
use PHPUnit\Framework\TestCase;
25+
use PHPUnit\Framework\Attributes\DataProvider;
2526
use Thrift\Protocol\TJSONProtocol;
2627
use Thrift\Protocol\TSimpleJSONProtocol;
2728
use Thrift\Transport\TMemoryBuffer;
@@ -64,9 +65,7 @@ public function testMessageWrite()
6465
$this->assertSame('["testString",1,0,{"thing":"test"}]', $this->protocol->getTransport()->getBuffer());
6566
}
6667

67-
/**
68-
* @dataProvider writeDataProvider
69-
*/
68+
#[DataProvider('writeDataProvider')]
7069
public function testWrite(
7170
$argsClassName,
7271
$argsValues,
@@ -80,7 +79,7 @@ public function testWrite(
8079
$this->assertEquals($expected, $actual);
8180
}
8281

83-
public function writeDataProvider()
82+
public static function writeDataProvider()
8483
{
8584
if (!is_dir(__DIR__ . '/../../../Resources/packages/php')) {
8685
throw new \RuntimeException(

lib/php/test/Integration/ValidatorOopTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* This test suite depends on running the compiler against the ./Resources/ThriftTest.thrift file:
2626
* lib/php/test$ ../../../compiler/cpp/thrift --gen php:validate,oop,nsglobal="ValidateOop" -r --out ./Resources/packages/phpvo ./Resources/ThriftTest.thrift
2727
*/
28-
class ValidatorOopTest extends BaseValidatorTest
28+
class ValidatorOopTest extends AbstractValidatorTestCase
2929
{
3030
public function getNsGlobal()
3131
{

lib/php/test/Integration/ValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* This test suite depends on running the compiler against the ./Resources/ThriftTest.thrift file:
2626
* lib/php/test$ ../../../compiler/cpp/thrift --gen php:validate,nsglobal="Validate" -r --out ./Resources/packages/phpv ./Resources/ThriftTest.thrift
2727
*/
28-
class ValidatorTest extends BaseValidatorTest
28+
class ValidatorTest extends AbstractValidatorTestCase
2929
{
3030
public function getNsGlobal()
3131
{

lib/php/test/Unit/Lib/ClassLoader/ThriftClassLoaderTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@
2323

2424
use phpmock\phpunit\PHPMock;
2525
use PHPUnit\Framework\TestCase;
26+
use PHPUnit\Framework\Attributes\DataProvider;
2627
use Thrift\ClassLoader\ThriftClassLoader;
2728

2829
class ThriftClassLoaderTest extends TestCase
2930
{
3031
use PHPMock;
3132

32-
/**
33-
* @dataProvider registerNamespaceDataProvider
34-
*/
33+
#[DataProvider('registerNamespaceDataProvider')]
3534
public function testRegisterNamespace(
3635
$namespaces,
3736
$class,
@@ -62,7 +61,7 @@ public function testRegisterNamespace(
6261
}
6362
}
6463

65-
public function registerNamespaceDataProvider()
64+
public static function registerNamespaceDataProvider()
6665
{
6766
yield 'default' => [
6867
'namespaces' => [

0 commit comments

Comments
 (0)