Skip to content

Commit e67c780

Browse files
committed
Add a test without optional dependencies
1 parent 31620e3 commit e67c780

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ jobs:
9292
dependencies: "highest"
9393
symfony-version: "stable"
9494
proxy: "lazy-ghost"
95+
# Test removing optional dependencies
96+
- topology: "server"
97+
php-version: "8.4"
98+
mongodb-version: "8.0"
99+
driver-version: "stable"
100+
dependencies: "highest"
101+
symfony-version: "stable"
102+
proxy: "native"
103+
remove-optional-dependencies: true
95104
# Test with a sharded cluster
96105
# Currently disabled due to a bug where MongoDB reports "sharding status unknown"
97106
# - topology: "sharded_cluster"
@@ -148,6 +157,13 @@ jobs:
148157
composer require --no-update symfony/var-dumper:^${{ matrix.symfony-version }}
149158
composer require --no-update --dev symfony/cache:^${{ matrix.symfony-version }}
150159
160+
- name: "Remove optional dependencies"
161+
if: "${{ matrix.remove-optional-dependencies }}"
162+
run: |
163+
composer remove --no-update friendsofphp/proxy-manager-lts symfony/var-exporter
164+
composer remove --no-update --dev symfony/cache doctrine/orm doctrine/annotations symfony/uid
165+
composer remove --no-update --dev doctrine/coding-standard phpstan/phpstan phpstan/phpstan-deprecation-rule phpstan/phpstan-phpunit
166+
151167
- name: "Install dependencies with Composer"
152168
uses: "ramsey/composer-install@v3"
153169
with:

tests/Tests/BaseTestCase.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,13 @@ protected static function getConfiguration(): Configuration
105105
$config->setPersistentCollectionNamespace('PersistentCollections');
106106
$config->setDefaultDB(DOCTRINE_MONGODB_DATABASE);
107107
$config->setMetadataDriverImpl(static::createMetadataDriverImpl());
108-
$config->setUseLazyGhostObject((bool) $_ENV['USE_LAZY_GHOST_OBJECT']);
109-
$config->setUseNativeLazyObject((bool) $_ENV['USE_NATIVE_LAZY_OBJECT']);
108+
if ($_ENV['USE_LAZY_GHOST_OBJECT']) {
109+
$config->setUseLazyGhostObject(true);
110+
}
111+
112+
if ($_ENV['USE_NATIVE_LAZY_OBJECT']) {
113+
$config->setUseNativeLazyObject(true);
114+
}
110115

111116
if ($config->isNativeLazyObjectEnabled()) {
112117
NativeLazyObjectFactory::enableTracking();

tests/Tests/ConfigurationTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
use PHPUnit\Framework\Attributes\RequiresPhp;
1414
use PHPUnit\Framework\Attributes\TestWith;
1515
use PHPUnit\Framework\TestCase;
16+
use ProxyManager\Configuration as ProxyManagerConfiguration;
1617
use stdClass;
1718

1819
use function base64_encode;
20+
use function class_exists;
1921
use function str_repeat;
2022

2123
class ConfigurationTest extends TestCase
@@ -38,6 +40,12 @@ public function testUseLazyGhostObject(): void
3840
self::assertFalse($c->isLazyGhostObjectEnabled());
3941
$c->setUseLazyGhostObject(true);
4042
self::assertTrue($c->isLazyGhostObjectEnabled());
43+
44+
if (! class_exists(ProxyManagerConfiguration::class)) {
45+
$this->expectException(LogicException::class);
46+
$this->expectExceptionMessage('Package "friendsofphp/proxy-manager-lts" is required to disable LazyGhostObject.');
47+
}
48+
4149
$c->setUseLazyGhostObject(false);
4250
self::assertFalse($c->isLazyGhostObjectEnabled());
4351
}

tests/Tests/Mapping/AnnotationDriverTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
namespace Doctrine\ODM\MongoDB\Tests\Mapping;
66

7+
use Doctrine\Common\Annotations\AnnotationReader;
78
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
89
use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
910
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
1011
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
1112
use Doctrine\Persistence\Mapping\Driver\FileClassLocator;
1213
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
14+
use PHPUnit\Framework\Attributes\RequiresMethod;
1315

1416
use function call_user_func;
1517
use function class_exists;
@@ -19,6 +21,7 @@
1921

2022
use const E_USER_DEPRECATED;
2123

24+
#[RequiresMethod(AnnotationReader::class, '__construct')]
2225
class AnnotationDriverTest extends AbstractAnnotationDriverTestCase
2326
{
2427
protected static function loadDriver(array $paths = []): MappingDriver

tests/Tests/Types/BinaryUuidTypeTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
use Doctrine\ODM\MongoDB\Types\Type;
88
use InvalidArgumentException;
99
use MongoDB\BSON\Binary;
10+
use PHPUnit\Framework\Attributes\RequiresMethod;
1011
use PHPUnit\Framework\TestCase;
1112
use Symfony\Component\Uid\UuidV4;
1213
use Throwable;
1314

15+
#[RequiresMethod(UuidV4::class, '__construct')]
1416
class BinaryUuidTypeTest extends TestCase
1517
{
1618
public function testConvertToDatabaseValue(): void

0 commit comments

Comments
 (0)