Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️
PHP attendize-alternativedoor-managementevent-check-inevent-managementevent-registrationevent-ticketingeventbrite-alternativeeventslaravelopen-sourcephpreactself-hostedsell-ticketssell-tickets-onlineticket-sellingticketing-systemtickettailor-alternativetito-alternative
<?php
namespace Tests\Unit\Services\Application\Handlers\EventOccurrence;
use HiEvents\DomainObjects\EventOccurrenceDomainObject;
use HiEvents\DomainObjects\Generated\EventOccurrenceDomainObjectAbstract;
use HiEvents\DomainObjects\Generated\ProductOccurrenceVisibilityDomainObjectAbstract;
use HiEvents\DomainObjects\ProductOccurrenceVisibilityDomainObject;
use HiEvents\Exceptions\ResourceNotFoundException;
use HiEvents\Repository\Interfaces\EventOccurrenceRepositoryInterface;
use HiEvents\Repository\Interfaces\ProductOccurrenceVisibilityRepositoryInterface;
use HiEvents\Services\Application\Handlers\EventOccurrence\GetProductVisibilityHandler;
use Mockery;
use Tests\TestCase;
class GetProductVisibilityHandlerTest extends TestCase
{
private ProductOccurrenceVisibilityRepositoryInterface|Mockery\MockInterface $visibilityRepository;
private EventOccurrenceRepositoryInterface|Mockery\MockInterface $occurrenceRepository;
private GetProductVisibilityHandler $handler;
protected function setUp(): void
{
parent::setUp();
$this->visibilityRepository = Mockery::mock(ProductOccurrenceVisibilityRepositoryInterface::class);
$this->occurrenceRepository = Mockery::mock(EventOccurrenceRepositoryInterface::class);
$this->handler = new GetProductVisibilityHandler($this->visibilityRepository, $this->occurrenceRepository);
}
public function test_handle_returns_visibility_records(): void
{
$occurrence = Mockery::mock(EventOccurrenceDomainObject::class);
$this->occurrenceRepository->shouldReceive('findFirstWhere')
->once()
->with([
EventOccurrenceDomainObjectAbstract::ID => 10,
EventOccurrenceDomainObjectAbstract::EVENT_ID => 1,
])
->andReturn($occurrence);
$records = collect([Mockery::mock(ProductOccurrenceVisibilityDomainObject::class)]);
$this->visibilityRepository->shouldReceive('findWhere')
->once()
->with([ProductOccurrenceVisibilityDomainObjectAbstract::EVENT_OCCURRENCE_ID => 10])
->andReturn($records);
$result = $this->handler->handle(1, 10);
$this->assertCount(1, $result);
}
public function test_handle_throws_when_occurrence_not_found(): void
{
$this->occurrenceRepository->shouldReceive('findFirstWhere')->once()->andReturn(null);
$this->expectException(ResourceNotFoundException::class);
$this->handler->handle(1, 999);
}
protected function tearDown(): void
{
Mockery::close();
parent::tearDown();
}
}