Skip to content

[Blameable] Not working in Unit Tests #212

@m-radzikowski

Description

@m-radzikowski

Blameable doesn't detects user in Unit Tests too. My code:

public function testAddEntity() {
    $client = static::createClient();
    $client->request('GET', '/admin/');
    $container = $client->getContainer();
    $doctrine = $container->get('doctrine');

    $user = $this->loadUser($doctrine, $username); // returns User Entity object

    $request  = $client->getRequest();

    $token = new UsernamePasswordToken($user, $user->getPassword(), "main", $user->getRoles());
    $container->get("security.context")->setToken($token);

    $event = new InteractiveLoginEvent($request, $token);
    $container->get("event_dispatcher")->dispatch("security.interactive_login", $event);

    $this->assertTrue( $client->getContainer()->get('security.context')->isGranted('ROLE_ADMIN') ); // correct, user is logged

    $newEntity = new Post;
    $this->em->persist($newEntity);
    $this->em->flush(); // error: Integrity constraint violation: 1048 Column 'created_by' cannot be null
}

I've tried this method of authentication (above) and standard HTTP authentication, but there is always MySQL error when I try to flush.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions