I'm struggling with the DomCrawler Component for Symfony, specifically the Client Request method I've been trying to hit a url within my site, "/foo/path/foo-user-1" where "foo-user-1" has been a parameter I passed through. The uri string is as expected, but for whatever reason I can't seem to move past the login page.
I suspect that this might have something to do with my app having a path (app_dev.php
) and I don't account for that in my tests...?
Thank you in advance for any help on this!
<?php
namespace App\FooBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class FooTest extends WebTestCase
{
public function testFooAction()
{
// making a request on the client:
$client = self::createClient([], array("HTTP_HOST" => "127.0.0.1"));
$client->followRedirects(true);
$url = $client->getContainer()->get("router")->generate(
'Route_name'
array("barParam" => "foo-user-1")
);
// $url => "/foo/path/foo-user-1"
$crawler = $client->request(
"GET",
$url
);
print_r($crawler); // => returns my login page html
// uri: https://127.0.0.1/login
// actual url: https://127.0.0.1/app_dev.php/login
}
}
+------------------+------------+
| Q | A |
+------------------+------------+
| Symfony Version? | 2.7.49 |
+------------------+------------+
| Php Version | 5.6.36 |
+------------------+------------+
| PHPUnit | 5.7.27 |
+------------------+------------+
| OS | Mac 10.12.6|
+------------------+------------+
EDIT: I've also replicated this scenario using the latest versions of symfony and php and it works just fine. I'm sure this is due to my version of symfony being so outdated I'm doubting the DomCrawler has full compatibility with symfony 2.7.x.