2

So thanks to Matteo (phpunit in symfony2 - No tests executed) I can now test my functional tests.

Now I got the following error when running phpunit -c app:

 You must change the main Request object in the front controller (app.php)
 in order to use the `host_with_path` strategy.

so I did change it in the app.php, from:

$request = RequestFactory::createFromGlobals('host_with_path');

to:

$request = Request::createFromGlobals();

I also updated my swiftmailer-bundle from version 2.3 to 5.4.0. Unfortunately This did not fix my error.

and this is my ../app/config_test.yml

swiftmailer:
disable_delivery: true

Am I missing something here?

I cannot seem to find this error anywhere on the web. Does someone know how I should fix this error?

After some searching I noticed that the app.php wasn't the problem. It was the DefaultControllerTest.php. The error could be fixed by removing the following lines from the DefaultControllerTest:

        $crawler = $client->request('GET', '/hello/Fabien');

    $this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0);

Due to recent developments our development team decided to stop using Sonata. As a side effect this bug got fixed. So I won't have a solution for this problem.

1 Answer 1

0

The problem here is, that the Client object is using neither app.php nor app_dev.php.

The client creates the request internally. So it won't be the request you need.

The only solution I can see is to override the method Symfony\Bundle\FrameworkBundle\Test\WebTestCase::createClient to return your own client. This client is than responsible for creating the actual request object. The following is the current behavior.

namespace Symfony\Component\HttpKernel;

use Symfony\Component\BrowserKit\Client as BaseClient;

class Client extends BaseClient
{
  ...
  /**
     * Converts the BrowserKit request to a HttpKernel request.
     *
     * @param DomRequest $request A DomRequest instance
     *
     * @return Request A Request instance
     */
    protected function filterRequest(DomRequest $request)
    {
        $httpRequest = Request::create($request->getUri(), $request->getMethod(), $request->getParameters(), $request->getCookies(), $request->getFiles(), $request->getServer(), $request->getContent());
        foreach ($this->filterFiles($httpRequest->files->all()) as $key => $value) {
            $httpRequest->files->set($key, $value);
        }
        return $httpRequest;
    }
  ...
}

You have to override method filterRequest to return kind of a request you want.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.