Skip to content

WebTestCase::loginAs() not working #487

@lukepass

Description

@lukepass

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions