1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sylius\Behat\Service; |
13
|
|
|
|
14
|
|
|
use Sylius\Behat\Exception\NotificationExpectationMismatchException; |
15
|
|
|
use Sylius\Behat\Service\Accessor\NotificationAccessorInterface; |
16
|
|
|
use Webmozart\Assert\Assert; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Łukasz Chruściel <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
final class NotificationChecker implements NotificationCheckerInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var NotificationAccessorInterface |
25
|
|
|
*/ |
26
|
|
|
private $notificationAccessor; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param NotificationAccessorInterface $notificationAccessor |
30
|
|
|
*/ |
31
|
|
|
public function __construct(NotificationAccessorInterface $notificationAccessor) |
32
|
|
|
{ |
33
|
|
|
$this->notificationAccessor = $notificationAccessor; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritdoc} |
38
|
|
|
* |
39
|
|
|
* @throws NotificationExpectationMismatchException |
40
|
|
|
*/ |
41
|
|
|
public function checkCreationNotification($resource) |
42
|
|
|
{ |
43
|
|
|
$message = sprintf('Success %s has been successfully created.', $this->humanizeResourceName($resource)); |
44
|
|
|
|
45
|
|
|
$this->checkSuccessNotificationMessage($message); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
* |
51
|
|
|
* @throws NotificationExpectationMismatchException |
52
|
|
|
*/ |
53
|
|
|
public function checkDeletionNotification($resource) |
54
|
|
|
{ |
55
|
|
|
$message = sprintf('Success %s has been successfully deleted.', $this->humanizeResourceName($resource)); |
56
|
|
|
|
57
|
|
|
$this->checkSuccessNotificationMessage($message); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
* |
63
|
|
|
* @throws NotificationExpectationMismatchException |
64
|
|
|
*/ |
65
|
|
|
public function checkEditionNotification($resource) |
66
|
|
|
{ |
67
|
|
|
$message = sprintf('Success %s has been successfully updated.', $this->humanizeResourceName($resource)); |
68
|
|
|
|
69
|
|
|
$this->checkSuccessNotificationMessage($message); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param string $message |
74
|
|
|
* |
75
|
|
|
* @throws NotificationExpectationMismatchException |
76
|
|
|
*/ |
77
|
|
|
public function checkSuccessNotificationMessage($message) |
78
|
|
|
{ |
79
|
|
|
if ($this->notificationAccessor->hasSuccessMessage() && $this->notificationAccessor->hasMessage($message)) { |
80
|
|
|
return; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
throw new NotificationExpectationMismatchException( |
84
|
|
|
'success', |
85
|
|
|
$message, |
86
|
|
|
$this->notificationAccessor->getMessageType(), |
87
|
|
|
$this->notificationAccessor->getMessage() |
88
|
|
|
); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param string $resourceName |
93
|
|
|
* |
94
|
|
|
* @return string |
95
|
|
|
*/ |
96
|
|
|
private function humanizeResourceName($resourceName) |
97
|
|
|
{ |
98
|
|
|
return ucfirst(str_replace('_', ' ', $resourceName)); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|