mirror of https://github.com/FriendsOfTYPO3/tea.git synced 2025-03-15 13:03:50 +01:00

[BUGFIX] Improve type safety for lazy-loaded associations ()

`_loadRealInstance` will return `null` if the target of the
association does not exist (anymore). We need to handle that case
in a clean way.

Also use a dedicated folder for the fixture to make the fixture
easier to find, and to discourage reuse of fixtures.
This commit is contained in:
Oliver Klee 2025-02-04 19:06:44 +01:00 committed by GitHub
parent dfc4a1b140
commit fb5066a2d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 2 deletions
Classes/Domain/Model
Tests/Functional/Domain/Repository

View file

@ -52,9 +52,8 @@ class Tea extends AbstractEntity
public function getImage(): ?FileReference public function getImage(): ?FileReference
{ {
if ($this->image instanceof LazyLoadingProxy) { if ($this->image instanceof LazyLoadingProxy) {
/** @var FileReference $image */
$image = $this->image->_loadRealInstance(); $image = $this->image->_loadRealInstance();
$this->image = $image; $this->image = ($image instanceof FileReference) ? $image : null;
} }
return $this->image; return $this->image;

View file

@ -0,0 +1,3 @@
"tx_tea_domain_model_tea"
,"uid","title","image",
,1,"Gunpowder",1
Can't render this file because it contains an unexpected character in line 2 and column 2.

View file

@ -115,6 +115,19 @@ final class TeaRepositoryTest extends FunctionalTestCase
self::assertSame(1, $image->getUid()); self::assertSame(1, $image->getUid());
} }
/**
* @test
*/
public function MapsDeletedImageRelationToNull(): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/propertyMapping/TeaWithDeletedImage.csv');
$model = $this->subject->findByUid(1);
self::assertInstanceOf(Tea::class, $model);
self::assertNull($model->getImage());
}
/** /**
* @test * @test
*/ */