|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Kreta package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Beñat Espiña <[email protected]> |
|
7
|
|
|
* (c) Gorka Laucirica <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
declare(strict_types=1); |
|
14
|
|
|
|
|
15
|
|
|
namespace Kreta\Notifier\Infrastructure\Persistence\Doctrine\DataFixtures; |
|
16
|
|
|
|
|
17
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
|
18
|
|
|
use Kreta\Notifier\Application\Command\Inbox\ReadNotificationCommand; |
|
19
|
|
|
use Kreta\Notifier\Application\Command\Inbox\ReceiveNotificationCommand; |
|
20
|
|
|
use Kreta\Notifier\Application\Command\Inbox\UnreadNotificationCommand; |
|
21
|
|
|
use Kreta\SharedKernel\Infrastructure\Persistence\Doctrine\DataFixtures\AbstractFixture; |
|
22
|
|
|
|
|
23
|
|
|
class LoadNotificationData extends AbstractFixture |
|
24
|
|
|
{ |
|
25
|
|
|
protected function type() : string |
|
26
|
|
|
{ |
|
27
|
|
|
return 'notification'; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function getOrder() : int |
|
31
|
|
|
{ |
|
32
|
|
|
return 2; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function load(ObjectManager $manager) : void |
|
36
|
|
|
{ |
|
37
|
|
|
$i = 0; |
|
38
|
|
|
while ($i < $this->amount()) { |
|
39
|
|
|
$userId = $this->getRandomUserByIndex($i); |
|
40
|
|
|
$notificationId = $this->fakeIds()[$i]; |
|
41
|
|
|
$body = 'The notification body ' . $i; |
|
42
|
|
|
|
|
43
|
|
|
$receiveNotificationCommand = new ReceiveNotificationCommand($body, $userId, $notificationId); |
|
44
|
|
|
$this->commandBus()->handle($receiveNotificationCommand); |
|
45
|
|
|
|
|
46
|
|
|
$readNotificationCommand = new ReadNotificationCommand($notificationId, $userId); |
|
47
|
|
|
$this->commandBus()->handle($readNotificationCommand); |
|
48
|
|
|
|
|
49
|
|
|
if ($i % 2 === 0) { |
|
50
|
|
|
$unreadNotificationCommand = new UnreadNotificationCommand($notificationId, $userId); |
|
51
|
|
|
$this->commandBus()->handle($unreadNotificationCommand); |
|
52
|
|
|
} |
|
53
|
|
|
++$i; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|