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 (#1592)
`_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:
parent
dfc4a1b140
commit
fb5066a2d7
3 changed files with 17 additions and 2 deletions
Classes/Domain/Model
Tests/Functional/Domain/Repository
|
@ -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;
|
||||||
|
|
|
@ -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.
|
|
@ -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
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue