Skip to content

Commit

Permalink
Immediately return null when null is provided in content and location…
Browse files Browse the repository at this point in the history
… providers
  • Loading branch information
emodric committed Sep 6, 2023
1 parent 659d352 commit c50751c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Parameters/ValueObjectProvider/ContentProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public function __construct(Repository $repository, ErrorHandlerInterface $error

public function getValueObject($value): ?Content
{
if ($value === null) {
return null;
}

try {
/** @var \eZ\Publish\API\Repository\Values\Content\Content $content */
$content = $this->repository->sudo(
Expand Down
4 changes: 4 additions & 0 deletions lib/Parameters/ValueObjectProvider/LocationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public function __construct(Repository $repository, ErrorHandlerInterface $error

public function getValueObject($value): ?Location
{
if ($value === null) {
return null;
}

try {
return $this->repository->sudo(
static fn (Repository $repository): Location => $repository->getLocationService()->loadLocation((int) $value),
Expand Down
12 changes: 12 additions & 0 deletions tests/lib/Parameters/ValueObjectProvider/ContentProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ public function testGetValueObject(): void
self::assertSame($content, $this->valueObjectProvider->getValueObject(42));
}

/**
* @covers \Netgen\Layouts\Ez\Parameters\ValueObjectProvider\ContentProvider::getValueObject
*/
public function testGetValueObjectWithNullValue(): void
{
$this->contentServiceMock
->expects(self::never())
->method('loadContent');

self::assertNull($this->valueObjectProvider->getValueObject(null));
}

/**
* @covers \Netgen\Layouts\Ez\Parameters\ValueObjectProvider\ContentProvider::getValueObject
*/
Expand Down
12 changes: 12 additions & 0 deletions tests/lib/Parameters/ValueObjectProvider/LocationProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ public function testGetValueObject(): void
self::assertSame($location, $this->valueObjectProvider->getValueObject(42));
}

/**
* @covers \Netgen\Layouts\Ez\Parameters\ValueObjectProvider\LocationProvider::getValueObject
*/
public function testGetValueObjectWithNullValue(): void
{
$this->locationServiceMock
->expects(self::never())
->method('loadLocation');

self::assertNull($this->valueObjectProvider->getValueObject(null));
}

/**
* @covers \Netgen\Layouts\Ez\Parameters\ValueObjectProvider\LocationProvider::getValueObject
*/
Expand Down

0 comments on commit c50751c

Please sign in to comment.