-
-
Notifications
You must be signed in to change notification settings - Fork 665
Expand file tree
/
Copy pathPartialUpdateEventSettingsHandlerTest.php
More file actions
76 lines (63 loc) · 2.88 KB
/
Copy pathPartialUpdateEventSettingsHandlerTest.php
File metadata and controls
76 lines (63 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace Tests\Unit\Services\Application\Handlers\EventSettings;
use HiEvents\DomainObjects\EventSettingDomainObject;
use HiEvents\Repository\Interfaces\EventSettingsRepositoryInterface;
use HiEvents\Services\Application\Handlers\EventSettings\DTO\PartialUpdateEventSettingsDTO;
use HiEvents\Services\Application\Handlers\EventSettings\DTO\UpdateEventSettingsDTO;
use HiEvents\Services\Application\Handlers\EventSettings\PartialUpdateEventSettingsHandler;
use HiEvents\Services\Application\Handlers\EventSettings\UpdateEventSettingsHandler;
use Mockery;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use Tests\TestCase;
class PartialUpdateEventSettingsHandlerTest extends TestCase
{
use MockeryPHPUnitIntegration;
public function test_explicit_show_copy_details_value_is_passed_through(): void
{
// Existing event has the control ON; the PATCH explicitly turns it OFF.
$dto = $this->runPartialUpdate(
existingValue: true,
settings: ['allow_copy_details_to_all_attendees' => false],
);
$this->assertFalse($dto->allow_copy_details_to_all_attendees);
}
public function test_omitted_show_copy_details_key_falls_back_to_existing_value(): void
{
// Existing event has the control OFF; the PATCH omits the key entirely.
// It must keep the existing value (false), NOT reset to the default (true).
$dto = $this->runPartialUpdate(
existingValue: false,
settings: [],
);
$this->assertFalse($dto->allow_copy_details_to_all_attendees);
}
/**
* Drives the partial handler and returns the UpdateEventSettingsDTO it forwards
* to the (mocked) full handler, so we can assert how the field was resolved.
*/
private function runPartialUpdate(bool $existingValue, array $settings): UpdateEventSettingsDTO
{
$existingSettings = (new EventSettingDomainObject())
->setAllowCopyDetailsToAllAttendees($existingValue)
->setPaymentProviders([]);
$repository = Mockery::mock(EventSettingsRepositoryInterface::class);
$repository->shouldReceive('findFirstWhere')
->with(['event_id' => 1])
->andReturn($existingSettings);
$captured = null;
$fullHandler = Mockery::mock(UpdateEventSettingsHandler::class);
$fullHandler->shouldReceive('handle')
->once()
->andReturnUsing(function (UpdateEventSettingsDTO $dto) use (&$captured, $existingSettings) {
$captured = $dto;
return $existingSettings;
});
$handler = new PartialUpdateEventSettingsHandler($fullHandler, $repository);
$handler->handle(new PartialUpdateEventSettingsDTO(
account_id: 1,
event_id: 1,
settings: array_merge(['location_details' => []], $settings),
));
return $captured;
}
}