Completed
Push — master ( ffcc47...e23ed8 )
by Loïc
06:21 queued 31s
created

NotificationChecker::checkNotification()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Monofony package.
5
 *
6
 * (c) Monofony
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 Monofony\Bundle\CoreBundle\Tests\Behat\Service;
13
14
use App\Tests\Behat\NotificationType;
15
use Monofony\Bundle\CoreBundle\Tests\Behat\Exception\NotificationExpectationMismatchException;
16
use Monofony\Bundle\CoreBundle\Tests\Behat\Service\Accessor\NotificationAccessorInterface;
17
18
final class NotificationChecker implements NotificationCheckerInterface
19
{
20
    /**
21
     * @var NotificationAccessorInterface
22
     */
23
    private $notificationAccessor;
24
25
    public function __construct(NotificationAccessorInterface $notificationAccessor)
26
    {
27
        $this->notificationAccessor = $notificationAccessor;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function checkNotification($message, NotificationType $type)
34
    {
35
        if ($this->hasType($type) && $this->hasMessage($message)) {
36
            return;
37
        }
38
39
        throw new NotificationExpectationMismatchException($type, $message, $this->notificationAccessor->getType(), $this->notificationAccessor->getMessage());
40
    }
41
42
    /**
43
     * @return bool
44
     */
45
    private function hasType(NotificationType $type)
46
    {
47
        return $type === $this->notificationAccessor->getType();
48
    }
49
50
    /**
51
     * @param string $message
52
     *
53
     * @return bool
54
     */
55
    private function hasMessage($message)
56
    {
57
        return false !== strpos($this->notificationAccessor->getMessage(), $message);
58
    }
59
}
60