This is addition to this question:
public function __construct()
{
// Choose a Mink driver. More about it in later chapters.
$driver = new GoutteDriver();
$this->session = new Session($driver);
}
I tried few things:
// if ( $this->session->getCurrentUrl() != UserController::APP_URL ) {
$headers = $this->session->getResponseHeaders();
print_r($headers);
if ( empty($headers['Location']) && empty($headers['location']) ) {
throw new Exception('Login failed: ' . json_encode($headers) );
}
getCurrentUrl() does return not the url which is redirected to. (Feature is implemented and redirect works).
Headers location is not existing. So test fails, when it should pass.
What is wrong?
The problem was with url I was posting to - it was wrong, first completely wrong, then similar but still wrong:
$this->session->getDriver()->getClient()
->request('POST', static::BASE_URL . '/user/registration', $this->getFormArray());
I did not post this code in question, because I thought it was not relevant. It was so hard to see mistake - after word "registration" there was no slash at the end.
But I was using symfony 3, and for method I had defined route
@Route("/user/registration/", name="registration")
with slash at the end. From browser it worked, because browser knows how to handle this. I did not even think that there is a difference in route - is it with slash or without slash during my 4-5 years of web development, never had such problem.
So not correct route - no redirect.
Location header is still not found, because now page is already redirected, but
$this->session->getCurrentUrl()
is now correct.