Skip to content
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
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ parameters:
path: src/Reflection/EnumReflectionProperty.php

-
message: '#^PHPDoc tag @var with type Doctrine\\Persistence\\Mapping\\ClassMetadata\<object\> is not subtype of native type PHPUnit\\Framework\\MockObject\\MockObject\.$#'
message: '#^PHPDoc tag @var with type Doctrine\\Persistence\\Mapping\\ClassMetadata\<object\> is not subtype of native type PHPUnit\\Framework\\MockObject\\Stub\.$#'
identifier: varTag.nativeType
count: 1
path: tests/Mapping/ClassMetadataFactoryTest.php
Expand Down
2 changes: 1 addition & 1 deletion src/Mapping/Driver/ClassNames.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{
/** @param list<class-string> $classNames */
public function __construct(
private array $classNames,
private readonly array $classNames,
) {
}

Expand Down
1 change: 0 additions & 1 deletion src/Mapping/Driver/DefaultFileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public function __construct(
private string|null $fileExtension = null,
) {
$this->addPaths((array) $paths);
$this->fileExtension = $fileExtension;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Mapping/Driver/FileClassLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
{
/** @param iterable<SplFileInfo> $files An iterable of files to include. */
public function __construct(
private iterable $files,
private readonly iterable $files,
) {
}

Expand Down
8 changes: 4 additions & 4 deletions src/Mapping/Driver/MappingDriverChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use function array_keys;
use function spl_object_id;
use function strpos;
use function str_starts_with;

/**
* The DriverChain allows you to add multiple other mapping drivers for
Expand Down Expand Up @@ -58,7 +58,7 @@ public function getDrivers(): array
public function loadMetadataForClass(string $className, ClassMetadata $metadata): void
{
foreach ($this->drivers as $namespace => $driver) {
if (strpos($className, $namespace) === 0) {
if (str_starts_with($className, $namespace)) {
$driver->loadMetadataForClass($className, $metadata);

return;
Expand Down Expand Up @@ -91,7 +91,7 @@ public function getAllClassNames(): array
}

foreach ($driverClasses[$oid] as $className) {
if (strpos($className, $namespace) !== 0) {
if (! str_starts_with($className, $namespace)) {
continue;
}

Expand All @@ -112,7 +112,7 @@ public function getAllClassNames(): array
public function isTransient(string $className): bool
{
foreach ($this->drivers as $namespace => $driver) {
if (strpos($className, $namespace) === 0) {
if (str_starts_with($className, $namespace)) {
return $driver->isTransient($className);
}
}
Expand Down
7 changes: 2 additions & 5 deletions src/Mapping/Driver/SymfonyFileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ final class SymfonyFileLocator implements FileLocator
*/
protected array $prefixes = [];

/** File extension that is searched for. */
protected string|null $fileExtension;

/**
* Represents PHP namespace delimiters when looking for files
*/
Expand All @@ -63,11 +60,11 @@ final class SymfonyFileLocator implements FileLocator
*/
public function __construct(
array $prefixes,
string $fileExtension = '',
/** File extension that is searched for. */
protected string|null $fileExtension = '',
string $nsSeparator = '.',
) {
$this->addNamespacePrefixes($prefixes);
$this->fileExtension = $fileExtension;

if ($nsSeparator === '') {
throw new InvalidArgumentException('Namespace separator should not be empty');
Expand Down
2 changes: 1 addition & 1 deletion tests/Event/PreUpdateEventArgsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private function createTestPreUpdateEventArgs(): PreUpdateEventArgs
{
$entity = new TestObject();

$objectManager = $this->createMock(ObjectManager::class);
$objectManager = self::createStub(ObjectManager::class);

$entityChangeset = [
'name' => ['old', 'new'],
Expand Down
11 changes: 6 additions & 5 deletions tests/ManagerRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function testResetManager(): void

public function testGetRepository(): void
{
$repository = $this->createMock(ObjectRepository::class);
$repository = self::createStub(ObjectRepository::class);

$defaultManager = $this->mr->getManager();
assert($defaultManager instanceof MockObject);
Expand All @@ -154,7 +154,7 @@ public function testGetRepositoryWithSpecificManagerName(): void
$this->getManagerFactory(),
);

$repository = $this->createMock(ObjectRepository::class);
$repository = self::createStub(ObjectRepository::class);

$defaultManager = $this->mr->getManager();
assert($defaultManager instanceof MockObject);
Expand Down Expand Up @@ -185,7 +185,7 @@ public function testGetRepositoryWithManagerDetection(): void
$this->getManagerFactory(),
);

$repository = $this->createMock(ObjectRepository::class);
$repository = self::createStub(ObjectRepository::class);

$defaultManager = $this->mr->getManager();
assert($defaultManager instanceof MockObject);
Expand All @@ -208,9 +208,10 @@ private function getManagerFactory(): Closure
{
return function (string $name) {
$mock = $this->createMock(ObjectManager::class);
$mock->expects($this->never())->method('clear');

$driver = $this->createMock(MappingDriver::class);
$metadata = $this->createMock(ClassMetadata::class);
$driver = self::createStub(MappingDriver::class);
$metadata = self::createStub(ClassMetadata::class);

$metadata
->method('getName')
Expand Down
12 changes: 6 additions & 6 deletions tests/Mapping/AbstractClassMetadataFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public function testItSkipsTransientClasses(): void
$cmf = $this->createTestFactory($driver);

$metadataCallCount = 0;
$cmf->newClassMetadataInstanceCallback = function ($className) use (&$metadataCallCount) {
$cmf->newClassMetadataInstanceCallback = static function ($className) use (&$metadataCallCount) {
$metadataCallCount++;
if ($metadataCallCount === 1) {
self::assertEquals(SomeGrandParentEntity::class, $className);
} elseif ($metadataCallCount === 2) {
self::assertEquals(SomeEntity::class, $className);
}

return $this->createMock(ClassMetadata::class);
return self::createStub(ClassMetadata::class);
};

$driverCallCount = 0;
Expand Down Expand Up @@ -71,7 +71,7 @@ public function testItThrowsWhenAttemptingToGetMetadataForAnonymousClass(): void

public function testAnonymousClassIsNotMistakenForShortAlias(): void
{
$driver = $this->createMock(MappingDriver::class);
$driver = self::createStub(MappingDriver::class);
$driver->method('isTransient')->willReturn(false);
$cmf = $this->createTestFactory($driver);

Expand All @@ -97,7 +97,7 @@ public function testItThrowsWhenAttemptingToCheckTransientForShortAlias(): void

public function testItGetsTheSameMetadataForBackslashedClassName(): void
{
$driver = $this->createMock(MappingDriver::class);
$driver = self::createStub(MappingDriver::class);
$cmf = $this->createTestFactory($driver);

$metadata = self::createStub(ClassMetadata::class);
Expand Down Expand Up @@ -135,8 +135,8 @@ class TestAbstractClassMetadataFactory extends AbstractClassMetadataFactory

/** @param ClassMetadata<object>|null $defaultMetadata */
public function __construct(
private MappingDriver|null $driver = null,
private ClassMetadata|null $defaultMetadata = null,
private readonly MappingDriver|null $driver = null,
private readonly ClassMetadata|null $defaultMetadata = null,
) {
}

Expand Down
8 changes: 4 additions & 4 deletions tests/Mapping/ClassMetadataFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class ClassMetadataFactoryTest extends TestCase
#[Override]
protected function setUp(): void
{
$driver = $this->createMock(MappingDriver::class);
$driver = self::createStub(MappingDriver::class);

/** @phpstan-var ClassMetadata<object> */
$metadata = $this->createMock(ClassMetadata::class);
$metadata = self::createStub(ClassMetadata::class);
$this->cmf = new TestClassMetadataFactory($driver, $metadata);
}

Expand Down Expand Up @@ -67,7 +67,7 @@ public function testGetParentMetadata(): void

public function testGetCachedMetadata(): void
{
$metadata = $this->createMock(ClassMetadata::class);
$metadata = self::createStub(ClassMetadata::class);
$cache = new ArrayAdapter();
$item = $cache->getItem($this->cmf->getCacheKey(ChildEntity::class));
$item->set($metadata);
Expand All @@ -92,7 +92,7 @@ public function testCacheGetMetadataFor(): void

public function testWillFallbackOnNotLoadedMetadata(): void
{
$classMetadata = $this->createMock(ClassMetadata::class);
$classMetadata = self::createStub(ClassMetadata::class);

$this->cmf->fallbackCallback = static fn () => $classMetadata;

Expand Down
6 changes: 3 additions & 3 deletions tests/Mapping/DriverChainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DriverChainTest extends TestCase
public function testDelegateToMatchingNamespaceDriver(string $namespace1, string $namespace2): void
{
$className = DriverChainEntity::class;
$classMetadata = $this->createMock(ClassMetadata::class);
$classMetadata = self::createStub(ClassMetadata::class);

$chain = new MappingDriverChain();

Expand Down Expand Up @@ -52,7 +52,7 @@ public function testDelegateToMatchingNamespaceDriver(string $namespace1, string
public function testLoadMetadataShouldThrowMappingExceptionWhenNoDelegatorWasFound(): void
{
$className = DriverChainEntity::class;
$classMetadata = $this->createMock(ClassMetadata::class);
$classMetadata = self::createStub(ClassMetadata::class);

$chain = new MappingDriverChain();

Expand Down Expand Up @@ -87,7 +87,7 @@ public function testGatherAllClassNames(): void
#[Group('DDC-706')]
public function testIsTransient(): void
{
$driver1 = $this->createMock(MappingDriver::class);
$driver1 = self::createStub(MappingDriver::class);
$chain = new MappingDriverChain();
$chain->addDriver($driver1, 'Doctrine\Tests\Models\CMS');

Expand Down
23 changes: 12 additions & 11 deletions tests/Mapping/FileDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Doctrine\Tests\Persistence\Mapping\Fixtures\TestClassMetadata;
use Override;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\MockObject\Stub;
use PHPUnit\Framework\TestCase;
use stdClass;

Expand Down Expand Up @@ -44,7 +45,7 @@ public function testGetElementFromGlobalFile(): void

public function testGetElementFromFile(): void
{
$locator = $this->newLocator();
$locator = $this->newLocator(true);
$locator->expects(self::once())
->method('findMappingFile')
->with(self::equalTo(stdClass::class))
Expand All @@ -57,7 +58,7 @@ public function testGetElementFromFile(): void

public function testGetElementUpdatesClassCache(): void
{
$locator = $this->newLocator();
$locator = $this->newLocator(true);

// findMappingFile should only be called once
$locator->expects(self::once())
Expand Down Expand Up @@ -119,7 +120,7 @@ public function testGetAllClassNamesBothSources(): void

public function testGetAllClassNamesBothSourcesNoDupes(): void
{
$locator = $this->newLocator();
$locator = $this->newLocator(true);
$locator->expects(self::once())
->method('getAllClassNames')
->with(self::equalTo('global'))
Expand All @@ -139,7 +140,7 @@ public function testGetAllClassNamesBothSourcesNoDupes(): void

public function testIsNotTransient(): void
{
$locator = $this->newLocator();
$locator = $this->newLocator(true);
$locator->expects(self::once())
->method('fileExists')
->with(self::equalTo(stdClass::class))
Expand All @@ -155,7 +156,7 @@ public function testIsNotTransient(): void

public function testIsTransient(): void
{
$locator = $this->newLocator();
$locator = $this->newLocator(true);
$locator->expects(self::once())
->method('fileExists')
->with(self::equalTo(NotLoadedClass::class))
Expand All @@ -173,10 +174,10 @@ public function testNonLocatorFallback(): void
self::assertFalse($driver->isTransient(stdClass::class));
}

/** @return FileLocator&MockObject */
private function newLocator(): MockObject
/** @return ($mock is true ? (FileLocator&MockObject) : (FileLocator&Stub)) */
private function newLocator(bool $mock = false): FileLocator
{
$locator = $this->createMock(FileLocator::class);
$locator = $mock ? $this->createMock(FileLocator::class) : self::createStub(FileLocator::class);
$locator->method('getFileExtension')->willReturn('.yml');
$locator->method('getPaths')->willReturn([__DIR__ . '/_files']);

Expand All @@ -188,9 +189,9 @@ private function createTestFileDriver(string|array|FileLocator $locator, string|
{
$driver = new TestFileDriver($locator, $fileExtension);

$driver->stdClass = $this->createMock(ClassMetadata::class);
$driver->stdGlobal = $this->createMock(ClassMetadata::class);
$driver->stdGlobal2 = $this->createMock(ClassMetadata::class);
$driver->stdClass = self::createStub(ClassMetadata::class);
$driver->stdGlobal = self::createStub(ClassMetadata::class);
$driver->stdGlobal2 = self::createStub(ClassMetadata::class);

return $driver;
}
Expand Down
6 changes: 4 additions & 2 deletions tests/Mapping/RuntimeReflectionServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ class RuntimeReflectionServiceTest extends TestCase

public mixed $unusedPublicProperty;

private string $typedNoDefaultProperty;
/** @phpstan-ignore property.uninitializedReadonly */
private readonly string $typedNoDefaultProperty;
private string $typedDefaultProperty = '';
private string $nonTypedNoDefaultProperty; // phpcs:ignore SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedProperty
/** @phpstan-ignore property.uninitializedReadonly */
private readonly string $nonTypedNoDefaultProperty; // phpcs:ignore SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedProperty
private string $nonTypedDefaultProperty = ''; // phpcs:ignore SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedProperty

public string $typedNoDefaultPublicProperty;
Expand Down
6 changes: 3 additions & 3 deletions tests/ObjectManagerDecoratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function testFlush(): void

public function testGetRepository(): void
{
$repository = $this->createMock(ObjectRepository::class);
$repository = self::createStub(ObjectRepository::class);

$this->wrapped->expects(self::once())
->method('getRepository')
Expand All @@ -112,7 +112,7 @@ public function testGetRepository(): void

public function testGetClassMetadata(): void
{
$classMetadata = $this->createMock(ClassMetadata::class);
$classMetadata = self::createStub(ClassMetadata::class);

$this->wrapped->expects(self::once())
->method('getClassMetadata')
Expand All @@ -124,7 +124,7 @@ public function testGetClassMetadata(): void

public function testGetClassMetadataFactory(): void
{
$classMetadataFactory = $this->createMock(ClassMetadataFactory::class);
$classMetadataFactory = self::createStub(ClassMetadataFactory::class);

$this->wrapped->expects(self::once())
->method('getMetadataFactory')
Expand Down
2 changes: 1 addition & 1 deletion tests/Reflection/TypedNoDefaultReflectionPropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function setId(mixed $id): void

class TypedNullableFoo
{
private string|null $value;
private string|null $value = null;

public function setValue(mixed $value): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/RuntimeReflectionPropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public function testGetSetValue(string $name, string $value): void
}

/** @param class-string<RuntimeReflectionPropertyTestProxyMock> $proxyClass */
#[TestWith(['Doctrine\\Tests\\Persistence\\RuntimeReflectionPropertyTestProxyMock'])]
#[TestWith(['\\Doctrine\\Tests\\Persistence\\RuntimeReflectionPropertyTestProxyMock'])]
#[TestWith([RuntimeReflectionPropertyTestProxyMock::class])]
#[TestWith([RuntimeReflectionPropertyTestProxyMock::class])]
public function testGetValueOnProxyProperty(string $proxyClass): void
{
$getCheckMock = $this->createMock(DummyMock::class);
Expand Down