Skip to content

Commit 06b22eb

Browse files
committed
Add view item list event
1 parent 9b33434 commit 06b22eb

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Setono\GoogleAnalyticsMeasurementProtocol\Request\Body\Event;
6+
7+
use Setono\GoogleAnalyticsMeasurementProtocol\Request\Body\Event\Item\Item;
8+
use Setono\GoogleAnalyticsMeasurementProtocol\Request\Body\Event\Trait\CreatesEmpty;
9+
use Setono\GoogleAnalyticsMeasurementProtocol\Request\Body\Event\Trait\HasItems;
10+
use Setono\GoogleAnalyticsMeasurementProtocol\Request\Body\Event\Trait\HasListId;
11+
use Setono\GoogleAnalyticsMeasurementProtocol\Request\Body\Event\Trait\HasListName;
12+
13+
class ViewItemListEvent extends Event
14+
{
15+
use CreatesEmpty;
16+
use HasListId;
17+
use HasListName;
18+
use HasItems;
19+
20+
public function getEventName(): string
21+
{
22+
return 'view_item_list';
23+
}
24+
25+
protected function getParameters(): array
26+
{
27+
return [
28+
'item_list_id' => $this->listId,
29+
'item_list_name' => $this->listName,
30+
'items' => array_map(static fn (Item $item) => $item->getParameters(), $this->items),
31+
];
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Setono\GoogleAnalyticsMeasurementProtocol\Request\Body\Event;
6+
7+
use Setono\GoogleAnalyticsMeasurementProtocol\Request\Body\Event\Item\Item;
8+
9+
/**
10+
* @covers \Setono\GoogleAnalyticsMeasurementProtocol\Request\Body\Event\ViewItemListEvent
11+
*/
12+
final class ViewItemListEventTest extends AbstractEventTestCase
13+
{
14+
protected function getEvent(): Event
15+
{
16+
return ViewItemListEvent::create()
17+
->setListId('LIST_ID')
18+
->setListName('List name')
19+
->addItem(Item::create()->setId('SKU1234')->setName('Blue t-shirt'))
20+
;
21+
}
22+
23+
protected function getExpectedJson(): string
24+
{
25+
return '{"name":"view_item_list","params":{"item_list_id":"LIST_ID","item_list_name":"List name","items":[{"item_id":"SKU1234","item_name":"Blue t-shirt","quantity":1}]}}';
26+
}
27+
}

0 commit comments

Comments
 (0)