Skip to content
Advertisement

Symfony 3.4 Functional tests

I have been stuck for some time on an error to do my functional tests with symfony 3.4.

My app run a custom GuardAuthenticator for authenticate my users within CAS authentication. This is just for explain the context. In my tests, I don’t want to use it, I want to use a specific authentication system.

I wrote functional tests. I started my test environment with the following :

JavaScript

According to the official Symfony doc, I extends symfony WebTestCase for set a specific authentication token for my tests How to Simulate HTTP Authentication in a Functional Test

JavaScript

Finally, I wrote my (simple) test :

JavaScript

I ran phpunit :

JavaScript

For debugging, I modified my test :

JavaScript

I ran phpunit :

JavaScript

After lots of tests I found when I call in my test :

JavaScript

It crash.

UPDATE : another test.

If I ran this :

JavaScript

It return me NULL… no token.

UPDATE 2

I dove into the code to go back to the point where symfony stops. It’s in the doDispatch method of SymfonyComponentEventDispatcherEventDispatcher class.

It trigger the listeners on the `kernel.event’ event. And when it trigger the listener named “SymfonyBundleSecurityBundleDebugTraceableFirewallListener” => “internal script failure”.

UPDATE 3 If I compare dev.log (which represents log when I run app in browser), I have this log on a request :

JavaScript

But when I run $this->client->request('GET', '/'), my test.log show :

JavaScript

No trace from security.

UPDATE 4 : another test

I ran this test :

JavaScript

It’s a page with this configuration in security.yml

JavaScript

… and the test works!

JavaScript

Advertisement

Answer

I found !

As said above, the authentication of my app is done via CAS. For testing, I want to simulate this authentication. So I created a FakeGuardAuthenticator which instead of interrogating the CAS server, simulates it and returns the credentials.

In my config_test.yml configuration file, I therefore have to override the guardAuthenticator by passing through an alias.

Which give :

JavaScript
JavaScript

Thansk to @vstelmakh and @Vyctorya for taking time to respond to me.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement