GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#40)
by joseph
02:22
created

CliTestDoxPrinter::addIncompleteTest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 3
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of PHPUnit.
4
 *
5
 * (c) Sebastian Bergmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace EdmondsCommerce\PHPQA\PHPUnit\TestDox;
12
13
use PHPUnit\Framework\AssertionFailedError;
14
use PHPUnit\Framework\Test;
15
use PHPUnit\Framework\TestCase;
16
use PHPUnit\Framework\TestResult;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, EdmondsCommerce\PHPQA\PHPUnit\TestDox\TestResult. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
17
use PHPUnit\Framework\Warning;
18
use PHPUnit\Runner\PhptTestCase;
19
use PHPUnit\TextUI\ResultPrinter;
20
use PHPUnit\Util\TestDox\NamePrettifier;
21
use SebastianBergmann\Timer\Timer;
22
23
/**
24
 * This printer is for CLI output only. For the classes that output to file, html and xml,
25
 * please refer to the PHPUnit\Util\TestDox namespace
26
 */
27
class CliTestDoxPrinter extends ResultPrinter
28
{
29
    /**
30
     * @var TestDoxTestResult
0 ignored issues
show
Bug introduced by
The type EdmondsCommerce\PHPQA\PH...stDox\TestDoxTestResult was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
     */
32
    private $currentTestResult;
33
34
    /**
35
     * @var TestDoxTestResult
36
     */
37
    private $previousTestResult;
38
39
    /**
40
     * @var TestDoxTestResult[]
41
     */
42
    private $nonSuccessfulTestResults = [];
43
44
    /**
45
     * @var NamePrettifier
46
     */
47
    private $prettifier;
48
49
    public function __construct(
50
        $out = null,
51
        bool $verbose = false,
52
        $colors = self::COLOR_DEFAULT,
53
        bool $debug = false,
54
        $numberOfColumns = 80,
55
        bool $reverse = false
56
    ) {
57
        parent::__construct($out, $verbose, $colors, $debug, $numberOfColumns, $reverse);
58
59
        $this->prettifier = new NamePrettifier();
60
    }
61
62
    public function startTest(Test $test): void
63
    {
64
        if (!$test instanceof TestCase && !$test instanceof PhptTestCase) {
65
            return;
66
        }
67
68
        $class = \get_class($test);
69
70
        if ($test instanceof TestCase) {
71
            $annotations = $test->getAnnotations();
72
73
            if (isset($annotations['class']['testdox'][0])) {
74
                $className = $annotations['class']['testdox'][0];
75
            } else {
76
                $className = $this->prettifier->prettifyTestClass($class);
77
            }
78
79
            if (isset($annotations['method']['testdox'][0])) {
80
                $testMethod = $annotations['method']['testdox'][0];
81
            } else {
82
                $testMethod = $this->prettifier->prettifyTestMethod($test->getName(false));
83
            }
84
85
            $testMethod .= \substr($test->getDataSetAsString(false), 5);
86
        } elseif ($test instanceof PhptTestCase) {
0 ignored issues
show
introduced by
$test is always a sub-type of PHPUnit\Runner\PhptTestCase.
Loading history...
87
            $className  = $class;
88
            $testMethod = $test->getName();
89
        }
90
91
        $this->currentTestResult = new \EdmondsCommerce\PHPQA\PHPUnit\TestDox\TestResult(
0 ignored issues
show
Documentation Bug introduced by
It seems like new EdmondsCommerce\PHPQ...className, $testMethod) of type EdmondsCommerce\PHPQA\PHPUnit\TestDox\TestResult is incompatible with the declared type EdmondsCommerce\PHPQA\PH...stDox\TestDoxTestResult of property $currentTestResult.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
92
            function (string $color, string $buffer) {
93
                return $this->formatWithColor($color, $buffer);
94
            },
95
            $className,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $className does not seem to be defined for all execution paths leading up to this point.
Loading history...
96
            $testMethod
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $testMethod does not seem to be defined for all execution paths leading up to this point.
Loading history...
97
        );
98
99
        parent::startTest($test);
100
    }
101
102
    public function endTest(Test $test, float $time): void
103
    {
104
        if (!$test instanceof TestCase && !$test instanceof PhptTestCase) {
105
            return;
106
        }
107
108
        parent::endTest($test, $time);
109
110
        $this->currentTestResult->setRuntime($time);
111
112
        $this->write($this->currentTestResult->toString($this->previousTestResult, $this->verbose));
113
114
        $this->previousTestResult = $this->currentTestResult;
115
116
        if (!$this->currentTestResult->isTestSuccessful()) {
117
            $this->nonSuccessfulTestResults[] = $this->currentTestResult;
118
        }
119
    }
120
121
    public function addError(Test $test, \Throwable $t, float $time): void
122
    {
123
        $this->currentTestResult->fail(
124
            $this->formatWithColor('fg-yellow', '✘'),
125
            (string)$t
126
        );
127
    }
128
129
    public function addWarning(Test $test, Warning $e, float $time): void
130
    {
131
        $this->currentTestResult->fail(
132
            $this->formatWithColor('fg-yellow', '✘'),
133
            (string)$e
134
        );
135
    }
136
137
    public function addFailure(Test $test, AssertionFailedError $e, float $time): void
138
    {
139
        $this->currentTestResult->fail(
140
            $this->formatWithColor('fg-red', '✘'),
141
            (string)$e
142
        );
143
    }
144
145
    public function addIncompleteTest(Test $test, \Throwable $t, float $time): void
146
    {
147
        $this->currentTestResult->fail(
148
            $this->formatWithColor('fg-yellow', '∅'),
149
            (string)$t,
150
            true
151
        );
152
    }
153
154
    public function addRiskyTest(Test $test, \Throwable $t, float $time): void
155
    {
156
        $this->currentTestResult->fail(
157
            $this->formatWithColor('fg-yellow', '☢'),
158
            (string)$t,
159
            true
160
        );
161
    }
162
163
    public function addSkippedTest(Test $test, \Throwable $t, float $time): void
164
    {
165
        $this->currentTestResult->fail(
166
            $this->formatWithColor('fg-yellow', '→'),
167
            (string)$t,
168
            true
169
        );
170
    }
171
172
    public function writeProgress(string $progress): void
173
    {
174
    }
175
176
    public function flush(): void
177
    {
178
    }
179
180
    public function printResult(TestResult $result): void
181
    {
182
        $this->printHeader();
183
184
        $this->printNonSuccessfulTestsSummary($result->count());
185
186
        $this->printFooter($result);
187
    }
188
189
    protected function printHeader(): void
190
    {
191
        $this->write("\n".Timer::resourceUsage()."\n\n");
192
    }
193
194
    private function printNonSuccessfulTestsSummary(int $numberOfExecutedTests): void
195
    {
196
        $numberOfNonSuccessfulTests = \count($this->nonSuccessfulTestResults);
197
198
        if ($numberOfNonSuccessfulTests === 0) {
199
            return;
200
        }
201
202
        if (($numberOfNonSuccessfulTests / $numberOfExecutedTests) >= 0.7) {
203
            return;
204
        }
205
206
        $this->write("Summary of non-successful tests:\n\n");
207
208
        $previousTestResult = null;
209
210
        foreach ($this->nonSuccessfulTestResults as $testResult) {
211
            $this->write($testResult->toString($previousTestResult, $this->verbose));
212
213
            $previousTestResult = $testResult;
214
        }
215
    }
216
}
217