Skip to content

Commit

Permalink
Add test for image property of Event entity (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasnatter authored Oct 23, 2020
1 parent cf07fca commit 49270bf
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 34 deletions.
56 changes: 29 additions & 27 deletions src/Entity/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,35 @@ public function setLocation(?string $location): self
return $this;
}

public function getImage(): ?MediaInterface
{
return $this->image;
}

/**
* @return array<string, mixed>|null
*
* @Serializer\VirtualProperty
* @Serializer\SerializedName("image")
*/
public function getImageData(): ?array
{
if (!$this->image) {
return null;
}

return [
'id' => $this->image->getId(),
];
}

public function setImage(?MediaInterface $image): self
{
$this->image = $image;

return $this;
}

/**
* @Serializer\VirtualProperty(name="title")
*/
Expand Down Expand Up @@ -247,31 +276,4 @@ protected function createTranslation(string $locale): EventTranslation

return $translation;
}

public function getImage(): ?MediaInterface
{
return $this->image;
}

/**
* @return array<string, mixed>|null
*
* @Serializer\VirtualProperty
* @Serializer\SerializedName("image")
*/
public function getImageData(): ?array
{
if (!$this->image) {
return null;
}

return [
'id' => $this->image->getId(),
];
}

public function setImage(?MediaInterface $image): void
{
$this->image = $image;
}
}
34 changes: 27 additions & 7 deletions tests/Unit/Entity/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Entity\Event;
use App\Entity\EventTranslation;
use PHPUnit\Framework\TestCase;
use Sulu\Bundle\MediaBundle\Entity\MediaInterface;

class EventTest extends TestCase
{
Expand All @@ -28,13 +29,6 @@ public function testEnabled(): void
$this->assertTrue($this->event->isEnabled());
}

public function testLocale(): void
{
$this->assertSame('de', $this->event->getLocale());
$this->assertSame($this->event, $this->event->setLocale('en'));
$this->assertSame('en', $this->event->getLocale());
}

public function testStartDate(): void
{
$now = new \DateTimeImmutable();
Expand All @@ -55,6 +49,25 @@ public function testEndDate(): void
$this->assertSame($now, $this->event->getEndDate());
}

public function testLocation(): void
{
$this->assertNull($this->event->getLocation());
$this->assertSame($this->event, $this->event->setLocation('Amsterdam'));
$this->assertSame('Amsterdam', $this->event->getLocation());
}

public function testImage(): void
{
$image = $this->prophesize(MediaInterface::class);
$image->getId()->willReturn(1234);

$this->assertNull($this->event->getImage());
$this->assertNull($this->event->getImageData());
$this->assertSame($this->event, $this->event->setImage($image->reveal()));
$this->assertSame($image->reveal(), $this->event->getImage());
$this->assertSame(['id' => 1234], $this->event->getImageData());
}

public function testTitle(): void
{
$this->assertNull($this->event->getTitle());
Expand Down Expand Up @@ -87,4 +100,11 @@ public function testDescription(): void
$this->assertSame('de', $this->event->getTranslations()['de']->getLocale());
$this->assertSame('Sulu is awesome', $this->event->getTranslations()['de']->getDescription());
}

public function testLocale(): void
{
$this->assertSame('de', $this->event->getLocale());
$this->assertSame($this->event, $this->event->setLocale('en'));
$this->assertSame('en', $this->event->getLocale());
}
}

0 comments on commit 49270bf

Please sign in to comment.