Skip to content

Commit

Permalink
fix phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Nov 26, 2023
1 parent 5c2d148 commit 7aca375
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
10 changes: 10 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ parameters:
- '~^Only booleans are allowed in .+, .+ given( on the (left|right) side)?\.~'
- '~^Variable (static )?(property access|method call) on .+\.~'

# remove once PHPUnit 9.x support is removed
-
path: 'tests/DemosTest.php'
message: '~^Access to constant (STATUS_PASSED|STATUS_INCOMPLETE|STATUS_SKIPPED) on an unknown class PHPUnit\\Runner\\BaseTestRunner\.$~'
count: 3
-
path: 'src/Phpunit/DemosTest.php'
message: '~^Call to an undefined method Atk4\\Ui\\Tests\\DemosTest::(getName|getStatus)\(\)\.$~'
count: 4

# TODO these rules are generated, this ignores should be fixed in the code
# for level = 2
-
Expand Down
6 changes: 3 additions & 3 deletions src/Behat/CoverageUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ public static function startFromPhpunitConfig(string $phpunitConfigDir): void

$phpunitCoverageConfig = simplexml_load_file($phpunitConfigDir . '/phpunit.xml.dist')->coverage;
foreach ($phpunitCoverageConfig->include->directory ?? [] as $path) {
$filter->includeDirectory($phpunitConfigDir . '/' . $path);
$filter->includeDirectory($phpunitConfigDir . '/' . $path); // @phpstan-ignore-line
}
foreach ($phpunitCoverageConfig->include->file ?? [] as $path) {
$filter->includeFile($phpunitConfigDir . '/' . $path);
}
foreach ($phpunitCoverageConfig->exclude->directory ?? [] as $path) {
$filter->excludeDirectory($phpunitConfigDir . '/' . $path);
$filter->excludeDirectory($phpunitConfigDir . '/' . $path); // @phpstan-ignore-line
}
foreach ($phpunitCoverageConfig->exclude->file ?? [] as $path) {
$filter->excludeFile($phpunitConfigDir . '/' . $path);
$filter->excludeFile($phpunitConfigDir . '/' . $path); // @phpstan-ignore-line
}

static::start($filter);
Expand Down
12 changes: 5 additions & 7 deletions tests/DemosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Atk4\Ui\Layout;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use PHPUnit\Runner\BaseTestRunner;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

Expand All @@ -31,6 +32,7 @@ class DemosTest extends TestCase

private static ?Persistence $_db = null;

/** @var array<string, int> */
private static array $_failedParentTests = [];

public static function setUpBeforeClass(): void
Expand Down Expand Up @@ -74,13 +76,9 @@ protected function setUp(): void

protected function _onNotSuccessfulTest(\Throwable $t): void
{
if (!in_array($this->getStatus(), [
\PHPUnit\Runner\BaseTestRunner::STATUS_PASSED,
\PHPUnit\Runner\BaseTestRunner::STATUS_SKIPPED,
\PHPUnit\Runner\BaseTestRunner::STATUS_INCOMPLETE,
], true)) {
if (!isset(self::$_failedParentTests[$this->getName()])) {
self::$_failedParentTests[$this->getName()] = $this->getStatus();
if (self::isPhpunit9x() ? !in_array($this->getStatus(), [BaseTestRunner::STATUS_PASSED, BaseTestRunner::STATUS_SKIPPED, BaseTestRunner::STATUS_INCOMPLETE], true) : !$this->status()->isPassed() && !$this->status()->isSkipped() && !$this->status()->isIncomplete()) {

Check failure on line 79 in tests/DemosTest.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Call to an undefined method Atk4\Ui\Tests\DemosTest::getStatus().

Check failure on line 79 in tests/DemosTest.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Call to an undefined method PHPUnit\Framework\TestStatus\TestStatus::isPassed().

Check failure on line 79 in tests/DemosTest.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Call to an undefined method Atk4\Ui\Tests\DemosTest::getStatus().

Check failure on line 79 in tests/DemosTest.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Call to an undefined method PHPUnit\Framework\TestStatus\TestStatus::isPassed().
if (!isset(self::$_failedParentTests[self::isPhpunit9x() ? $this->getName() : $this->nameWithDataSet()])) {

Check failure on line 80 in tests/DemosTest.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Call to an undefined method Atk4\Ui\Tests\DemosTest::getName().

Check failure on line 80 in tests/DemosTest.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Call to an undefined method Atk4\Ui\Tests\DemosTest::getName().
self::$_failedParentTests[self::isPhpunit9x() ? $this->getName() : $this->nameWithDataSet()] = self::isPhpunit9x() ? $this->getStatus() : $this->status()->asInt();

Check failure on line 81 in tests/DemosTest.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Call to an undefined method Atk4\Ui\Tests\DemosTest::getName().

Check failure on line 81 in tests/DemosTest.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Call to an undefined method Atk4\Ui\Tests\DemosTest::getStatus().

Check failure on line 81 in tests/DemosTest.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Call to an undefined method Atk4\Ui\Tests\DemosTest::getName().

Check failure on line 81 in tests/DemosTest.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Call to an undefined method Atk4\Ui\Tests\DemosTest::getStatus().
} else {
self::markTestIncomplete('Test failed, but non-HTTP test failed too, fix it first');
}
Expand Down

0 comments on commit 7aca375

Please sign in to comment.