symfonytest / symfony-bundle-test Goto Github PK
View Code? Open in Web Editor NEWSmoke test your Symfony bundle
License: MIT License
Smoke test your Symfony bundle
License: MIT License
Hey,
I use the Mailer with TemplatedEmail and Twig and get the following error:
Twig\Error\RuntimeError : An exception has been thrown during the rendering of a template ("Invalid resource "kernel:loadRoutes" passed to the "service" route loader: use the format "object_id::method" or "object_id" if your object class has an "__invoke" method.").
After I patched my copy like this: (https://github.com/SymfonyTest/symfony-bundle-test/blob/master/src/AppKernel.php#L122-L127)
$container->loadFromExtension('framework', [
'router' => [
- 'resource' => 'kernel:loadRoutes',
+ 'resource' => 'kernel::loadRoutes',
'type' => 'service',
],
]);
I get this error:
Twig\Error\RuntimeError : An exception has been thrown during the rendering of a template ("Service "kernel" not found: the container inside "Symfony\Component\DependencyInjection\Argument\ServiceLocator" is a smaller service locator that is empty...").
I already tried to define the kernel in the container directly with something like this:
$container->set('kernel', $kernel);
But unfortunately this doesn't work.
FYI @chapterjason
Is there something else we should change before releasing 2.0 beta1?
Looking at the release, it says it's compatible with Symfony 6. But with 1.8.2 installed I'm still getting:
Fatal error: Declaration of
Nyholm\BundleTest\AppKernel::getProjectDir() must be compatible with
Symfony\Component\HttpKernel\Kernel::getProjectDir(): string in
/project/vendor/nyholm/symfony-bundle-test/src/AppKernel.php on line 94
I can see the signatures were updated in master, but not in 1.x. Is 1.x meant to be compatible with Symfony 6?
As I was working on some tests and the changes in the 6.0 branch in Symfony was made to add return types, I got a lot of errors about some methods in the kernel.
PHP Fatal error: Declaration of Nyholm\BundleTest\AppKernel::buildContainer() must be compatible with Symfony\Component\HttpKernel\Kernel::buildContainer(): Symfony\Component\DependencyInjection\ContainerBuilder in /[...]/vendor/nyholm/symfony-bundle-test/src/AppKernel.php on line 185
PHP Fatal error: Declaration of Nyholm\BundleTest\AppKernel::getCacheDir() must be compatible with Symfony\Component\HttpKernel\Kernel::getCacheDir(): string in /[...]/vendor/nyholm/symfony-bundle-test/src/AppKernel.php on line 81
PHP Fatal error: Declaration of Nyholm\BundleTest\AppKernel::getLogDir() must be compatible with Symfony\Component\HttpKernel\Kernel::getLogDir(): string in /[...]/vendor/nyholm/symfony-bundle-test/src/AppKernel.php on line 86
PHP Fatal error: Declaration of Nyholm\BundleTest\AppKernel::getProjectDir() must be compatible with Symfony\Component\HttpKernel\Kernel::getProjectDir(): string in /[...]/vendor/nyholm/symfony-bundle-test/src/AppKernel.php on line 91
PHP Fatal error: Declaration of Nyholm\BundleTest\AppKernel::registerBundles() must be compatible with Symfony\Component\HttpKernel\KernelInterface::registerBundles(): iterable in /[...]/vendor/nyholm/symfony-bundle-test/src/AppKernel.php on line 116
To make it work I had to change the return types:
public function registerBundles(): iterable;
protected function buildContainer(): ContainerBuilder;
public function getCacheDir(): string;
public function getLogDir(): string;
public function getProjectDir(): string;
I just wanted to open the issue first to discuss a solution, I can create the pull request then.
My first thought was a second kernel with compatible return types, but I'm not sure how to create that without a lot of duplication.
Just to mention for a bit better release notes for future releases :)
Release notes: https://github.com/SymfonyTest/symfony-bundle-test/releases/tag/2.0.0
Broken link: https://github.com/SymfonyTest/symfony-bundle-test/blob/2.0.0/Changelog.md
Actual link: https://github.com/SymfonyTest/symfony-bundle-test/blob/2.0.0/CHANGELOG.md
Are we able to get a final 1.x release, 1.9.0, please?
Thanks for this great package ๐
Why was https://github.com/SymfonyTest/symfony-bundle-test/blob/1.x/src/CompilerPass/PublicServicePass.php removed in v2? If I want to test services that are only used by users of the bundle they are removed by default in Symfony and hence I cannot test them using this package. If I mark them public with the old PublicServicePass
then I can.
Can you elaborate on this? Am I missing something? :)
This means that in tests accessing private services will not be caught as an error? I find this dangerous.
Here are some of my thoughts on the next releases which already brings the Symfony 7 and PHP 8.3 Support in 3.x and some preparation in the 2.x branch which is missing, I will fix that the next days as follows:
WDYT?
// cc: @Nyholm
We should basically copy the awesome Travis files from our other repos
I just noticed that the BaseBundleTestCase
class is not compatible with the FrameworkBundle AssertionTraits.
In the trait MailerAssertionsTrait
the getContainer
function is statically called, cause it is expected that the trait will be used in the KernelTestCase
which have all the kernel and functions static.
Unfortunately the BaseBundleTestCase
uses non-static variables and functions and causes errors like these:
Error : Non-static method Nyholm\BundleTest\BaseBundleTestCase::getContainer() cannot be called statically
/[...]/vendor/symfony/framework-bundle/Test/MailerAssertionsTrait.php:121
/[...]/vendor/symfony/framework-bundle/Test/MailerAssertionsTrait.php:25
/[...]/Tests/ExampleTest.php:159
I see three possible solutions:
$this
, but this also means more maintenance.// EDIT
Also noticed that the KernelTextCase returns the test.service_container
to allow access to private services.
Do we have any current blockers?
The composer.json says that PHP 5.5+ is supported, but the code uses return types.
Currently, you cannot set the $priority
argument of ContainerBuilder::addCompilerPass();
when adding a CompilerPass
to the TestKernel
. In a few cases, this is needed, e.g. to run after another CompilerPass which alters the container (in my case: I am developing a bundle providing a custom translator implementation, before we can alter the translator in the pass of the bundle, the CompilerPass of the FrameworkBundle
, which configures the Translator, must have ran).
I see these possibilities here:
I am willing to work on this, but I am not sure, which way shall I choose.
In 1ea1ed9 the BaseBundleTestCase was removed, but that was not documented on the CHANGELOG.
As it was part of /src before in 1.x, maybe the preferred approach on how to upgrade to 2.x can get documented as well?
If a kernel has been created but not booted, BaseBundleTestCase::ensureKernelShutdown
triggers a deprecation warning when accessing getContainer
. Ideally, it should skip the whole logic as the kernel is not booted.
This is especially an issue given that BaseBundleTestCase::bootKernel()
starts by calling ensureKernelShutdown
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.