Skip to content

Commit 48a7de7

Browse files
authored
Upgrade to PHPUnit 11 for PHP >= 8.2 and check deprecation messages (#2902)
* Upgrade to PHPUnit 11 for PHP >= 8.2 and check deprecation messages * Remove usage of deprecated Assert::assertContainsOnly()
1 parent 4655b35 commit 48a7de7

File tree

10 files changed

+16
-13
lines changed

10 files changed

+16
-13
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"phpstan/phpstan": "^2.1",
5353
"phpstan/phpstan-deprecation-rules": "^2.0",
5454
"phpstan/phpstan-phpunit": "^2.0",
55-
"phpunit/phpunit": "^10.5.58",
55+
"phpunit/phpunit": "^10.5.58|^11.5.43",
5656
"squizlabs/php_codesniffer": "^4",
5757
"symfony/cache": "^5.4 || ^6.0 || ^7.0 || ^8.0",
5858
"symfony/uid": "^5.4 || ^6.0 || ^7.0 || ^8.0"

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd"
55
bootstrap="tests/bootstrap.php"
66
cacheDirectory=".phpunit.cache"
77
displayDetailsOnAllIssues="true"

src/Proxy/Factory/LazyGhostProxyFactory.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@
2828
use function file_exists;
2929
use function file_put_contents;
3030
use function filemtime;
31-
use function get_debug_type;
3231
use function is_dir;
3332
use function is_int;
34-
use function is_scalar;
3533
use function is_writable;
3634
use function ltrim;
3735
use function mkdir;
@@ -115,7 +113,7 @@ public function __construct(
115113
}
116114

117115
if (is_int($autoGenerate) && ($autoGenerate < 0 || $autoGenerate > 4)) {
118-
throw new InvalidArgumentException(sprintf('Invalid auto generate mode "%s" given.', is_scalar($autoGenerate) ? (string) $autoGenerate : get_debug_type($autoGenerate)));
116+
throw new InvalidArgumentException(sprintf('Invalid auto generate mode "%d" given.', $autoGenerate));
119117
}
120118

121119
$this->uow = $dm->getUnitOfWork();

tests/Tests/BaseTestCase.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,11 @@ protected static function getConfiguration(): Configuration
105105
$config->setPersistentCollectionNamespace('PersistentCollections');
106106
$config->setDefaultDB(DOCTRINE_MONGODB_DATABASE);
107107
$config->setMetadataDriverImpl(static::createMetadataDriverImpl());
108-
if ($_ENV['USE_LAZY_GHOST_OBJECT']) {
109-
$config->setUseLazyGhostObject(true);
110-
}
111108

112109
if ($_ENV['USE_NATIVE_LAZY_OBJECT']) {
113110
$config->setUseNativeLazyObject(true);
111+
} elseif ($_ENV['USE_LAZY_GHOST_OBJECT']) {
112+
$config->setUseLazyGhostObject(true);
114113
}
115114

116115
if ($config->isNativeLazyObjectEnabled()) {

tests/Tests/ConfigurationTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Doctrine\ODM\MongoDB\PersistentCollection\PersistentCollectionGenerator;
1212
use LogicException;
1313
use MongoDB\Driver\Manager;
14+
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
1415
use PHPUnit\Framework\Attributes\RequiresPhp;
1516
use PHPUnit\Framework\Attributes\TestWith;
1617
use PHPUnit\Framework\TestCase;
@@ -37,6 +38,7 @@ public function testUseNativeLazyObjectBeforePHP84(): void
3738
$c->setUseNativeLazyObject(true);
3839
}
3940

41+
#[IgnoreDeprecations]
4042
public function testUseLazyGhostObject(): void
4143
{
4244
$c = new Configuration();
@@ -74,6 +76,7 @@ public function testUseLazyGhostObjectWithSymfony8(): void
7476
$c->setUseLazyGhostObject(true);
7577
}
7678

79+
#[IgnoreDeprecations]
7780
public function testNativeLazyObjectDeprecatedByDefault(): void
7881
{
7982
$c = new Configuration();

tests/Tests/Functional/CustomTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testCustomTypeValueConversions(): void
4747

4848
$country = $this->dm->find(Country::class, $country->id);
4949

50-
self::assertContainsOnly('DateTime', $country->nationalHolidays);
50+
self::assertContainsOnlyInstancesOf(DateTime::class, $country->nationalHolidays);
5151
}
5252

5353
public function testConvertToDatabaseValueExpectsArray(): void

tests/Tests/Functional/ShardKeyTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ public function setUp(): void
3535

3636
public function tearDown(): void
3737
{
38-
$this->logger->unregister();
38+
if (isset($this->logger)) {
39+
$this->logger->unregister();
40+
}
3941

4042
parent::tearDown();
4143
}

tests/Tests/Functional/TargetDocumentTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
88
use Doctrine\ODM\MongoDB\Mapping\MappingException;
99
use Doctrine\ODM\MongoDB\Tests\BaseTestCase;
10+
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
1011
use stdClass;
1112

1213
class TargetDocumentTest extends BaseTestCase
1314
{
14-
/** @doesNotPerformAssertions */
15+
#[DoesNotPerformAssertions]
1516
public function testMappedSuperClassAsTargetDocument(): void
1617
{
1718
$test = new TargetDocumentTestDocument();

tests/Tests/Query/FilterCollectionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function testEnable(): void
2222

2323
$enabledFilters = $filterCollection->getEnabledFilters();
2424
self::assertCount(1, $enabledFilters);
25-
self::assertContainsOnly(BsonFilter::class, $enabledFilters);
25+
self::assertContainsOnlyInstancesOf(BsonFilter::class, $enabledFilters);
2626

2727
$filterCollection->disable('testFilter');
2828
self::assertEmpty($filterCollection->getEnabledFilters());

tests/Tests/QueryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ public function testFindWithHint(): void
508508
$collection->expects($this->once())
509509
->method('find')
510510
->with(['foo' => 'bar'], ['hint' => 'foo'])
511-
->will($this->returnValue($cursor));
511+
->willReturn($cursor);
512512

513513
// Using QueryBuilder->find adds hint to the query array
514514
$queryArray = [

0 commit comments

Comments
 (0)