Skip to content

Commit

Permalink
Merge pull request #2556 from malarzm/require-php-8-1
Browse files Browse the repository at this point in the history
Require PHP 8.1
  • Loading branch information
malarzm authored Oct 24, 2023
2 parents d3c8966 + 10b2ea7 commit df768ee
Show file tree
Hide file tree
Showing 17 changed files with 25 additions and 65 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
strategy:
matrix:
php-version:
- "8.0"
- "8.1"
- "8.2"
mongodb-version:
Expand All @@ -32,7 +31,7 @@ jobs:
- "highest"
include:
- dependencies: "lowest"
php-version: "8.0"
php-version: "8.1"
mongodb-version: "4.4"
driver-version: "1.11.0"
topology: "server"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
php-version:
- "8.0"
- "8.1"

services:
mongodb:
Expand Down
4 changes: 2 additions & 2 deletions UPGRADE-2.6.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

## PHP requirements

* MongoDB ODM 2.6 requires PHP 8.0 or newer. If you're not running PHP 8.0 yet,
it's recommended that you upgrade to PHP 8.0 before upgrading ODM.
* MongoDB ODM 2.6 requires PHP 8.1 or newer. If you're not running PHP 8.1 yet,
it's recommended that you upgrade to PHP 8.1 before upgrading ODM.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
{ "name": "Fran Moreno", "email": "franmomu@gmail.com" }
],
"require": {
"php": "^8.0",
"php": "^8.1",
"ext-mongodb": "^1.11",
"doctrine/annotations": "^1.12 || ^2.0",
"doctrine/cache": "^1.11 || ^2.0",
Expand Down
4 changes: 0 additions & 4 deletions lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -2377,10 +2377,6 @@ public function mapField(array $mapping): array
assert($reflProp instanceof ReflectionProperty);

if (isset($mapping['enumType'])) {
if (PHP_VERSION_ID < 80100) {
throw MappingException::enumsRequirePhp81($this->name, $mapping['fieldName']);
}

if (! enum_exists($mapping['enumType'])) {
throw MappingException::nonEnumTypeMapped($this->name, $mapping['fieldName'], $mapping['enumType']);
}
Expand Down
20 changes: 0 additions & 20 deletions lib/Doctrine/ODM/MongoDB/Mapping/MappingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ public static function mappingNotFoundByDbName(string $className, string $dbFiel
return new self(sprintf("No mapping found for field by DB name '%s' in class '%s'.", $dbFieldName, $className));
}

public static function duplicateFieldMapping(string $document, string $fieldName): self
{
return new self(sprintf('Property "%s" in "%s" was already declared, but it must be declared only once', $fieldName, $document));
}

public static function duplicateDatabaseFieldName(string $document, string $offendingFieldName, string $databaseName, string $originalFieldName): self
{
return new self(sprintf('Field "%s" in class "%s" is mapped to field "%s" in the database, but that name is already in use by field "%s".', $offendingFieldName, $document, $databaseName, $originalFieldName));
Expand Down Expand Up @@ -117,11 +112,6 @@ public static function identifierRequired(string $documentName): self
return new self(sprintf("No identifier/primary key specified for Document '%s'. Every Document must have an identifier/primary key.", $documentName));
}

public static function missingIdentifierField(string $className, string $fieldName): self
{
return new self(sprintf('The identifier %s is missing for a query of %s', $fieldName, $className));
}

public static function missingIdGeneratorClass(string $className): self
{
return new self(sprintf('The class-option for the custom ID generator is missing in class %s.', $className));
Expand Down Expand Up @@ -217,11 +207,6 @@ public static function cannotUseShardedCollectionInOutStage(string $className):
return new self(sprintf("Cannot use class '%s' as collection for out stage. Sharded collections are not allowed.", $className));
}

public static function cannotUseShardedCollectionInLookupStages(string $className): self
{
return new self(sprintf("Cannot use class '%s' as collection for lookup or graphLookup stage. Sharded collections are not allowed.", $className));
}

public static function referencePrimersOnlySupportedForInverseReferenceMany(string $className, string $fieldName): self
{
return new self(sprintf("Cannot use reference priming on '%s' in class '%s'. Reference priming is only supported for inverse references", $fieldName, $className));
Expand Down Expand Up @@ -277,11 +262,6 @@ public static function schemaValidationError(int $errorCode, string $errorMessag
return new self(sprintf('The following schema validation error occurred while parsing the "%s" property of the "%s" class: "%s" (code %s).', $property, $className, $errorMessage, $errorCode));
}

public static function enumsRequirePhp81(string $className, string $fieldName): self
{
return new self(sprintf('Enum types require PHP 8.1 in %s::%s', $className, $fieldName));
}

public static function nonEnumTypeMapped(string $className, string $fieldName, string $enumType): self
{
return new self(sprintf(
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<!-- Ignore warnings and show progress of the run -->
<arg value="np"/>

<config name="php_version" value="80000"/>
<config name="php_version" value="80100"/>

<file>benchmark</file>
<file>lib</file>
Expand Down
4 changes: 2 additions & 2 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -981,12 +981,12 @@ parameters:
path: tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataLoadEventTest.php

-
message: "#^Parameter \\#1 \\$mapping of method Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\ClassMetadata\\<class@anonymous/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest\\.php\\:234\\>\\:\\:mapField\\(\\) expects array\\{type\\?\\: string, fieldName\\?\\: string, name\\?\\: string, strategy\\?\\: string, association\\?\\: int, id\\?\\: bool, isOwningSide\\?\\: bool, collectionClass\\?\\: class\\-string, \\.\\.\\.\\}, array\\{fieldName\\: 'enum', enumType\\: 'Documents81\\\\\\\\Card'\\} given\\.$#"
message: "#^Parameter \\#1 \\$mapping of method Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\ClassMetadata\\<class@anonymous/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest\\.php\\:230\\>\\:\\:mapField\\(\\) expects array\\{type\\?\\: string, fieldName\\?\\: string, name\\?\\: string, strategy\\?\\: string, association\\?\\: int, id\\?\\: bool, isOwningSide\\?\\: bool, collectionClass\\?\\: class\\-string, \\.\\.\\.\\}, array\\{fieldName\\: 'enum', enumType\\: 'Documents\\\\\\\\Card'\\} given\\.$#"
count: 1
path: tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php

-
message: "#^Parameter \\#1 \\$mapping of method Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\ClassMetadata\\<class@anonymous/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest\\.php\\:254\\>\\:\\:mapField\\(\\) expects array\\{type\\?\\: string, fieldName\\?\\: string, name\\?\\: string, strategy\\?\\: string, association\\?\\: int, id\\?\\: bool, isOwningSide\\?\\: bool, collectionClass\\?\\: class\\-string, \\.\\.\\.\\}, array\\{fieldName\\: 'enum', enumType\\: 'Documents81\\\\\\\\SuitNonBacked'\\} given\\.$#"
message: "#^Parameter \\#1 \\$mapping of method Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\ClassMetadata\\<class@anonymous/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest\\.php\\:249\\>\\:\\:mapField\\(\\) expects array\\{type\\?\\: string, fieldName\\?\\: string, name\\?\\: string, strategy\\?\\: string, association\\?\\: int, id\\?\\: bool, isOwningSide\\?\\: bool, collectionClass\\?\\: class\\-string, \\.\\.\\.\\}, array\\{fieldName\\: 'enum', enumType\\: 'Documents\\\\\\\\SuitNonBacked'\\} given\\.$#"
count: 1
path: tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php

Expand Down
12 changes: 2 additions & 10 deletions tests/Doctrine/ODM/MongoDB/Tests/Functional/EnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

namespace Doctrine\ODM\MongoDB\Tests\Functional;

use Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver;
use Doctrine\ODM\MongoDB\Tests\BaseTestCase;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use Documents81\Card;
use Documents81\Suit;
use Documents\Card;
use Documents\Suit;
use Error;
use Jean85\PrettyVersions;
use MongoDB\BSON\ObjectId;
Expand All @@ -18,7 +16,6 @@
use function sprintf;
use function version_compare;

/** @requires PHP >= 8.1 */
class EnumTest extends BaseTestCase
{
public function testPersistNew(): void
Expand Down Expand Up @@ -116,9 +113,4 @@ public function testQueryWithMappedNonEnumFieldIsPassedToTypeDirectly(): void

self::assertSame(['_id' => 'C'], $qb->getQuery()->debug('query'));
}

protected static function createMetadataDriverImpl(): MappingDriver
{
return AttributeDriver::create(__DIR__ . '/../../../Documents');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
use Doctrine\ODM\MongoDB\Types\Type;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Persistence\Reflection\EnumReflectionProperty;
use Documents\Card;
use Documents\CustomCollection;
use Documents\Suit;
use Documents\UserTyped;
use Documents81\Card;
use Documents81\Suit;
use InvalidArgumentException;

use function key;
Expand Down Expand Up @@ -632,7 +632,6 @@ public function testView(): void
], $metadata->fieldMappings['name']);
}

/** @requires PHP >= 8.1 */
public function testEnumType(): void
{
$metadata = $this->dm->getClassMetadata(Card::class);
Expand Down
19 changes: 7 additions & 12 deletions tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
use Documents\Address;
use Documents\Album;
use Documents\Bars\Bar;
use Documents\Card;
use Documents\CmsGroup;
use Documents\CmsUser;
use Documents\CustomCollection;
use Documents\CustomRepository\Repository;
use Documents\SpecialUser;
use Documents\Suit;
use Documents\SuitInt;
use Documents\SuitNonBacked;
use Documents\User;
use Documents\UserName;
use Documents\UserRepository;
use Documents\UserTyped;
use Documents81\Card;
use Documents81\Suit;
use Documents81\SuitInt;
use Documents81\SuitNonBacked;
use Generator;
use InvalidArgumentException;
use ProxyManager\Proxy\GhostObjectInterface;
Expand Down Expand Up @@ -181,7 +181,6 @@ public function testFieldTypeFromReflection(): void
self::assertEquals(CustomCollection::class, $cm->getAssociationCollectionClass('referenceMany'));
}

/** @requires PHP >= 8.1 */
public function testEnumTypeFromReflection(): void
{
$cm = new ClassMetadata(Card::class);
Expand All @@ -202,7 +201,6 @@ public function testEnumTypeFromReflection(): void
self::assertFalse($cm->isNullable('nullableSuit'));
}

/** @requires PHP >= 8.1 */
public function testEnumReflectionPropertySerialization(): void
{
$cm = new ClassMetadata(Card::class);
Expand All @@ -216,19 +214,17 @@ public function testEnumReflectionPropertySerialization(): void
self::assertInstanceOf(EnumReflectionProperty::class, $cm->reflFields['suit']);
}

/** @requires PHP >= 8.1 */
public function testEnumTypeFromReflectionMustBeBacked(): void
{
$cm = new ClassMetadata(Card::class);

$this->expectException(MappingException::class);
$this->expectExceptionMessage(
'Attempting to map a non-backed enum Documents81\SuitNonBacked: Documents81\Card::suitNonBacked',
'Attempting to map a non-backed enum Documents\SuitNonBacked: Documents\Card::suitNonBacked',
);
$cm->mapField(['fieldName' => 'suitNonBacked']);
}

/** @requires PHP >= 8.1 */
public function testEnumTypeMustPointToAnEnum(): void
{
$object = new class {
Expand All @@ -240,15 +236,14 @@ public function testEnumTypeMustPointToAnEnum(): void

$this->expectException(MappingException::class);
$this->expectExceptionMessage(
'Attempting to map a non-enum type Documents81\Card as an enum: ',
'Attempting to map a non-enum type Documents\Card as an enum: ',
);
$cm->mapField([
'fieldName' => 'enum',
'enumType' => Card::class,
]);
}

/** @requires PHP >= 8.1 */
public function testEnumTypeMustPointToABackedEnum(): void
{
$object = new class {
Expand All @@ -260,7 +255,7 @@ public function testEnumTypeMustPointToABackedEnum(): void

$this->expectException(MappingException::class);
$this->expectExceptionMessage(
'Attempting to map a non-backed enum Documents81\SuitNonBacked: ',
'Attempting to map a non-backed enum Documents\SuitNonBacked: ',
);
$cm->mapField([
'fieldName' => 'enum',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping
http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd"
>
<document name="Documents81\Card">
<document name="Documents\Card">
<id />
<field name="suit" />
<field name="nullableSuit" type="string" enum-type="Documents81\Suit" nullable="true" />
<field name="nullableSuit" type="string" enum-type="Documents\Suit" nullable="true" />
</document>
</doctrine-mongo-mapping>
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public function testPHP80Types(): void
self::assertInstanceOf(CollWithPHP80Types::class, $coll);
}

/** @requires PHP >= 8.1 */
public function testPHP81Types(): void
{
$class = $this->generator->loadClass(CollWithPHP81Types::class, Configuration::AUTOGENERATE_EVAL);
Expand Down
2 changes: 1 addition & 1 deletion tests/Documents81/Card.php → tests/Documents/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Documents81;
namespace Documents;

use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

Expand Down
2 changes: 1 addition & 1 deletion tests/Documents81/Suit.php → tests/Documents/Suit.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Documents81;
namespace Documents;

enum Suit: string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Documents81;
namespace Documents;

enum SuitInt: int
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Documents81;
namespace Documents;

enum SuitNonBacked
{
Expand Down

0 comments on commit df768ee

Please sign in to comment.