TestListener::endTest()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 2
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of graze/hamcrest-test-listener.
5
 *
6
 * Copyright (c) 2015 Nature Delivered Ltd. <https://www.graze.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @license https://github.com/graze/hamcrest-test-listener/blob/master/LICENSE MIT
12
 * @link    https://github.com/graze/hamcrest-test-listener
13
 */
14
15
namespace Hamcrest\Adapter\PHPUnit;
16
17
use Hamcrest\MatcherAssert;
18
use PHPUnit\Framework\BaseTestListener;
19
use PHPUnit\Framework\Test;
20
use PHPUnit\Framework\TestCase;
21
22
class TestListener extends BaseTestListener
0 ignored issues
show
Deprecated Code introduced by
The class PHPUnit\Framework\BaseTestListener has been deprecated: Use TestListenerDefaultImplementation trait instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

22
class TestListener extends /** @scrutinizer ignore-deprecated */ BaseTestListener
Loading history...
23
{
24
    /**
25
     * @param Test $test
26
     */
27
    public function startTest(Test $test)
28
    {
29
        MatcherAssert::resetCount();
30
    }
31
32
    /**
33
     * @param Test  $test
34
     * @param float $time
35
     */
36
    public function endTest(Test $test, $time)
37
    {
38
        try {
39
            if ($test instanceof TestCase) {
40
                $test->addToAssertionCount(MatcherAssert::getCount());
41
            }
42
        } catch (\Exception $e) {
43
            $result = $test->getTestResultObject();
0 ignored issues
show
Bug introduced by
The method getTestResultObject() does not exist on PHPUnit\Framework\Test. It seems like you code against a sub-type of PHPUnit\Framework\Test such as PHPUnit\Framework\TestCase. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
            /** @scrutinizer ignore-call */ 
44
            $result = $test->getTestResultObject();
Loading history...
44
            $result->addError($test, $e, $time);
45
        }
46
    }
47
}
48