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 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 @@ -74,7 +74,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 @@ -99,7 +99,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 @@ -130,7 +130,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 @@ -153,9 +153,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 @@ -28,15 +28,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 @@ -70,7 +70,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 @@ -96,7 +96,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 @@ -134,8 +134,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 @@ -26,10 +26,10 @@ class ClassMetadataFactoryTest extends TestCase

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 @@ -65,7 +65,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 @@ -90,7 +90,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 @@ -12,6 +12,7 @@
use Doctrine\Tests\Persistence\Mapping\Fixtures\NotLoadedClass;
use Doctrine\Tests\Persistence\Mapping\Fixtures\TestClassMetadata;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\MockObject\Stub;
use PHPUnit\Framework\TestCase;
use stdClass;

Expand Down Expand Up @@ -43,7 +44,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 @@ -56,7 +57,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 @@ -118,7 +119,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 @@ -138,7 +139,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 @@ -154,7 +155,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 @@ -172,10 +173,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 @@ -187,9 +188,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 @@ -21,9 +21,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 @@ -98,7 +98,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 @@ -110,7 +110,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 @@ -122,7 +122,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 @@ -39,8 +39,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
Loading