1

I have application which base on logging users by FOSOAuthServerBundle and I want to test actions in this application.

So... In Sf2 are special config file for testing environment, config_test.yml and I've put this code:

security:
    firewalls:
        default:
            anonymous: ~

In theory it should solve my problem, because this firewall allows anyone access any action. I've put it in config_test.yml, so it should work only then I'm testing application. Good solution, I was thinking.

But Sf threw this error:

You are not allowed to define new elements for path "security.firewalls". Please define all elements for this path in one config file.

My questions is: How can I allow access actions without logging while testing application by PHPUnit?

Kamil P
  • 782
  • 1
  • 12
  • 29

1 Answers1

2

You can't add/define new elements but you can modify them.

In config_test.yml instead default firewall use name of your real firewall used in security.yml.

And better will be using http_basic: ~ instead anonymous: ~ so your tests will can behave like real authenticated user.

Nice cookbook here: http://symfony.com/doc/2.8/cookbook/testing/http_authentication.html

Paweł Mikołajczuk
  • 3,692
  • 25
  • 32
  • It works, thank you. In my case - I use FOSOAuthServerBundle http_basic wont work - in prod config I have `anonymous: false` and should also overwrite it. – Kamil P Feb 23 '16 at 15:35