LoggingAssertionExecutor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 17 3
A __construct() 0 8 1
1
<?php
2
3
namespace Magium\Assertions;
4
5
use Magium\AbstractTestCase;
6
use Magium\Assertions\Element\AbstractSelectorAssertion;
7
use Magium\Util\Log\LoggerInterface;
8
9
class LoggingAssertionExecutor
10
{
11
12
    const ASSERTION = 'LoggingAssertionExecutor';
13
14
    protected $logger;
15
    protected $testCase;
16
17
    public function __construct(
18
        LoggerInterface $logger,
19
        AbstractTestCase $testCase
20
    )
21
    {
22
        $this->logger = $logger;
23
        $this->testCase = $testCase;
24
    }
25
26
    public function execute(AbstractAssertion $assertion, array $extra = [])
27
    {
28
29
        if ($assertion instanceof AbstractSelectorAssertion) {
30
            $extra = array_merge($extra, [
31
                'selector'  => $assertion->getSelector(),
32
                'by'        => $assertion->getBy()
33
            ]);
34
        }
35
        try {
36
            $assertion->assert();
37
            $this->logger->logAssertionSuccess( $assertion, $extra );
38
        } catch (\Exception $e) {
39
            $this->logger->logAssertionFailure($e, $assertion, $extra);
40
            $this->testCase->fail($e->getMessage());
41
        }
42
    }
43
44
}
45