Completed
Pull Request — 3.1 (#348)
by Piotr
07:35
created

Messages::getMessageText()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * (c) FSi sp. z o.o. <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace FSi\Bundle\AdminBundle\Behat\Element;
13
14
use Exception;
15
use SensioLabs\Behat\PageObjectExtension\PageObject\Element;
16
17
class Messages extends Element
18
{
19
    protected $selector = '#messages';
20
21
    public function getMessageText(string $type): string
22
    {
23
        $alerts = $this->findAll('css', sprintf('.alert-%s', $type));
24
        if (count($alerts) < 1) {
25
            throw new Exception(sprintf("Unable to find any alert with type '%s'", $type));
26
        }
27
28
        return implode("\n", array_map(function ($alert) {
29
            return $alert->getText();
30
        }, $alerts));
31
    }
32
}
33