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

Messages   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 16
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getMessageText() 0 11 2
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