Skip to content

Commit

Permalink
Merge pull request #58 from Chris53897/feature/php8-perf
Browse files Browse the repository at this point in the history
Feature/php8 perf
  • Loading branch information
tattali committed Jul 1, 2023
2 parents 218e077 + d3ef642 commit 2943469
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Event/CalendarEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public function getFilters(): array
return $this->filters;
}

public function addEvent(Event $event): self
public function addEvent(Event $event, bool $checkUnique=false): self
{
if (!\in_array($event, $this->events, true)) {
if (!$checkUnique || !\in_array($event, $this->events, true)) {
$this->events[] = $event;
}

Expand Down
17 changes: 17 additions & 0 deletions tests/Event/CalendarEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@

use CalendarBundle\Entity\Event;
use CalendarBundle\Event\CalendarEvent;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class CalendarEventTest extends TestCase
{
private \DateTime $start;
private \DateTime $end;
private array $filters;
/** @var Event&MockObject $eventEntity */
private $eventEntity;
/** @var Event&MockObject $eventEntity2 */
private $eventEntity2;
private CalendarEvent $event;

public function setUp(): void
Expand All @@ -23,6 +27,7 @@ public function setUp(): void
$this->filters = [];

$this->eventEntity = $this->createMock(Event::class);
$this->eventEntity2 = $this->createMock(Event::class);

$this->event = new CalendarEvent(
$this->start,
Expand All @@ -40,7 +45,19 @@ public function testItHasRequireValues(): void

public function testItHandleEvents(): void
{
$this->assertCount(0, $this->event->getEvents());

$this->event->addEvent($this->eventEntity);
$this->assertEquals([$this->eventEntity], $this->event->getEvents());
$this->assertCount(1, $this->event->getEvents());

$this->event->addEvent($this->eventEntity, true);
$this->assertCount(1, $this->event->getEvents());

$this->event->addEvent($this->eventEntity);
$this->assertCount(2, $this->event->getEvents());

$this->event->addEvent($this->eventEntity2, true);
$this->assertCount(3, $this->event->getEvents());
}
}

0 comments on commit 2943469

Please sign in to comment.