liip / liip/LiipFunctionalTestBundle
WebTestCase::loginAs() not working
- Dominant language
- PHP
- Stars
- 648
- Forks
- 179
- PR merge metrics
- No merged PRs in 30d
Description
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
1. Symfony 3.4
2. PHP v7.2
3. Liip v2.0.0-alpha12
### Steps to reproduce
See above.
### Expected result
See above.
### Actual result
See above.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with config_test.yml and the DivisionControllerTest sequence around loginAs() and makeClient(), then inspect the authentication-related log entry at Symfony's AccessListener.php. Reproduce the request and verify that the configured test client remains authenticated and reaches the division list instead of being redirected to login.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, symfony
- Domain
- authentication, testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100