[DependencyInjection] fixes #9815 Syntax error in PHP dumper

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #9815
| License       | MIT
| Doc PR        | -

I also updated the unit tests to test a namespaces class to prevent future issues like this one.