Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge release 2.2.1 into 2.3.x #186

Merged
merged 6 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions .doctrine-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,27 @@
"upcoming": true
},
{
"name": "2.2",
"branchName": "2.2.x",
"slug": "2.2",
"name": "2.3",
"branchName": "2.3.x",
"slug": "2.3",
"upcoming": true
},
{
"name": "2.1",
"branchName": "2.1.x",
"slug": "2.1",
"name": "2.2",
"branchName": "2.2.x",
"slug": "2.2",
"current": true,
"aliases": [
"current",
"stable"
]
},
{
"name": "2.1",
"branchName": "2.1.x",
"slug": "2.1",
"maintained": false
},
{
"name": "2.0",
"branchName": "2.0.x",
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"doctrine/cache": "^1.11 || ^2.0",
"doctrine/collections": "^1.0",
"doctrine/event-manager": "^1.0",
"psr/cache": "^1.0|^2.0|^3.0"
"psr/cache": "^1.0|^2.0|^3.0",
"doctrine/deprecations": "^0.5.3"
},
"require-dev": {
"composer/package-versions-deprecated": "^1.11",
Expand Down
25 changes: 13 additions & 12 deletions lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

namespace Doctrine\Persistence\Mapping;

use BadMethodCallException;
use Doctrine\Common\Cache\Cache;
use Doctrine\Common\Cache\CacheProvider;
use Doctrine\Common\Cache\Psr6\CacheAdapter;
use Doctrine\Common\Cache\Psr6\DoctrineProvider;
use Doctrine\Deprecations\Deprecation;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Persistence\Proxy;
use Psr\Cache\CacheItemPoolInterface;
Expand All @@ -20,14 +19,10 @@
use function assert;
use function explode;
use function is_array;
use function sprintf;
use function str_replace;
use function strpos;
use function strrpos;
use function substr;
use function trigger_error;

use const E_USER_DEPRECATED;

/**
* The ClassMetadataFactory is used to create ClassMetadata objects that contain all the
Expand Down Expand Up @@ -78,7 +73,12 @@ abstract class AbstractClassMetadataFactory implements ClassMetadataFactory
*/
public function setCacheDriver(?Cache $cacheDriver = null)
{
@trigger_error(sprintf('%s is deprecated. Use setCache() with a PSR-6 cache instead.', __METHOD__), E_USER_DEPRECATED);
Deprecation::trigger(
'doctrine/persistence',
'https://github.com/doctrine/persistence/issues/184',
'%s is deprecated. Use setCache() with a PSR-6 cache instead.',
__METHOD__
);

$this->cacheDriver = $cacheDriver;

Expand All @@ -88,10 +88,6 @@ public function setCacheDriver(?Cache $cacheDriver = null)
return;
}

if (! $cacheDriver instanceof CacheProvider) {
throw new BadMethodCallException('Cannot convert cache to PSR-6 cache');
}

$this->cache = CacheAdapter::wrap($cacheDriver);
}

Expand All @@ -104,7 +100,12 @@ public function setCacheDriver(?Cache $cacheDriver = null)
*/
public function getCacheDriver()
{
@trigger_error(sprintf('%s is deprecated. Use getCache() instead.', __METHOD__), E_USER_DEPRECATED);
Deprecation::trigger(
'doctrine/persistence',
'https://github.com/doctrine/persistence/issues/184',
'%s is deprecated. Use getCache() instead.',
__METHOD__
);

return $this->cacheDriver;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ abstract class AnnotationDriver implements MappingDriver
* Cache for AnnotationDriver#getAllClassNames().
*
* @var string[]|null
* @psalm-var list<class-string>|null
*/
protected $classNames;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ public function getAllClassNames($globalBasename)
}

// NOTE: All files found here means classes are not transient!
$classes[] = str_replace('.', '\\', $fileName);
/** @psalm-var class-string */
$class = str_replace('.', '\\', $fileName);
$classes[] = $class;
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions lib/Doctrine/Persistence/Mapping/Driver/FileDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use function array_keys;
use function array_merge;
use function array_unique;
use function array_values;
use function is_file;
use function str_replace;

Expand All @@ -26,7 +27,7 @@ abstract class FileDriver implements MappingDriver

/**
* @var ClassMetadata[]|null
* @psalm-var ClassMetadata<object>[]|null
* @psalm-var array<class-string, ClassMetadata<object>>|null
*/
protected $classCache;

Expand Down Expand Up @@ -77,6 +78,7 @@ public function getGlobalBasename()
* This will lazily load the mapping file if it is not loaded yet.
*
* @param string $className
* @psalm-param class-string $className
*
* @return ClassMetadata The element of schema meta data.
* @psalm-return ClassMetadata<object>
Expand Down Expand Up @@ -132,10 +134,10 @@ public function getAllClassNames()
return (array) $this->locator->getAllClassNames($this->globalBasename);
}

return array_unique(array_merge(
return array_values(array_unique(array_merge(
array_keys($this->classCache),
(array) $this->locator->getAllClassNames($this->globalBasename)
));
)));
}

/**
Expand Down
1 change: 1 addition & 0 deletions lib/Doctrine/Persistence/Mapping/Driver/FileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function findMappingFile($className);
* @param string|null $globalBasename Passed to allow excluding the basename.
*
* @return string[]
* @psalm-return list<class-string>
*/
public function getAllClassNames($globalBasename);

Expand Down
6 changes: 5 additions & 1 deletion lib/Doctrine/Persistence/Mapping/Driver/MappingDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,20 @@ interface MappingDriver
* Loads the metadata for the specified class into the provided container.
*
* @param string $className
* @psalm-param ClassMetadata<object> $metadata
* @psalm-param class-string<T> $className
* @psalm-param ClassMetadata<T> $metadata
*
* @return void
*
* @template T of object
*/
public function loadMetadataForClass($className, ClassMetadata $metadata);

/**
* Gets the names of all mapped classes known to this driver.
*
* @return string[] The names of all mapped classes known to this driver.
* @psalm-return list<class-string>
*/
public function getAllClassNames();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class StaticPHPDriver implements MappingDriver
* Map of all class names.
*
* @var string[]
* @psalm-var list<class-string>
*/
private $classNames;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,14 @@ public function getAllClassNames($globalBasename = null)
'\\'
);

$classes[] = $this->prefixes[$path] . str_replace(DIRECTORY_SEPARATOR, '\\', $nsSuffix) . '\\' . str_replace($this->nsSeparator, '\\', $fileName);
/** @psalm-var class-string */
$class = $this->prefixes[$path] . str_replace(DIRECTORY_SEPARATOR, '\\', $nsSuffix) . '\\' . str_replace($this->nsSeparator, '\\', $fileName);
} else {
$classes[] = str_replace($this->nsSeparator, '\\', $fileName);
/** @psalm-var class-string */
$class = str_replace($this->nsSeparator, '\\', $fileName);
}

$classes[] = $class;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/Persistence/ObjectManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface ObjectManager
* @return object|null The found object.
* @psalm-return T|null
*
* @template T
* @template T of object
*/
public function find($className, $id);

Expand Down
4 changes: 4 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ parameters:
-
message: '#Method Doctrine\\Tests\\Persistence\\Mapping\\TestClassMetadataFactory\:\:getFqcnFromAlias\(\) should return class\-string but returns string\.#'
path: 'tests/Doctrine/Tests/Persistence/Mapping/TestClassMetadataFactory.php'
# https://github.com/phpstan/phpstan/issues/1267
-
message: "#^Call to an undefined static method T of object\\:\\:loadMetadata\\(\\)\\.$#"
path: lib/Doctrine/Persistence/Mapping/Driver/StaticPHPDriver.php
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ parameters:
- tests

excludes_analyse:
- tests/Doctrine/Tests/Persistence/Mapping/_files/TestEntity.php
- tests/Doctrine/Tests/Persistence/Mapping/_files/Doctrine.Tests.Persistence.Mapping.PHPTestEntity.php
3 changes: 2 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
<directory name="tests/Doctrine" />
<ignoreFiles>
<directory name="vendor" />
<file name="tests/Doctrine/Tests/Persistence/Mapping/_files/TestEntity.php" />
<!-- this one is a mapping file in written in PHP -->
<file name="tests/Doctrine/Tests/Persistence/Mapping/_files/Doctrine.Tests.Persistence.Mapping.PHPTestEntity.php" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\Persistence\Mapping;

use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use Doctrine\Persistence\Mapping\AbstractClassMetadataFactory;
use Doctrine\Tests\DoctrineTestCase;

final class AbstractClassMetadataFactoryTest extends DoctrineTestCase
{
use VerifyDeprecations;

public function testSetCacheDriverIsDeprecated(): void
{
$this->expectDeprecationWithIdentifier(
'https://github.com/doctrine/persistence/issues/184'
);

$cmf = $this->getMockForAbstractClass(AbstractClassMetadataFactory::class);
$cmf->setCacheDriver(null);
}

public function testGetCacheDriverIsDeprecated(): void
{
$this->expectDeprecationWithIdentifier(
'https://github.com/doctrine/persistence/issues/184'
);

$cmf = $this->getMockForAbstractClass(AbstractClassMetadataFactory::class);
$cmf->getCacheDriver();
}
}
6 changes: 5 additions & 1 deletion tests/Doctrine/Tests/Persistence/Mapping/PHPDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public function testLoadMetadata(): void
$metadata->expects($this->once())->method('getFieldNames');

$driver = new PHPDriver([__DIR__ . '/_files']);
$driver->loadMetadataForClass('TestEntity', $metadata);
$driver->loadMetadataForClass(PHPTestEntity::class, $metadata);
}
}

class PHPTestEntity
{
}