Skip to content

Commit 78e3606

Browse files
authored
PHP 8 support (#793)
* Run tests on PHP 8 * Provide new polyfill for phpunit assertion functions * PHPLIB-588: Add polyfill for PHP 8's get_debug_type function * Add missing tearDown calls * Remove obsolete BC layer * Fix type names in assertions * Test on PHP 7.4 by default * Use 5.x-dev for symfony/phpunit-bridge until a release is tagged Not all necessary fixes are available in the latest beta. Once Symfony 5.2 is released, we can switch to this stable version. * Use correct assertion method for strings * Add instructions how to run against a specific PHPUnit version
1 parent 6c66a1a commit 78e3606

30 files changed

+2902
-456
lines changed

.travis.yml

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: php
22
dist: xenial
3+
php: "7.4"
34

45
addons:
56
apt:
@@ -32,7 +33,6 @@ jobs:
3233
include:
3334

3435
- stage: Smoke Testing
35-
php: "7.3"
3636
env:
3737
- CHECKS=phpunit
3838
- stage: Smoke Testing
@@ -56,7 +56,7 @@ jobs:
5656
- stage: Test
5757
php: "7.2"
5858
- stage: Test
59-
php: "7.4"
59+
php: "7.3"
6060

6161
# Test against lowest supported dependencies
6262
- stage: Test
@@ -91,59 +91,64 @@ jobs:
9191
env:
9292
- SERVER_VERSION=3.6.19
9393
- stage: Test
94-
php: "7.3"
9594
env:
9695
- SERVER_VERSION=4.0.19
9796
- stage: Test
98-
php: "7.3"
9997
env:
10098
- SERVER_VERSION=4.2.8
10199

102100
# Test upcoming server version
103101
#- stage: Test
104-
# php: "7.3"
105102
# env:
106103
# - SERVER_VERSION=4.5.0
107104

108105
# Test other server configurations
109106
- stage: Test
110-
php: "7.3"
111107
env:
112108
- DEPLOYMENT=STANDALONE_AUTH
113109
- stage: Test
114-
php: "7.3"
115110
env:
116111
- DEPLOYMENT=STANDALONE_SSL
117112
- stage: Test
118-
php: "7.3"
119113
env:
120114
- SERVER_VERSION=3.6.13
121115
- DEPLOYMENT=REPLICASET
122116
- stage: Test
123-
php: "7.3"
124117
env:
125118
- DEPLOYMENT=REPLICASET
126119
- stage: Test
127-
php: "7.3"
128120
env:
129121
- DEPLOYMENT=SHARDED_CLUSTER
130122
- stage: Test
131-
php: "7.3"
132123
env:
133124
- DEPLOYMENT=SHARDED_CLUSTER_RS
134125

135126
# Test next patch release for driver
136127
- stage: Test
137-
php: "7.3"
138128
env:
139129
- DRIVER_BRANCH="v1.8"
140130

141131
# Test next minor release for driver
142132
- stage: Test
143-
php: "7.3"
144133
env:
145134
- DRIVER_BRANCH="master"
146135

136+
# Test upcoming PHP version
137+
- stage: Test
138+
php: "nightly"
139+
env:
140+
- DRIVER_BRANCH="master"
141+
- stage: Test
142+
php: "nightly"
143+
env:
144+
- DRIVER_BRANCH="master"
145+
- DEPLOYMENT=REPLICASET
146+
- stage: Test
147+
php: "nightly"
148+
env:
149+
- DRIVER_BRANCH="master"
150+
- DEPLOYMENT=SHARDED_CLUSTER_RS
151+
147152
before_install:
148153
- pip install "mongo-orchestration>=0.6.7,<1.0" --user `whoami`
149154
- export SERVER_FILENAME=mongodb-linux-x86_64-${SERVER_DISTRO}-${SERVER_VERSION}

CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ test suite. In addition to various PHPUnit options, it defines required
3636
this configuration by creating your own `phpunit.xml` file based on the
3737
`phpunit.xml.dist` file we provide.
3838

39+
By default, the `simple-phpunit` binary chooses the correct PHPUnit version for
40+
the PHP version you are running. To run tests against a specific PHPUnit version,
41+
use the `SYMFONY_PHPUNIT_VERSION` environment variable:
42+
43+
```
44+
$ SYMFONY_PHPUNIT_VERSION=7.5 vendor/bin/simple-phpunit
45+
```
46+
3947
## Checking coding standards
4048

4149
The library's code is checked using [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer),

composer.json

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,28 @@
99
{ "name": "Jeremy Mikola", "email": "[email protected]" }
1010
],
1111
"require": {
12-
"php": "^7.0",
12+
"php": "^7.0 || ^8.0",
1313
"ext-hash": "*",
1414
"ext-json": "*",
1515
"ext-mongodb": "^1.8.1",
16-
"jean85/pretty-package-versions": "^1.2"
16+
"jean85/pretty-package-versions": "^1.2",
17+
"symfony/polyfill-php80": "^1.19"
1718
},
1819
"require-dev": {
1920
"squizlabs/php_codesniffer": "^3.5, <3.5.5",
20-
"symfony/phpunit-bridge": "^5.2@beta"
21+
"symfony/phpunit-bridge": "5.x-dev"
2122
},
2223
"autoload": {
2324
"psr-4": { "MongoDB\\": "src/" },
2425
"files": [ "src/functions.php" ]
2526
},
2627
"autoload-dev": {
2728
"psr-4": { "MongoDB\\Tests\\": "tests/" },
28-
"// Manually include assertion functions for PHPUnit 8.x and earlier ":"",
29-
"// See: https://github.com/sebastianbergmann/phpunit/issues/3746 ":"",
30-
"files": [
31-
"vendor/bin/.phpunit/phpunit/src/Framework/Assert/Functions.php",
32-
"tests/PHPUnit/FunctionsPolyfill.php"
33-
]
29+
"files": [ "tests/PHPUnit/Functions.php" ]
3430
},
3531
"extra": {
3632
"branch-alias": {
3733
"dev-master": "1.8.x-dev"
3834
}
39-
},
40-
"scripts": {
41-
"// Ensure PHPUnit is installed through the PHPUnit bridge before ":"",
42-
"// dumping the autoloader to avoid errors due to missing files.":"",
43-
"pre-autoload-dump": "if test -f vendor/bin/simple-phpunit; then vendor/bin/simple-phpunit --version > /dev/null; fi"
4435
}
4536
}

src/Exception/InvalidArgumentException.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020
use MongoDB\Driver\Exception\InvalidArgumentException as DriverInvalidArgumentException;
2121
use function array_pop;
2222
use function count;
23-
use function get_class;
24-
use function gettype;
23+
use function get_debug_type;
2524
use function implode;
2625
use function is_array;
27-
use function is_object;
2826
use function sprintf;
2927

3028
class InvalidArgumentException extends DriverInvalidArgumentException implements Exception
@@ -58,6 +56,6 @@ public static function invalidType($name, $value, $expectedType)
5856
$expectedType = $typeString;
5957
}
6058

61-
return new static(sprintf('Expected %s to have type "%s" but found "%s"', $name, $expectedType, is_object($value) ? get_class($value) : gettype($value)));
59+
return new static(sprintf('Expected %s to have type "%s" but found "%s"', $name, $expectedType, get_debug_type($value)));
6260
}
6361
}

src/Exception/ResumeTokenException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
namespace MongoDB\Exception;
1919

20-
use function gettype;
20+
use function get_debug_type;
2121
use function sprintf;
2222

2323
class ResumeTokenException extends RuntimeException
@@ -30,7 +30,7 @@ class ResumeTokenException extends RuntimeException
3030
*/
3131
public static function invalidType($value)
3232
{
33-
return new static(sprintf('Expected resume token to have type "array or object" but found "%s"', gettype($value)));
33+
return new static(sprintf('Expected resume token to have type "array or object" but found "%s"', get_debug_type($value)));
3434
}
3535

3636
/**

tests/Collection/FunctionalTestCase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,7 @@ private function doTearDown()
3232
}
3333

3434
$this->dropCollection();
35+
36+
parent::tearDown();
3537
}
3638
}

tests/DocumentationExamplesTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ private function doTearDown()
4242
}
4343

4444
$this->dropCollection();
45+
46+
parent::tearDown();
4547
}
4648

4749
public function testExample_1_2()

tests/Model/IndexInfoFunctionalTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ private function doTearDown()
2929
}
3030

3131
$this->collection->drop();
32+
33+
parent::tearDown();
3234
}
3335

3436
public function testIs2dSphere()

tests/Operation/FunctionalTestCase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ private function doTearDown()
2828
}
2929

3030
$this->dropCollection();
31+
32+
parent::tearDown();
3133
}
3234

3335
protected function createDefaultReadConcern()

tests/PHPUnit/ConstraintTrait.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

tests/PHPUnit/ConstraintTraitForV6.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/PHPUnit/ConstraintTraitForV7.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

tests/PHPUnit/ConstraintTraitForV9.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/PHPUnit/EvaluateTrait.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)