Home » Php » php – Disable security firewall in test environment on Symfony2

php – Disable security firewall in test environment on Symfony2

Posted by: admin July 12, 2020 Leave a comment

Questions:

I’m trying to disable a security firewall for a test environment in Symfony2, but i’m not having luck. Here’s what i have in config_test.yml:

security:
    firewalls:
        web:
            pattern: .*
            security: false
            anonymous: ~

However, this is not disabling security. Any ideas how i can completely disable security for a certain firewall when in test env?

How to&Answers:

As mentioned in similar topic turn off firewall when developing put following rule in Your security.yml:

firewalls:
    dev:
        pattern:  ^/
        security: false

Answer:

Possible solution

You could extract from config.yml this part of code:

imports:
    - { resource: security.yml }

And put it separately to config_dev.yml and config_prod.yml. In this case config_test.yml will not import security configuration and, as result, you’ll have no security in test environment.

Answer:

Do not change security.yml, instead make an ad hoc rule for testing purposes.

You have to disable all the security firewalls configuration on your config_test.yml:

  imports:
      - { resource: config_dev.yml }

  framework:
      test: ~
      session:
          storage_id: session.storage.mock_file
      profiler:
          collect: false

  web_profiler:
      toolbar: false
      intercept_redirects: false

  swiftmailer:
      disable_delivery: true

  security:
      firewalls:
          dev:
              pattern:  ^/
              security: false

Note

Mind that config_test.yml imports config_dev.yml, which imports config.yml. So you must override all the basic configuration on test config file to make it works.