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.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ parameters:
- tests/data/doctrine_fixtures/TestFixture1.php
- tests/data/doctrine_fixtures/TestFixture2.php
- tests/_support/UnitTester.php
checkMissingIterableValueType: false
reportUnmatchedIgnoredErrors: true
ignoreErrors:
- path: tests/
Expand All @@ -21,3 +20,4 @@ parameters:
message: '#Method \S+ has no return type specified#'
- path: tests/
message: '#(?:Method|Property) .+ with generic (?:interface|class) \S+ does not specify its types#'
- identifier: missingType.iterableValue
4 changes: 0 additions & 4 deletions src/Codeception/Module/Doctrine.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ protected function clean(): void
$reflectedEm = new ReflectionClass($em);
if ($reflectedEm->hasProperty('repositories')) {
$property = $reflectedEm->getProperty('repositories');
$property->setAccessible(true);
$property->setValue($em, []);
}
$this->em->clear();
Expand Down Expand Up @@ -401,13 +400,11 @@ public function haveFakeRepository(string $className, array $methods = []): void
//Support doctrine versions before 2.4.0

$property = $reflectedEm->getProperty('repositories');
$property->setAccessible(true);
$property->setValue($em, array_merge($property->getValue($em), [$className => $mock]));
} elseif ($reflectedEm->hasProperty('repositoryFactory')) {
//For doctrine 2.4.0+ versions

$repositoryFactoryProperty = $reflectedEm->getProperty('repositoryFactory');
$repositoryFactoryProperty->setAccessible(true);
$repositoryFactory = $repositoryFactoryProperty->getValue($em);

$reflectedRepositoryFactory = new ReflectionClass($repositoryFactory);
Expand All @@ -419,7 +416,6 @@ public function haveFakeRepository(string $className, array $methods = []): void
);
} elseif ($reflectedRepositoryFactory->hasProperty('repositoryList')) {
$repositoryListProperty = $reflectedRepositoryFactory->getProperty('repositoryList');
$repositoryListProperty->setAccessible(true);

$repositoryHash = $em->getClassMetadata($className)->getName() . spl_object_id($em);
$repositoryListProperty->setValue(
Expand Down
2 changes: 0 additions & 2 deletions src/Codeception/Util/ReflectionPropertyAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public function getProperty(object $obj, string $field): mixed
$reflectedEntity = new ReflectionClass($class);
if ($reflectedEntity->hasProperty($field)) {
$property = $reflectedEntity->getProperty($field);
$property->setAccessible(true);
return $property->getValue($obj);
}
$class = get_parent_class($class);
Expand Down Expand Up @@ -62,7 +61,6 @@ private function setPropertiesForClass(?object $obj, string $class, array $data)

foreach ($reflectedEntity->getProperties() as $property) {
if (isset($data[$property->name])) {
$property->setAccessible(true);
$property->setValue($obj, $data[$property->name]);
}
}
Expand Down
18 changes: 9 additions & 9 deletions tests/unit/Codeception/Module/Doctrine2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ protected function _setUp()
$connection = DriverManager::getConnection(['driver' => $sqliteDriver, 'memory' => true]);

if (version_compare(InstalledVersions::getVersion('doctrine/orm'), '3', '>=')) {
$this->em = new EntityManager(
$connection,
ORMSetup::createAttributeMetadataConfiguration([$dir], true)
);
$configuration = ORMSetup::createAttributeMetadataConfiguration([$dir], true);
} else {
$this->em = new EntityManager(
$connection,
// @phpstan-ignore-next-line
ORMSetup::createAnnotationMetadataConfiguration([$dir], true)
);
// @phpstan-ignore-next-line
$configuration = ORMSetup::createAnnotationMetadataConfiguration([$dir], true);
}

if (PHP_VERSION_ID >= 80400 && method_exists($configuration, 'enableNativeLazyObjects')) {
$configuration->enableNativeLazyObjects(true);
}

$this->em = new EntityManager($connection, $configuration);

(new SchemaTool($this->em))->createSchema([
$this->em->getClassMetadata(CompositePrimaryKeyEntity::class),
$this->em->getClassMetadata(PlainEntity::class),
Expand Down