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

it_checks_if_successful_notification_has_appeared()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
nc 1
cc 1
eloc 4
nop 1
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 spec\Sylius\Behat\Service;
15
16
use Behat\Mink\Element\NodeElement;
17
use PhpSpec\ObjectBehavior;
18
use Sylius\Behat\Exception\NotificationExpectationMismatchException;
19
use Sylius\Behat\NotificationType;
20
use Sylius\Behat\Service\Accessor\NotificationAccessorInterface;
21
use Sylius\Behat\Service\NotificationChecker;
22
use Sylius\Behat\Service\NotificationCheckerInterface;
23
24
final class NotificationCheckerSpec extends ObjectBehavior
25
{
26
    function let(NotificationAccessorInterface $notificationAccessor)
27
    {
28
        $this->beConstructedWith($notificationAccessor);
29
    }
30
31
    function it_is_initializable()
32
    {
33
        $this->shouldHaveType(NotificationChecker::class);
34
    }
35
36
    function it_implements_notification_checker_interface()
37
    {
38
        $this->shouldImplement(NotificationCheckerInterface::class);
39
    }
40
41
    function it_checks_if_successful_notification_with_specific_message_has_appeared(
42
        NotificationAccessorInterface $notificationAccessor,
43
        NodeElement $firstMessage,
44
        NodeElement $secondMessage
45
    ) {
46
        $notificationAccessor->getMessageElements()->willReturn([$firstMessage, $secondMessage]);
47
48
        $firstMessage->getText()->willReturn('Some resource has been successfully edited.');
49
        $firstMessage->hasClass('positive')->willReturn(true);
50
51
        $secondMessage->getText()->willReturn('Some resource has been successfully deleted.');
52
        $secondMessage->hasClass('positive')->willReturn(true);
53
54
        $this->checkNotification('Some resource has been successfully deleted.', NotificationType::success());
55
    }
56
57
    function it_checks_if_failure_notification_with_specific_message_has_appeared(
58
        NotificationAccessorInterface $notificationAccessor,
59
        NodeElement $firstMessage,
60
        NodeElement $secondMessage
61
    ) {
62
        $notificationAccessor->getMessageElements()->willReturn([$firstMessage, $secondMessage]);
63
64
        $firstMessage->getText()->willReturn('Some resource has been successfully edited.');
65
        $firstMessage->hasClass('negative')->willReturn(false);
66
67
        $secondMessage->getText()->willReturn('Some resource could not be deleted.');
68
        $secondMessage->hasClass('negative')->willReturn(true);
69
70
        $this->checkNotification('Some resource could not be deleted.', NotificationType::failure());
71
    }
72
73
    function it_throws_exception_if_no_message_with_given_content_and_type_has_been_found(
74
        NotificationAccessorInterface $notificationAccessor,
75
        NodeElement $firstMessage,
76
        NodeElement $secondMessage
77
    ) {
78
        $notificationAccessor->getMessageElements()->willReturn([$firstMessage, $secondMessage]);
79
80
        $firstMessage->getText()->willReturn('Some resource has been successfully edited.');
81
        $firstMessage->hasClass('negative')->willReturn(false);
82
83
        $secondMessage->getText()->willReturn('Some resource could not be deleted.');
84
        $secondMessage->hasClass('negative')->willReturn(true);
85
86
        $this
87
            ->shouldThrow(NotificationExpectationMismatchException::class)
88
            ->during('checkNotification', ['Some resource has been successfully created.', NotificationType::failure()])
89
        ;
90
    }
91
}
92