Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ parameters:
- ../tests/PHPStan/Rules/Properties/UninitializedPropertyRuleTest.php
- ../tests/PHPStan/Command/IgnoredRegexValidatorTest.php
- ../src/Command/IgnoredRegexValidator.php
- ../src/Testing/PHPUnit/*
exceptions:
uncheckedExceptionClasses:
- 'PHPStan\ShouldNotHappenException'
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" bootstrap="tests/bootstrap.php" cacheResult="false" colors="true" executionOrder="random" failOnRisky="true" failOnWarning="true" failOnEmptyTestSuite="true" beStrictAboutChangesToGlobalState="true" beStrictAboutOutputDuringTests="true" cacheDirectory="tmp/.phpunit.cache" beStrictAboutCoverageMetadata="true">
<extensions>
<bootstrap class="PHPStan\Testing\PHPUnit\PHPUnitExtension"/>
</extensions>
<testsuites>
<testsuite name="PHPStan">
<directory suffix="Test.php">tests/PHPStan</directory>
Expand Down
7 changes: 0 additions & 7 deletions src/Testing/PHPStanTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace PHPStan\Testing;

use Override;
use PHPStan\Analyser\ConstantResolver;
use PHPStan\Analyser\DirectInternalScopeFactory;
use PHPStan\Analyser\Error;
Expand Down Expand Up @@ -97,12 +96,6 @@ public static function getContainer(): Container
return self::$containers[$cacheKey];
}

#[Override]
public static function setUpBeforeClass(): void
{
self::getContainer();
}

/**
* @return string[]
*/
Expand Down
26 changes: 26 additions & 0 deletions src/Testing/PHPUnit/InitContainerBeforeDataProviderSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php declare(strict_types = 1);

namespace PHPStan\Testing\PHPUnit;

use Override;
use PHPStan\Testing\PHPStanTestCase;
use PHPUnit\Event\Test\DataProviderMethodCalled;
use PHPUnit\Event\Test\DataProviderMethodCalledSubscriber;
use function is_a;

final class InitContainerBeforeDataProviderSubscriber implements DataProviderMethodCalledSubscriber
{

#[Override]
public function notify(DataProviderMethodCalled $event): void
{
$testClassName = $event->testMethod()->className();

if (!is_a($testClassName, PhpStanTestCase::class, true)) {
return;
}

$testClassName::getContainer();
}

}
26 changes: 26 additions & 0 deletions src/Testing/PHPUnit/PHPUnitExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php declare(strict_types = 1);

namespace PHPStan\Testing\PHPUnit;

use Override;
use PHPUnit\Runner\Extension\Extension;
use PHPUnit\Runner\Extension\Facade;
use PHPUnit\Runner\Extension\ParameterCollection;
use PHPUnit\TextUI\Configuration\Configuration;

final class PHPUnitExtension implements Extension
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name should be PHPStanPHPUnitExtension

{

#[Override]
public function bootstrap(
Configuration $configuration,
Facade $facade,
ParameterCollection $parameters,
): void
{
$facade->registerSubscriber(
new InitContainerBeforeDataProviderSubscriber(),
);
}

}
Loading