add tests and fixes

Pullrequest for https://github.com/symfony/symfony/issues/8902