LoggingAssertionExecutor::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
nc 1
cc 1
eloc 5
nop 2
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