WebTestCase::loginAs() not working
lukepass opened this issue · comments
Hello, I followed the guide to authenticate using WebTestCase::loginAs()
but it's not working and it's redirecting me to the login page.
This is my config_test.yml:
imports:
- { resource: config_dev.yml }
framework:
test: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
storage_id: session.storage.mock_file
name: MOCKSESSID
profiler:
collect: false
web_profiler:
toolbar: false
intercept_redirects: false
swiftmailer:
disable_delivery: true
liip_functional_test:
cache_db:
sqlite: liip_functional_test.services_database_backup.sqlite
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_sqlite
path: "%kernel.cache_dir%/test.db"
security:
firewalls:
main:
http_basic: ~
And this is the test:
class DivisionControllerTest extends FixtureWebTestCase
{
public function testDivisionList()
{
$this->loginAs($this->fixtures->getReference('admin-user'), 'main');
$client = $this->makeClient();
$crawler = $client->request('GET', '/teachers/divisions/list');
// successful
$this->isSuccessful($client->getResponse());
// more than 1 division
$this->assertGreaterThan(
1,
$crawler->filter('tr')->count()
);
}
}
And this is the log:
[2019-01-16 12:49:32] request.INFO: Matched route "teacher_division_list". {"route":"teacher_division_list","route_parameters":{"orderBy":"name","_controller":"AppBundle\\Controller\\DivisionController::listAction","_route":"teacher_division_list"},"request_uri":"http://localhost/teachers/divisions/list","method":"GET"} []
[2019-01-16 12:49:32] security.INFO: Populated the TokenStorage with an anonymous Token. [] []
[2019-01-16 12:49:32] security.DEBUG: Access denied, the user is not fully authenticated; redirecting to authentication entry point. {"exception":"[object] (Symfony\\Component\\Security\\Core\\Exception\\AccessDeniedException(code: 403): Access Denied. at /xyz/vendor/symfony/symfony/src/Symfony/Component/Security/Http/Firewall/AccessListener.php:68)"} []
[2019-01-16 12:49:32] security.DEBUG: Calling Authentication entry point. [] []
Preconditions
- Symfony 3.4
- PHP v7.2
- Liip v2.0.0-alpha12
Steps to reproduce
See above.
Expected result
See above.
Actual result
See above.
Hello, any news on this subject? Thanks!
No, sorry, is the problem still here with the 3.x branch?
Got same problem here ..
We got 302 redirection (due to Access Denied)
Is it working for you if you follow the redirect?
$client->followRedirects();
I just got into the same issue. With auto-follow the client goes to the login page, gets authenticated and redirected back. So the tests succeeds, but this feels weird.