Skip to content

Commit

Permalink
Simplify implementation (#56)
Browse files Browse the repository at this point in the history
* chore: Update php-cs-fixer

* refactor!: Rename AppKernel to TestKernel

BREAKING CHANGE: Renamed AppKernel to TestKernel to make it more obvious what the kernel is used for.

* refactor!: Rename addConfigFile to addConfig

BREAKING CHANGE: Renamed addConfigFile to addConfig cause it also takes a closure to allow configuration with the Symfony\Component\DependencyInjection\ContainerBuilder

* refactor!: Rename setRoutingFile to addRoutingFile

BREAKING CHANGE: Renamed setRoutingFile to addRoutingFile to allow multiple routing files

* cut: Remove setRootDir method

The rootDir is already deprecated lower than symfony 4.4, no need to support.

* cut: Remove unused test method

* chore: Add types on several places

* ci: Fix version in ci

* chore: Fix cs

* chore: Fix type

* fix: Add realpath for cache and log dir

This resolves symlinks that might be used in systems like MacOS

* refactor: Use yield instead of temporary array

* refactor!: Rename addCompilerPasses to addCompilerPass

BREAKING CHANGE: Renamed addCompilerPasses to addCompilerPass, this also changed the signature to single compiler passes only.

* refactor: Use MicroKernelTrait instead of custom implementation

* chore: Fix cs

* refactor: Switch to configure kernel class via method instead override static property

* chore: Fix CS

* ci: Update to latest ubuntu

* chore: Fix cs

* docs: Fix cs

* chore: Rebuild phpstan baseline

* chore: Rebuild psalm baseline

* ci: Set all container to ubuntu-20.04
  • Loading branch information
chapterjason authored Aug 24, 2021
1 parent 3ec9b53 commit 5ce337b
Show file tree
Hide file tree
Showing 15 changed files with 233 additions and 329 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [ pull_request ]
jobs:
tests:
name: PHPUnit PHP ${{ matrix.php }} ${{ matrix.dependency }} (Symfony ${{ matrix.symfony }})
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
matrix:
php:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
with:
php-version: 8.0
coverage: none
tools: phpstan:0.12.92, cs2pr
tools: phpstan:0.12.94, cs2pr

- name: Download dependencies
uses: ramsey/composer-install@v1
Expand All @@ -36,7 +36,7 @@ jobs:
with:
php-version: 8.0
coverage: none
tools: php-cs-fixer:2.19.0, cs2pr
tools: php-cs-fixer:3, cs2pr

- name: PHP-CS-Fixer
run: php-cs-fixer fix --dry-run --format=checkstyle | cs2pr
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/phpunit.xml
/.phpunit.result.cache
/vendor/
.php_cs.cache
.php-cs-fixer.cache
4 changes: 2 additions & 2 deletions .php_cs → .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

$finder = PhpCsFixer\Finder::create()
$finder = (new PhpCsFixer\Finder())
->in(__DIR__.'/src')
->in(__DIR__.'/tests')
;

return PhpCsFixer\Config::create()
return (new PhpCsFixer\Config())
->setRules([
'@Symfony' => true,
])
Expand Down
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
**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.
you need to create a custom `TestKernel` and load your bundle and configuration.

Using this bundle test together with Matthias Nobacks's
[SymfonyDependencyInjectionTest](https://github.com/SymfonyTest/SymfonyDependencyInjectionTest)
Expand All @@ -24,18 +24,22 @@ $ composer require --dev nyholm/symfony-bundle-test
```php

use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Nyholm\BundleTest\AppKernel;
use Nyholm\BundleTest\TestKernel;
use Acme\AcmeFooBundle;
use Acme\Service\Foo;
use Symfony\Component\HttpKernel\KernelInterface;

class BundleInitializationTest extends KernelTestCase
{
protected static function createKernel(array $options = [])
protected static function getKernelClass(): string
{
KernelTestCase::$class = AppKernel::class;
return TestKernel::class;
}

protected static function createKernel(array $options = []): KernelInterface
{
/**
* @var AppKernel $kernel
* @var TestKernel $kernel
*/
$kernel = parent::createKernel($options);
$kernel->addBundle(AcmeFooBundle::class);
Expand All @@ -44,7 +48,7 @@ class BundleInitializationTest extends KernelTestCase
return $kernel;
}

public function testInitBundle()
public function testInitBundle(): void
{
// Boot the kernel.
$kernel = self::bootKernel();
Expand All @@ -61,15 +65,15 @@ class BundleInitializationTest extends KernelTestCase
$this->assertInstanceOf(Foo::class, $service);
}

public function testBundleWithDifferentConfiguration()
public function testBundleWithDifferentConfiguration(): void
{
// Boot the kernel as normal ...
$kernel = self::bootKernel(['config' => static function(AppKernel $kernel){
$kernel = self::bootKernel(['config' => static function(TestKernel $kernel){
// Add some other bundles we depend on
$kernel->addBundle(OtherBundle::class);

// Add some configuration
$kernel->addConfigFile(__DIR__.'/config.yml');
$kernel->addConfig(__DIR__.'/config.yml');
}]);

// ...
Expand Down
25 changes: 0 additions & 25 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,30 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Access to an undefined property Nyholm\\\\BundleTest\\\\AppKernel\\:\\:\\$rootDir\\.$#"
count: 1
path: src/AppKernel.php

-
message: "#^PHPDoc tag @param references unknown parameter\\: \\$bundle$#"
count: 1
path: src/AppKernel.php

-
message: "#^Call to method reset\\(\\) on an unknown class Symfony\\\\Component\\\\DependencyInjection\\\\ResettableContainerInterface\\.$#"
count: 1
path: src/BaseBundleTestCase.php

-
message: "#^Class Symfony\\\\Component\\\\DependencyInjection\\\\ResettableContainerInterface not found\\.$#"
count: 1
path: src/BaseBundleTestCase.php

-
message: "#^PHPDoc tag @param references unknown parameter\\: \\$options$#"
count: 1
path: src/BaseBundleTestCase.php

-
message: "#^Comparison operation \"\\>\\=\" between 50306 and 50100 is always true\\.$#"
count: 1
Expand Down
21 changes: 1 addition & 20 deletions psalm.baseline.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.8.1@f73f2299dbc59a3e6c4d66cff4605176e728ee69">
<file src="src/AppKernel.php">
<InvalidReturnStatement occurrences="1">
<code>$bundles</code>
</InvalidReturnStatement>
<InvalidReturnType occurrences="1">
<code>iterable</code>
</InvalidReturnType>
<ReservedWord occurrences="1">
<code>$loader-&gt;getResolver()-&gt;resolve($file, 'php')</code>
</ReservedWord>
<UndefinedClass occurrences="1">
<code>RouteCollectionBuilder</code>
</UndefinedClass>
</file>
<file src="src/BaseBundleTestCase.php">
<UndefinedClass occurrences="1">
<code>ResettableContainerInterface</code>
</UndefinedClass>
</file>
<files psalm-version="4.x-dev@">
<file src="src/config/parameters.php">
<UndefinedGlobalVariable occurrences="3">
<code>$container</code>
Expand Down
Loading

0 comments on commit 5ce337b

Please sign in to comment.