Completed
Push — 1.0 ( 290bb5...44dd9d )
by Kamil
21:01
created

NotificationChecker::checkNotification()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 7
nc 3
nop 2
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
declare(strict_types=1);
13
14
namespace Sylius\Behat\Service;
15
16
use Sylius\Behat\Exception\NotificationExpectationMismatchException;
17
use Sylius\Behat\NotificationType;
18
use Sylius\Behat\Service\Accessor\NotificationAccessorInterface;
19
use Webmozart\Assert\Assert;
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
    public function checkNotification(string $message, NotificationType $type): void
40
    {
41
        foreach ($this->notificationAccessor->getMessageElements() as $messageElement) {
42
            if (
43
                false !== strpos($messageElement->getText(), $message) &&
44
                $messageElement->hasClass($type->__toString() === 'success' ? 'positive' : 'negative')
45
            ) {
46
                return;
47
            }
48
        }
49
50
        throw new NotificationExpectationMismatchException($type, $message);
51
    }
52
}
53