-
Notifications
You must be signed in to change notification settings - Fork 534
Init container also for tests without dataprovider #4346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
||
namespace PHPStan\Testing\PHPUnit; | ||
|
||
final class ContainerInitializer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small helper to make sure we initialize containers only once per test-class
|
||
public static function initialize(string $testClassName): void | ||
{ | ||
if (array_key_exists($testClassName, self::$initialized)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should not be once per class. See the $cacheKey
in getContainer()
, it should be baased on that + class name. Probably extract the cache key computation into a new public static method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually I was wondering why we cannot just call $testClassName::getContainer()
and let it build/cache whatever it needs... but this errors like
Exception in third-party event subscriber: An ignoreErrors entry cannot contain both path and paths fields.
#0 /Users/staabm/workspace/phpstan-src/src/DependencyInjection/ContainerFactory.php(162): PHPStan\DependencyInjection\ContainerFactory->validateParameters(Array, Array)
#1 /Users/staabm/workspace/phpstan-src/src/Testing/PHPStanTestCase.php(74): PHPStan\DependencyInjection\ContainerFactory->create('/var/folders/yj...', Array, Array)
#2 /Users/staabm/workspace/phpstan-src/src/Testing/PHPUnit/ContainerInitializer.php(24): PHPStan\Testing\PHPStanTestCase::getContainer()
#3 /Users/staabm/workspace/phpstan-src/src/Testing/PHPUnit/InitContainerBeforeTestSubscriber.php(29): PHPStan\Testing\PHPUnit\ContainerInitializer::initialize('PHPStan\\Depende...')
#4 /Users/staabm/workspace/phpstan-src/tests/vendor/phpunit/phpunit/src/Event/Dispatcher/DirectDispatcher.php(106): PHPStan\Testing\PHPUnit\InitContainerBeforeTestSubscriber->notify(Object(PHPUnit\Event\Test\PreparationStarted))
#5 /Users/staabm/workspace/phpstan-src/tests/vendor/phpunit/phpunit/src/Event/Dispatcher/DeferringDispatcher.php(47): PHPUnit\Event\DirectDispatcher->dispatch(Object(PHPUnit\Event\Test\PreparationStarted))
#6 /Users/staabm/workspace/phpstan-src/tests/vendor/phpunit/phpunit/src/Event/Emitter/DispatchingEmitter.php(319): PHPUnit\Event\DeferringDispatcher->dispatch(Object(PHPUnit\Event\Test\PreparationStarted))
#7 /Users/staabm/workspace/phpstan-src/vendor/phpunit/phpunit/src/Framework/TestCase.php(479): PHPUnit\Event\DispatchingEmitter->testPreparationStarted(Object(PHPUnit\Event\Code\TestMethod))
#8 /Users/staabm/workspace/phpstan-src/vendor/phpunit/phpunit/src/Framework/TestRunner/TestRunner.php(87): PHPUnit\Framework\TestCase->runBare()
#9 /Users/staabm/workspace/phpstan-src/vendor/phpunit/phpunit/src/Framework/TestCase.php(361): PHPUnit\Framework\TestRunner->run(Object(PHPStan\DependencyInjection\InvalidIgnoredErrorExceptionTest))
#10 /Users/staabm/workspace/phpstan-src/vendor/phpunit/phpunit/src/Framework/TestSuite.php(369): PHPUnit\Framework\TestCase->run()
#11 /Users/staabm/workspace/phpstan-src/vendor/phpunit/phpunit/src/Framework/TestSuite.php(369): PHPUnit\Framework\TestSuite->run()
#12 /Users/staabm/workspace/phpstan-src/tests/vendor/brianium/paratest/src/WrapperRunner/ApplicationForWrapperWorker.php(116): PHPUnit\Framework\TestSuite->run()
#13 /Users/staabm/workspace/phpstan-src/tests/vendor/brianium/paratest/bin/phpunit-wrapper.php(80): ParaTest\WrapperRunner\ApplicationForWrapperWorker->runTest('tests/PHPStan/D...')
#14 /Users/staabm/workspace/phpstan-src/tests/vendor/brianium/paratest/bin/phpunit-wrapper.php(85): {closure}()
#15 {main}
looks like a race condition but I don't know yet how/why
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get the same error when re-using the cache key logic from getContainer
- feels like the cache key is not unqiue enough for parallel execution.
will be afk and do some tourists stuff in dresden ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a race condition, it's a test that tests these errors on purpose 😀
Thank you! |
#4342 did only work for tests which used a dataprovider