laravel-acl icon indicating copy to clipboard operation
laravel-acl copied to clipboard

Laravel-ACL doesn't work Codeception

Open vjandrea opened this issue 8 years ago • 0 comments

Hello there, i'm having trouble using Laravel-ACL's getRoles() in my Codeception tests. I can't figure out if it's a Laravel-ACL specific limit or it's related to the application handling in Codeception. Here's the test i wrote:

$I = new FeatureTester($scenario);
$I->wantTo('see that Kodeine ACL works with Codeception');

// setup
$user = new User([
    'first_name' => 'Test', 
    'last_name' => 'User', 
    'email' => '[email protected]',
    'password' => 'reallysafe',
    ]);
$user->save();

$I->expect('that assignRole() works');
$user->assignRole('user');

$I->amGoingTo('verify if the role has been assigned in the db');
$user_role = Role::where('slug', 'user')->first();
$I->seeRecord('role_user', ['role_id' => $user_role->id, 'user_id' => $user->id]);

$I->expect('that getRoles returns "user"');
$I->assertEquals(['user'], $user->getRoles());

And this is the result

$ codecept run feature Kodeine_ACL_Cept.php
Codeception PHP Testing Framework v2.2.9
Powered by PHPUnit 5.7.14 by Sebastian Bergmann and contributors.

There was 1 failure:

1) Kodeine_ACL_Cept: See that kodeine acl works with codeception
 Test  tests/feature/Kodeine_ACL_Cept.php
 Step  Assert equals ["user"],[]
 Fail  Failed asserting that two arrays are equal.
- Expected | + Actual
@@ @@
Array (
-    0 => 'user'
)

Scenario Steps:

 5. $I->assertEquals(["user"],[]) at tests/feature/Kodeine_ACL_Cept.php:27
 4. // I expect that getRoles returns "user"
 3. $I->seeRecord("role_user",{"role_id":7,"user_id":49}) at tests/feature/Kodeine_ACL_Cept.php:24
 2. // I am going to verify if the role has been assigned in the db
 1. // I expect that assignRole() works

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

I am using the Laravel5 and Asserts helpers.

vjandrea avatar Mar 07 '17 05:03 vjandrea