Test if your bundle is compatible with different Symfony versions
When you want to make sure that your bundle works with different versions of Symfony
you need to create a custom AppKernel
and load your bundle and configuration.
Using this bundle test together with Matthias Nobacks's SymfonyDependencyInjectionTest will give you a good base for testing a Symfony bundle.
Via Composer
$ composer require --dev nyholm/symfony-bundle-test
use Nyholm\BundleTest\BaseBundleTestCase;
use Acme\AcmeFooBundle;
use Acme\Service\Foo;
class BundleInitializationTest extends BaseBundleTestCase
{
protected function getBundleClass()
{
return AcmeFooBundle::class;
}
public function testInitBundle()
{
// Boot the kernel.
$this->bootKernel();
// Get the container
$container = $this->getContainer();
// Test if you services exists
$this->assertTrue($container->has('acme.foo'));
$service = $container->get('acme.foo');
$this->assertInstanceOf(Foo::class, $service);
}
public function testBundleWithDifferentConfiguration()
{
// Create a new Kernel
$kernel = $this->createKernel();
// Add some configuration
$kernel->addConfigFile(__DIR__.'/config.yml');
// Add some other bundles we depend on
$kernel->addBundle(OtherBundle::class);
// Boot the kernel as normal ...
$this->bootKernel();
// ...
}
}
You want "Github actions" to run against each currently supported LTS version of Symfony (since there would be only one per major version), plus the current if it's not an LTS too. There is no need for testing against version in between because Symfony follows Semantic Versioning.
Create a file in .github/workflows directory:
#.github/workflows/php.yml
name: My bundle test
on:
push: ~
pull_request: ~
jobs:
build:
runs-on: ${{ matrix.operating-system }}
name: PHP ${{ matrix.php }} and Symfony ${{ matrix.symfony }}
strategy:
matrix:
operating-system: [ ubuntu-latest, windows-latest ]
php: [ '7.4', '8.0' ]
symfony: ['4.4', '5.3']
steps:
- uses: actions/checkout@master
- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: flex
- name: Download dependencies
env:
SYMFONY_REQUIRE: ${{ matrix.symfony }}
uses: ramsey/composer-install@v1
- name: Run test suite on PHP ${{ matrix.php }} and Symfony ${{ matrix.symfony }}
run: ./vendor/bin/phpunit