Skip to content

Add instructions about testing unused private services #76

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,44 @@ class BundleInitializationTest extends KernelTestCase

```

## Test unused private services
By default Symfony removes private services that are not used (this is also the behaviour in the test container). If you want to test your private services anyway, here is a method for doing that:

```php
class BundleInitializationTest extends KernelTestCase
{
// ...

protected static function createKernel(array $options = []): KernelInterface
{
// ...

$kernel->addTestCompilerPass(new class() implements CompilerPassInterface {
public function process(ContainerBuilder $container): void
{
foreach ($container->getDefinitions() as $id => $definition) {
if (stripos($id, 'your_namespace') === 0) {
$definition->setPublic(true);
}
}

foreach ($container->getAliases() as $id => $alias) {
if (stripos($id, 'your_namespace') === 0) {
$alias->setPublic(true);
}
}
}
});

// ...
}

// ...
}
```

This compiler pass will mark all services that starts with `your_namespace` (case insensitive) as public and hence they won't be removed.

## Configure Github Actions

You want ["Github actions"](https://docs.github.com/en/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](http://semver.org/spec/v2.0.0.html).
Expand Down