| 1 | <?php |
||||||
| 2 | |||||||
| 3 | declare(strict_types=1); |
||||||
| 4 | |||||||
| 5 | namespace Jasny\PHPUnit; |
||||||
| 6 | |||||||
| 7 | use Jasny\PHPUnit\Util\ExpectedWarnings; |
||||||
| 8 | use PHPUnit\Framework\AssertionFailedError; |
||||||
| 9 | use PHPUnit\Framework\Attributes\After; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 10 | use PHPUnit\Framework\Attributes\Before; |
||||||
|
0 ignored issues
–
show
The type
PHPUnit\Framework\Attributes\Before 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||||
| 11 | use PHPUnit\Framework\TestStatus\TestStatus; |
||||||
|
0 ignored issues
–
show
The type
PHPUnit\Framework\TestStatus\TestStatus 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||||
| 12 | |||||||
| 13 | trait ExpectWarningTrait |
||||||
| 14 | { |
||||||
| 15 | protected ExpectedWarnings|null $expectedWarnings; |
||||||
| 16 | |||||||
| 17 | abstract public function status(): TestStatus; |
||||||
| 18 | abstract public function addToAssertionCount(int $count); |
||||||
| 19 | |||||||
| 20 | #[Before] |
||||||
| 21 | protected function registerExpectedWarnings(): void |
||||||
| 22 | { |
||||||
| 23 | $this->expectedWarnings = new ExpectedWarnings(); |
||||||
| 24 | $this->expectedWarnings->register(); |
||||||
| 25 | 14 | } |
|||||
| 26 | |||||||
| 27 | 14 | #[After] |
|||||
| 28 | 14 | protected function unregisterExpectedWarnings(): void |
|||||
| 29 | { |
||||||
| 30 | if ($this->expectedWarnings === null) { |
||||||
| 31 | return; |
||||||
| 32 | } |
||||||
| 33 | |||||||
| 34 | $this->expectedWarnings->unregister(); |
||||||
| 35 | 14 | $this->expectedWarnings = null; |
|||||
| 36 | } |
||||||
| 37 | 14 | ||||||
| 38 | 2 | /** |
|||||
| 39 | * Performs assertions shared by all tests of a test cas. |
||||||
| 40 | */ |
||||||
| 41 | 12 | protected function assertPostConditions(): void |
|||||
| 42 | 12 | { |
|||||
| 43 | if ($this->expectedWarnings === null) { |
||||||
| 44 | return; |
||||||
| 45 | } |
||||||
| 46 | |||||||
| 47 | if (!$this->status()->isSuccess() && !$this->status()->isRisky() && !$this->status()->isUnknown()) { |
||||||
| 48 | 14 | return; // @codeCoverageIgnore |
|||||
| 49 | } |
||||||
| 50 | 14 | ||||||
| 51 | 14 | $notTriggered = $this->expectedWarnings->getNotTriggered(); |
|||||
| 52 | 2 | ||||||
| 53 | if ($notTriggered !== []) { |
||||||
| 54 | // @codeCoverageIgnoreStart |
||||||
| 55 | 12 | $desc = ExpectedWarnings::describeExpected(reset($notTriggered)); |
|||||
| 56 | throw new AssertionFailedError(\sprintf('Failed asserting that %s is triggered', $desc)); |
||||||
| 57 | 12 | // @codeCoverageIgnoreEnd |
|||||
| 58 | } |
||||||
| 59 | } |
||||||
| 60 | |||||||
| 61 | public function expectDeprecation(): void |
||||||
| 62 | { |
||||||
| 63 | $this->expectedWarnings->add('deprecation'); |
||||||
|
0 ignored issues
–
show
The method
add() does not exist on null.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 64 | $this->addToAssertionCount(1); |
||||||
| 65 | 1 | } |
|||||
| 66 | |||||||
| 67 | 1 | public function expectDeprecationMessage(string $message): void |
|||||
| 68 | 1 | { |
|||||
| 69 | $this->expectedWarnings->add('deprecation', $message); |
||||||
| 70 | $this->addToAssertionCount(1); |
||||||
| 71 | 1 | } |
|||||
| 72 | |||||||
| 73 | 1 | public function expectDeprecationMessageMatches(string $regularExpression): void |
|||||
| 74 | 1 | { |
|||||
| 75 | $this->expectedWarnings->addRegExp('deprecation', $regularExpression); |
||||||
| 76 | $this->addToAssertionCount(1); |
||||||
| 77 | 3 | } |
|||||
| 78 | |||||||
| 79 | 3 | public function expectNotice(): void |
|||||
| 80 | 3 | { |
|||||
| 81 | $this->expectedWarnings->add('notice'); |
||||||
| 82 | $this->addToAssertionCount(1); |
||||||
| 83 | 3 | } |
|||||
| 84 | |||||||
| 85 | 3 | public function expectNoticeMessage(string $message): void |
|||||
| 86 | 3 | { |
|||||
| 87 | $this->expectedWarnings->add('notice', $message); |
||||||
| 88 | $this->addToAssertionCount(1); |
||||||
| 89 | 1 | } |
|||||
| 90 | |||||||
| 91 | 1 | public function expectNoticeMessageMatches(string $regularExpression): void |
|||||
| 92 | 1 | { |
|||||
| 93 | $this->expectedWarnings->addRegExp('notice', $regularExpression); |
||||||
| 94 | $this->addToAssertionCount(1); |
||||||
| 95 | 1 | } |
|||||
| 96 | |||||||
| 97 | 1 | public function expectWarning(): void |
|||||
| 98 | 1 | { |
|||||
| 99 | $this->expectedWarnings->add('warning'); |
||||||
| 100 | $this->addToAssertionCount(1); |
||||||
| 101 | 1 | } |
|||||
| 102 | |||||||
| 103 | 1 | public function expectWarningMessage(string $message): void |
|||||
| 104 | 1 | { |
|||||
| 105 | $this->expectedWarnings->add('warning', $message); |
||||||
| 106 | $this->addToAssertionCount(1); |
||||||
| 107 | 3 | } |
|||||
| 108 | |||||||
| 109 | 3 | public function expectWarningMessageMatches(string $regularExpression): void |
|||||
| 110 | 3 | { |
|||||
| 111 | $this->expectedWarnings->addRegExp('warning', $regularExpression); |
||||||
| 112 | $this->addToAssertionCount(1); |
||||||
| 113 | 1 | } |
|||||
| 114 | } |
||||||
| 115 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths