Skip to content

Commit

Permalink
Merge branch 'main' into feature/add-tests-for-php83
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris53897 authored Nov 27, 2023
2 parents 2dbdcde + 922e6b2 commit 47ad0a0
Show file tree
Hide file tree
Showing 44 changed files with 272 additions and 442 deletions.
14 changes: 1 addition & 13 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env:

jobs:
phpunit:
name: "PHPUnit ${{ matrix.php-version }} (${{ matrix.deps }})${{ matrix.dbal-version && format(' - DBAL {0}', matrix.dbal-version) || '' }}"
name: "PHPUnit ${{ matrix.php-version }} (${{ matrix.deps }})"
runs-on: "ubuntu-20.04"

services:
Expand All @@ -30,17 +30,9 @@ jobs:
- "8.3"
deps:
- "highest"
dbal-version:
- ""
include:
- deps: "lowest"
php-version: "7.4"
- deps: "highest"
php-version: "8.3"
dbal-version: "^2.13.1"
- deps: "highest"
php-version: "8.3"
dbal-version: "^3.2"
- deps: "highest"
php-version: "8.1"

Expand All @@ -57,10 +49,6 @@ jobs:
extensions: mongodb
coverage: "pcov"

- name: "Restrict DBAL version"
if: "${{ matrix.dbal-version }}"
run: "composer require --dev --no-update doctrine/dbal:${{ matrix.dbal-version }}"

# Remove PHP-CS-Fixer to avoid conflicting dependency ranges (i.e. doctrine/annotations)
- name: "Remove PHP-CS-Fixer"
run: "composer remove --dev --no-update friendsofphp/php-cs-fixer"
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ a release.
---

## [Unreleased]
### Added
- Tree: Added `@template` and `@template-extends` annotations to the Tree repositories

### Changed
- Dropped support for PHP < 7.4
- Dropped support for Symfony < 5.4
- Dropped support for doctrine/dbal < 3.2

### Deprecated
- Calling `Gedmo\Mapping\Event\Adapter\ORM::getObjectManager()` and `getObject()` on EventArgs that do not implement `getObjectManager()` and `getObject()` (such as old EventArgs implementing `getEntityManager()` and `getEntity()`)
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
},
"require-dev": {
"doctrine/cache": "^1.11 || ^2.0",
"doctrine/dbal": "^2.13.1 || ^3.2",
"doctrine/dbal": "^3.2",
"doctrine/doctrine-bundle": "^2.3",
"doctrine/mongodb-odm": "^2.3",
"doctrine/orm": "^2.14.0",
Expand All @@ -69,7 +69,7 @@
"symfony/yaml": "^5.4 || ^6.0"
},
"conflict": {
"doctrine/dbal": "<2.13.1 || ^3.0 <3.2",
"doctrine/dbal": "<3.2",
"doctrine/mongodb-odm": "<2.3",
"doctrine/orm": "<2.14.0 || 2.16.0 || 2.16.1",
"sebastian/comparator": "<2.0"
Expand Down
4 changes: 4 additions & 0 deletions example/app/Entity/Repository/CategoryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@

namespace App\Entity\Repository;

use App\Entity\Category;
use Gedmo\Tree\Entity\Repository\NestedTreeRepository;

/**
* @template-extends NestedTreeRepository<Category>
*/
final class CategoryRepository extends NestedTreeRepository
{
}
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ parameters:
path: tests/Gedmo/Timestampable/Fixture/ArticleCarbon.php

-
message: "#^Property Gedmo\\\\Tests\\\\Tree\\\\MaterializedPathODMMongoDBRepositoryTest\\:\\:\\$repo \\(Gedmo\\\\Tree\\\\Document\\\\MongoDB\\\\Repository\\\\MaterializedPathRepository\\) does not accept Doctrine\\\\ORM\\\\EntityRepository\\<Gedmo\\\\Tests\\\\Tree\\\\Fixture\\\\Document\\\\Category\\>\\.$#"
message: "#^Property Gedmo\\\\Tests\\\\Tree\\\\MaterializedPathODMMongoDBRepositoryTest\\:\\:\\$repo \\(Gedmo\\\\Tree\\\\Document\\\\MongoDB\\\\Repository\\\\MaterializedPathRepository\\<Gedmo\\\\Tests\\\\Tree\\\\Fixture\\\\Document\\\\Category\\>\\) does not accept Doctrine\\\\ORM\\\\EntityRepository\\<Gedmo\\\\Tests\\\\Tree\\\\Fixture\\\\Document\\\\Category\\>\\.$#"
count: 1
path: tests/Gedmo/Tree/MaterializedPathODMMongoDBRepositoryTest.php

Expand Down
7 changes: 4 additions & 3 deletions src/Mapping/ExtensionMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
use Doctrine\Bundle\DoctrineBundle\Mapping\MappingDriver as DoctrineBundleMappingDriver;
use Doctrine\Common\Annotations\Reader;
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata as DocumentClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataInfo as EntityClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadata as EntityClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataInfo as LegacyEntityClassMetadata;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\Mapping\Driver\DefaultFileLocator;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
Expand Down Expand Up @@ -95,7 +96,7 @@ public function __construct(ObjectManager $objectManager, string $extensionNames
/**
* Reads extension metadata
*
* @param ClassMetadata&(DocumentClassMetadata|EntityClassMetadata) $meta
* @param ClassMetadata&(DocumentClassMetadata|EntityClassMetadata|LegacyEntityClassMetadata) $meta
*
* @return array<string, mixed> the metatada configuration
*/
Expand All @@ -116,7 +117,7 @@ public function getExtensionMetadata($meta)

$class = $this->objectManager->getClassMetadata($parentClass);

assert($class instanceof DocumentClassMetadata || $class instanceof EntityClassMetadata);
assert($class instanceof DocumentClassMetadata || $class instanceof EntityClassMetadata || $class instanceof LegacyEntityClassMetadata);

$extendedMetadata = $this->driver->readExtendedMetadata($class, $config);

Expand Down
5 changes: 3 additions & 2 deletions src/Mapping/MappedEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata as DocumentClassMetadata;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadataInfo as EntityClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadata as EntityClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataInfo as LegacyEntityClassMetadata;
use Doctrine\Persistence\Mapping\AbstractClassMetadataFactory;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\ObjectManager;
Expand Down Expand Up @@ -229,7 +230,7 @@ final public function setCacheItemPool(CacheItemPoolInterface $cacheItemPool): v
*/
public function loadMetadataForObjectClass(ObjectManager $objectManager, $metadata)
{
assert($metadata instanceof DocumentClassMetadata || $metadata instanceof EntityClassMetadata);
assert($metadata instanceof DocumentClassMetadata || $metadata instanceof EntityClassMetadata || $metadata instanceof LegacyEntityClassMetadata);

$factory = $this->getExtensionMetadataFactory($objectManager);

Expand Down
4 changes: 2 additions & 2 deletions src/References/Mapping/Event/Adapter/ODM.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Proxy\Proxy as ORMProxy;
use Doctrine\Persistence\Proxy as PersistenceProxy;
use Gedmo\Mapping\Event\Adapter\ODM as BaseAdapterODM;
use Gedmo\References\Mapping\Event\ReferencesAdapter;
use ProxyManager\Proxy\GhostObjectInterface;
Expand All @@ -32,7 +32,7 @@ public function getIdentifier($om, $object, $single = true)
}

if ($om instanceof EntityManagerInterface) {
if ($object instanceof ORMProxy) {
if ($object instanceof PersistenceProxy) {
$id = $om->getUnitOfWork()->getEntityIdentifier($object);
} else {
$meta = $om->getClassMetadata(get_class($object));
Expand Down
4 changes: 2 additions & 2 deletions src/References/Mapping/Event/Adapter/ORM.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Doctrine\ODM\MongoDB\DocumentManager as MongoDocumentManager;
use Doctrine\ODM\PHPCR\DocumentManager as PhpcrDocumentManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Proxy\Proxy as ORMProxy;
use Doctrine\Persistence\Proxy as PersistenceProxy;
use Gedmo\Exception\InvalidArgumentException;
use Gedmo\Mapping\Event\Adapter\ORM as BaseAdapterORM;
use Gedmo\References\Mapping\Event\ReferencesAdapter;
Expand Down Expand Up @@ -79,7 +79,7 @@ public function getSingleReference($om, $class, $identifier)

public function extractIdentifier($om, $object, $single = true)
{
if ($object instanceof ORMProxy) {
if ($object instanceof PersistenceProxy) {
$id = $om->getUnitOfWork()->getEntityIdentifier($object);
} else {
$meta = $om->getClassMetadata(get_class($object));
Expand Down
1 change: 0 additions & 1 deletion src/Tool/Wrapper/EntityWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Doctrine\Common\Util\ClassUtils;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Proxy\Proxy;
use Doctrine\Persistence\Proxy as PersistenceProxy;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
use Gedmo\Tree\TreeListener;

/**
* @phpstan-extends DocumentRepository<object>
* @template T of object
*
* @phpstan-extends DocumentRepository<T>
*
* @phpstan-implements RepositoryInterface<T>
*/
abstract class AbstractTreeRepository extends DocumentRepository implements RepositoryInterface
{
Expand All @@ -40,6 +44,7 @@ abstract class AbstractTreeRepository extends DocumentRepository implements Repo
*/
protected $repoUtils;

/** @param ClassMetadata<T> $class */
public function __construct(DocumentManager $em, UnitOfWork $uow, ClassMetadata $class)
{
parent::__construct($em, $uow, $class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
*
* @author Gustavo Falco <comfortablynumb84@gmail.com>
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
*
* @template T of object
*
* @template-extends AbstractTreeRepository<T>
*/
class MaterializedPathRepository extends AbstractTreeRepository
{
Expand Down
7 changes: 6 additions & 1 deletion src/Tree/Entity/Repository/AbstractTreeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
use Gedmo\Tree\TreeListener;

/**
* @phpstan-extends EntityRepository<object>
* @template T of object
*
* @template-extends EntityRepository<T>
*
* @template-implements RepositoryInterface<T>
*/
abstract class AbstractTreeRepository extends EntityRepository implements RepositoryInterface
{
Expand All @@ -41,6 +45,7 @@ abstract class AbstractTreeRepository extends EntityRepository implements Reposi
*/
protected $repoUtils;

/** @param ClassMetadata<T> $class */
public function __construct(EntityManagerInterface $em, ClassMetadata $class)
{
parent::__construct($em, $class);
Expand Down
4 changes: 4 additions & 0 deletions src/Tree/Entity/Repository/ClosureTreeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
*
* @author Gustavo Adrian <comfortablynumb84@gmail.com>
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
*
* @template T of object
*
* @template-extends AbstractTreeRepository<T>
*/
class ClosureTreeRepository extends AbstractTreeRepository
{
Expand Down
4 changes: 4 additions & 0 deletions src/Tree/Entity/Repository/MaterializedPathRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
*
* @author Gustavo Falco <comfortablynumb84@gmail.com>
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
*
* @template T of object
*
* @template-extends AbstractTreeRepository<T>
*/
class MaterializedPathRepository extends AbstractTreeRepository
{
Expand Down
6 changes: 5 additions & 1 deletion src/Tree/Entity/Repository/NestedTreeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
namespace Gedmo\Tree\Entity\Repository;

use Doctrine\ORM\Exception\ORMException;
use Doctrine\ORM\Proxy\Proxy;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\Proxy;
use Gedmo\Exception\InvalidArgumentException;
use Gedmo\Exception\RuntimeException;
use Gedmo\Exception\UnexpectedValueException;
Expand All @@ -28,6 +28,10 @@
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
*
* @template T of object
*
* @template-extends AbstractTreeRepository<T>
*
* @method persistAsFirstChild($node)
* @method persistAsFirstChildOf($node, $parent)
* @method persistAsLastChild($node)
Expand Down
11 changes: 11 additions & 0 deletions src/Tree/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
* @author Gustavo Falco <comfortablynumb84@gmail.com>
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
*
* @template T of object
*/
interface RepositoryInterface extends RepositoryUtilsInterface
{
Expand All @@ -26,6 +28,8 @@ interface RepositoryInterface extends RepositoryUtilsInterface
* @param string $direction
*
* @return iterable<int|string, object>
*
* @phpstan-return iterable<int|string, T>
*/
public function getRootNodes($sortByField = null, $direction = 'asc');

Expand All @@ -38,6 +42,10 @@ public function getRootNodes($sortByField = null, $direction = 'asc');
* @param bool $includeNode Flag indicating whether the given node should be included in the results
*
* @return array<int|string, object>
*
* @phpstan-param T $node
*
* @phpstan-return iterable<int|string, T>
*/
public function getNodesHierarchy($node = null, $direct = false, array $options = [], $includeNode = false);

Expand All @@ -53,6 +61,9 @@ public function getNodesHierarchy($node = null, $direct = false, array $options
* @return iterable<int|string, object> List of children
*
* @phpstan-param 'asc'|'desc'|'ASC'|'DESC'|array<int, 'asc'|'desc'|'ASC'|'DESC'> $direction
* @phpstan-param T|null $node
*
* @phpstan-return iterable<int|string, T>
*/
public function getChildren($node = null, $direct = false, $sortByField = null, $direction = 'ASC', $includeNode = false);

Expand Down
11 changes: 7 additions & 4 deletions src/Tree/RepositoryUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@

/**
* @final since gedmo/doctrine-extensions 3.11
*
* @template T of object
*/
class RepositoryUtils implements RepositoryUtilsInterface
{
/** @var ClassMetadata */
/** @var ClassMetadata<T> */
protected $meta;

/** @var TreeListener */
Expand All @@ -31,7 +33,7 @@ class RepositoryUtils implements RepositoryUtilsInterface
/** @var ObjectManager&(DocumentManager|EntityManagerInterface) */
protected $om;

/** @var RepositoryInterface */
/** @var RepositoryInterface<T> */
protected $repo;

/**
Expand All @@ -44,8 +46,9 @@ class RepositoryUtils implements RepositoryUtilsInterface

/**
* @param ObjectManager&(DocumentManager|EntityManagerInterface) $om
* @param ClassMetadata<T> $meta
* @param TreeListener $listener
* @param RepositoryInterface $repo
* @param RepositoryInterface<T> $repo
*/
public function __construct(ObjectManager $om, ClassMetadata $meta, $listener, $repo)
{
Expand All @@ -56,7 +59,7 @@ public function __construct(ObjectManager $om, ClassMetadata $meta, $listener, $
}

/**
* @return ClassMetadata
* @return ClassMetadata<T>
*/
public function getClassMetadata()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Tree/Strategy/ORM/Nested.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Proxy\Proxy;
use Doctrine\Persistence\Proxy;
use Gedmo\Exception\InvalidArgumentException;
use Gedmo\Exception\UnexpectedValueException;
use Gedmo\Mapping\Event\AdapterInterface;
Expand Down
6 changes: 3 additions & 3 deletions tests/Gedmo/Blameable/Fixture/Document/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ class Article
private ?string $title = null;

/**
* @ODM\ReferenceOne(targetDocument="Type")
* @ODM\ReferenceOne(targetDocument="Gedmo\Tests\Blameable\Fixture\Document\Type")
*/
#[Odm\ReferenceOne(targetDocument: Type::class)]
private ?\Gedmo\Tests\Blameable\Fixture\Document\Type $type = null;
private ?Type $type = null;

/**
* @ODM\Field(type="string")
Expand All @@ -60,7 +60,7 @@ class Article
private ?string $updated = null;

/**
* @ODM\ReferenceOne(targetDocument="User")
* @ODM\ReferenceOne(targetDocument="Gedmo\Tests\Blameable\Fixture\Document\User")
*
* @Gedmo\Blameable(on="create")
*/
Expand Down
Loading

0 comments on commit 47ad0a0

Please sign in to comment.