Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consecutive tests fail when using custom table names #378

Closed
pszucs opened this issue Nov 27, 2018 · 9 comments
Closed

Consecutive tests fail when using custom table names #378

pszucs opened this issue Nov 27, 2018 · 9 comments

Comments

@pszucs
Copy link

pszucs commented Nov 27, 2018

The first test in the class passes and then the rest of the tests fail. I believe this issue is related to this one here: #306

The difference is that I'm not using custom roles, I'm just adding prefixes to the Bouncer table names in the AppServiceProvider's boot method:

Bouncer::tables([
    'abilities' => 'bouncer_abilities',
    'permissions' => 'bouncer_permissions',
    'roles' => 'bouncer_roles',
    'assigned_roles' => 'bouncer_assigned_roles',
]);

The tests are really simple:

public function setUp()
{
    parent::setUp();

    $this->admin = AdminUser::findOrFail(1);
}

public function testListUsers1() {
    $response = $this->actingAs($this->admin)
        ->json('GET', '/users');

    $response->assertStatus(200);
}

public function testListUsers2() {
    $response = $this->actingAs($this->admin)
        ->json('GET', '/users');

    $response->assertStatus(200);
}

These tests pass if I use the default table names.

Any help would be much appreciated.

@JosephSilber
Copy link
Owner

  1. where are you seeding your admin user / general users?

  2. "the rest of the tests fail". With which error? Do you have a stack trace?

  3. Are you using any of Laravel's database testing traits, such as RefreshDatabase?

@pszucs
Copy link
Author

pszucs commented Jan 15, 2019

Thanks for your reply.

  1. I'm seeding them from the seeds/AdminUsersSeeder and seeds/UsersSeeder classes just before executing the tests. So the testing begins with a fresh database and seeded data.
  2. Executing the phpunit --testdox tests/Feature/UserTest.php produces the following output:
PHPUnit 7.4.4 by Sebastian Bergmann and contributors.

Feature\User
 ✔ Already exists
 ✘ Does not exist
   │
   │ Expected status code 200 but received 403.
   │ Failed asserting that false is true.
   │ 
   │ /var/www/helloderr/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:133
   │ /var/www/helloderr/tests/Feature/UserTest.php:83
   │ 

 ✘ Create
   │
   │ Expected status code 200 but received 403.
   │ Failed asserting that false is true.
   │ 
   │ /var/www/helloderr/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:133
   │ /var/www/helloderr/tests/Feature/UserTest.php:111
   │ 

The second test is the testDoesNotExist() method. Dumping the $response with $response->dump(); outputs the following:

{#1214
  +"message": "This action is unauthorized."
  +"exception": "Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException"
  +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php"
  +"line": 202
  +"trace": array:71 [
    0 => {#1209
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php"
      +"line": 176
      +"function": "prepareException"
      +"class": "Illuminate\Foundation\Exceptions\Handler"
      +"type": "->"
    }
    1 => {#1210
      +"file": "/var/www/helloderr/app/Exceptions/Handler.php"
      +"line": 160
      +"function": "render"
      +"class": "Illuminate\Foundation\Exceptions\Handler"
      +"type": "->"
    }
    2 => {#1216
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
      +"line": 83
      +"function": "render"
      +"class": "App\Exceptions\Handler"
      +"type": "->"
    }
    3 => {#1195
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
      +"line": 55
      +"function": "handleException"
      +"class": "Illuminate\Routing\Pipeline"
      +"type": "->"
    }
    4 => {#1215
      +"file": "/var/www/helloderr/app/Http/Middleware/CspHeaders.php"
      +"line": 46
      +"function": "Illuminate\Routing\{closure}"
      +"class": "Illuminate\Routing\Pipeline"
      +"type": "->"
    }
    5 => {#1205
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      +"line": 151
      +"function": "handle"
      +"class": "App\Http\Middleware\CspHeaders"
      +"type": "->"
    }
    6 => {#1213
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
      +"line": 53
      +"function": "Illuminate\Pipeline\{closure}"
      +"class": "Illuminate\Pipeline\Pipeline"
      +"type": "->"
    }
    7 => {#1222
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php"
      +"line": 41
      +"function": "Illuminate\Routing\{closure}"
      +"class": "Illuminate\Routing\Pipeline"
      +"type": "->"
    }
    8 => {#869
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      +"line": 151
      +"function": "handle"
      +"class": "Illuminate\Routing\Middleware\SubstituteBindings"
      +"type": "->"
    }
    9 => {#1220
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
      +"line": 53
      +"function": "Illuminate\Pipeline\{closure}"
      +"class": "Illuminate\Pipeline\Pipeline"
      +"type": "->"
    }
    10 => {#1234
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php"
      +"line": 43
      +"function": "Illuminate\Routing\{closure}"
      +"class": "Illuminate\Routing\Pipeline"
      +"type": "->"
    }
    11 => {#1225
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      +"line": 151
      +"function": "handle"
      +"class": "Illuminate\Auth\Middleware\Authenticate"
      +"type": "->"
    }
    12 => {#1236
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
      +"line": 53
      +"function": "Illuminate\Pipeline\{closure}"
      +"class": "Illuminate\Pipeline\Pipeline"
      +"type": "->"
    }
    13 => {#1237
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php"
      +"line": 75
      +"function": "Illuminate\Routing\{closure}"
      +"class": "Illuminate\Routing\Pipeline"
      +"type": "->"
    }
    14 => {#1221
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      +"line": 151
      +"function": "handle"
      +"class": "Illuminate\Foundation\Http\Middleware\VerifyCsrfToken"
      +"type": "->"
    }
    15 => {#1239
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
      +"line": 53
      +"function": "Illuminate\Pipeline\{closure}"
      +"class": "Illuminate\Pipeline\Pipeline"
      +"type": "->"
    }
    16 => {#1241
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php"
      +"line": 49
      +"function": "Illuminate\Routing\{closure}"
      +"class": "Illuminate\Routing\Pipeline"
      +"type": "->"
    }
    17 => {#1240
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      +"line": 151
      +"function": "handle"
      +"class": "Illuminate\View\Middleware\ShareErrorsFromSession"
      +"type": "->"
    }
    18 => {#1242
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
      +"line": 53
      +"function": "Illuminate\Pipeline\{closure}"
      +"class": "Illuminate\Pipeline\Pipeline"
      +"type": "->"
    }
    19 => {#1244
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php"
      +"line": 63
      +"function": "Illuminate\Routing\{closure}"
      +"class": "Illuminate\Routing\Pipeline"
      +"type": "->"
    }
    20 => {#1243
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      +"line": 151
      +"function": "handle"
      +"class": "Illuminate\Session\Middleware\StartSession"
      +"type": "->"
    }
    21 => {#1247
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
      +"line": 53
      +"function": "Illuminate\Pipeline\{closure}"
      +"class": "Illuminate\Pipeline\Pipeline"
      +"type": "->"
    }
    22 => {#1245
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php"
      +"line": 37
      +"function": "Illuminate\Routing\{closure}"
      +"class": "Illuminate\Routing\Pipeline"
      +"type": "->"
    }
    23 => {#1246
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      +"line": 151
      +"function": "handle"
      +"class": "Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse"
      +"type": "->"
    }
    24 => {#1250
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
      +"line": 53
      +"function": "Illuminate\Pipeline\{closure}"
      +"class": "Illuminate\Pipeline\Pipeline"
      +"type": "->"
    }
    25 => {#1248
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php"
      +"line": 66
      +"function": "Illuminate\Routing\{closure}"
      +"class": "Illuminate\Routing\Pipeline"
      +"type": "->"
    }
    26 => {#1249
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      +"line": 151
      +"function": "handle"
      +"class": "Illuminate\Cookie\Middleware\EncryptCookies"
      +"type": "->"
    }
    27 => {#1256
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
      +"line": 53
      +"function": "Illuminate\Pipeline\{closure}"
      +"class": "Illuminate\Pipeline\Pipeline"
      +"type": "->"
    }
    28 => {#1286
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      +"line": 104
      +"function": "Illuminate\Routing\{closure}"
      +"class": "Illuminate\Routing\Pipeline"
      +"type": "->"
    }
    29 => {#1287
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Routing/Router.php"
      +"line": 684
      +"function": "then"
      +"class": "Illuminate\Pipeline\Pipeline"
      +"type": "->"
    }
    30 => {#1277
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Routing/Router.php"
      +"line": 659
      +"function": "runRouteWithinStack"
      +"class": "Illuminate\Routing\Router"
      +"type": "->"
    }
    31 => {#1292
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Routing/Router.php"
      +"line": 625
      +"function": "runRoute"
      +"class": "Illuminate\Routing\Router"
      +"type": "->"
    }
    32 => {#1305
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Routing/Router.php"
      +"line": 614
      +"function": "dispatchToRoute"
      +"class": "Illuminate\Routing\Router"
      +"type": "->"
    }
    33 => {#1289
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php"
      +"line": 176
      +"function": "dispatch"
      +"class": "Illuminate\Routing\Router"
      +"type": "->"
    }
    34 => {#1295
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
      +"line": 30
      +"function": "Illuminate\Foundation\Http\{closure}"
      +"class": "Illuminate\Foundation\Http\Kernel"
      +"type": "->"
    }
    35 => {#1293
      +"file": "/var/www/helloderr/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php"
      +"line": 58
      +"function": "Illuminate\Routing\{closure}"
      +"class": "Illuminate\Routing\Pipeline"
      +"type": "->"
    }
    36 => {#1294
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      +"line": 151
      +"function": "handle"
      +"class": "Barryvdh\Debugbar\Middleware\InjectDebugbar"
      +"type": "->"
    }
    37 => {#1296
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
      +"line": 53
      +"function": "Illuminate\Pipeline\{closure}"
      +"class": "Illuminate\Pipeline\Pipeline"
      +"type": "->"
    }
    38 => {#1297
      +"file": "/var/www/helloderr/vendor/mnabialek/laravel-test-css/src/Middleware/LaravelTestCss.php"
      +"line": 38
      +"function": "Illuminate\Routing\{closure}"
      +"class": "Illuminate\Routing\Pipeline"
      +"type": "->"
    }
    39 => {#1301
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      +"line": 151
      +"function": "handle"
      +"class": "Mnabialek\LaravelTestCss\Middleware\LaravelTestCss"
      +"type": "->"
    }
    40 => {#1299
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
      +"line": 53
      +"function": "Illuminate\Pipeline\{closure}"
      +"class": "Illuminate\Pipeline\Pipeline"
      +"type": "->"
    }
    41 => {#1288
      +"file": "/var/www/helloderr/vendor/fideloper/proxy/src/TrustProxies.php"
      +"line": 57
      +"function": "Illuminate\Routing\{closure}"
      +"class": "Illuminate\Routing\Pipeline"
      +"type": "->"
    }
    42 => {#1306
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      +"line": 151
      +"function": "handle"
      +"class": "Fideloper\Proxy\TrustProxies"
      +"type": "->"
    }
    43 => {#1304
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
      +"line": 53
      +"function": "Illuminate\Pipeline\{closure}"
      +"class": "Illuminate\Pipeline\Pipeline"
      +"type": "->"
    }
    44 => {#1308
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php"
      +"line": 31
      +"function": "Illuminate\Routing\{closure}"
      +"class": "Illuminate\Routing\Pipeline"
      +"type": "->"
    }
    45 => {#1302
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      +"line": 151
      +"function": "handle"
      +"class": "Illuminate\Foundation\Http\Middleware\TransformsRequest"
      +"type": "->"
    }
    46 => {#1211
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
      +"line": 53
      +"function": "Illuminate\Pipeline\{closure}"
      +"class": "Illuminate\Pipeline\Pipeline"
      +"type": "->"
    }
    47 => {#1311
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php"
      +"line": 31
      +"function": "Illuminate\Routing\{closure}"
      +"class": "Illuminate\Routing\Pipeline"
      +"type": "->"
    }
    48 => {#1310
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      +"line": 151
      +"function": "handle"
      +"class": "Illuminate\Foundation\Http\Middleware\TransformsRequest"
      +"type": "->"
    }
    49 => {#1309
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
      +"line": 53
      +"function": "Illuminate\Pipeline\{closure}"
      +"class": "Illuminate\Pipeline\Pipeline"
      +"type": "->"
    }
    50 => {#1312
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php"
      +"line": 27
      +"function": "Illuminate\Routing\{closure}"
      +"class": "Illuminate\Routing\Pipeline"
      +"type": "->"
    }
    51 => {#1303
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      +"line": 151
      +"function": "handle"
      +"class": "Illuminate\Foundation\Http\Middleware\ValidatePostSize"
      +"type": "->"
    }
    52 => {#1314
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
      +"line": 53
      +"function": "Illuminate\Pipeline\{closure}"
      +"class": "Illuminate\Pipeline\Pipeline"
      +"type": "->"
    }
    53 => {#1318
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php"
      +"line": 62
      +"function": "Illuminate\Routing\{closure}"
      +"class": "Illuminate\Routing\Pipeline"
      +"type": "->"
    }
    54 => {#1313
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      +"line": 151
      +"function": "handle"
      +"class": "Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode"
      +"type": "->"
    }
    55 => {#1335
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
      +"line": 53
      +"function": "Illuminate\Pipeline\{closure}"
      +"class": "Illuminate\Pipeline\Pipeline"
      +"type": "->"
    }
    56 => {#1319
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      +"line": 104
      +"function": "Illuminate\Routing\{closure}"
      +"class": "Illuminate\Routing\Pipeline"
      +"type": "->"
    }
    57 => {#1338
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php"
      +"line": 151
      +"function": "then"
      +"class": "Illuminate\Pipeline\Pipeline"
      +"type": "->"
    }
    58 => {#1336
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php"
      +"line": 116
      +"function": "sendRequestThroughRouter"
      +"class": "Illuminate\Foundation\Http\Kernel"
      +"type": "->"
    }
    59 => {#1358
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php"
      +"line": 345
      +"function": "handle"
      +"class": "Illuminate\Foundation\Http\Kernel"
      +"type": "->"
    }
    60 => {#1352
      +"file": "/var/www/helloderr/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php"
      +"line": 317
      +"function": "call"
      +"class": "Illuminate\Foundation\Testing\TestCase"
      +"type": "->"
    }
    61 => {#1350
      +"file": "/var/www/helloderr/tests/Feature/UserTest.php"
      +"line": 75
      +"function": "json"
      +"class": "Illuminate\Foundation\Testing\TestCase"
      +"type": "->"
    }
    62 => {#1353
      +"file": "/var/www/helloderr/vendor/phpunit/phpunit/src/Framework/TestCase.php"
      +"line": 1148
      +"function": "testDoesNotExist"
      +"class": "Tests\Feature\UserTest"
      +"type": "->"
    }
    63 => {#1344
      +"file": "/var/www/helloderr/vendor/phpunit/phpunit/src/Framework/TestCase.php"
      +"line": 842
      +"function": "runTest"
      +"class": "PHPUnit\Framework\TestCase"
      +"type": "->"
    }
    64 => {#1348
      +"file": "/var/www/helloderr/vendor/phpunit/phpunit/src/Framework/TestResult.php"
      +"line": 675
      +"function": "runBare"
      +"class": "PHPUnit\Framework\TestCase"
      +"type": "->"
    }
    65 => {#1359
      +"file": "/var/www/helloderr/vendor/phpunit/phpunit/src/Framework/TestCase.php"
      +"line": 796
      +"function": "run"
      +"class": "PHPUnit\Framework\TestResult"
      +"type": "->"
    }
    66 => {#1349
      +"file": "/var/www/helloderr/vendor/phpunit/phpunit/src/Framework/TestSuite.php"
      +"line": 750
      +"function": "run"
      +"class": "PHPUnit\Framework\TestCase"
      +"type": "->"
    }
    67 => {#1351
      +"file": "/var/www/helloderr/vendor/phpunit/phpunit/src/TextUI/TestRunner.php"
      +"line": 622
      +"function": "run"
      +"class": "PHPUnit\Framework\TestSuite"
      +"type": "->"
    }
    68 => {#1343
      +"file": "/var/www/helloderr/vendor/phpunit/phpunit/src/TextUI/Command.php"
      +"line": 206
      +"function": "doRun"
      +"class": "PHPUnit\TextUI\TestRunner"
      +"type": "->"
    }
    69 => {#1347
      +"file": "/var/www/helloderr/vendor/phpunit/phpunit/src/TextUI/Command.php"
      +"line": 162
      +"function": "run"
      +"class": "PHPUnit\TextUI\Command"
      +"type": "->"
    }
    70 => {#1356
      +"file": "/var/www/helloderr/vendor/phpunit/phpunit/phpunit"
      +"line": 61
      +"function": "main"
      +"class": "PHPUnit\TextUI\Command"
      +"type": "::"
    }
  ]
}

Regardless of what I'm testing in the second, third, etc. methods the response is always 403 - the admin user is not authorized.

  1. No, I'm not using any of those.

If I comment out the table name definitions then all the tests pass:

PHPUnit 7.4.4 by Sebastian Bergmann and contributors.

Feature\User
 ✔ Already exists
 ✔ Does not exist
 ✔ Create
 ✔ Edit email already exists
 ✔ Edit success

Time: 321 ms, Memory: 24.00MB

@JosephSilber
Copy link
Owner

JosephSilber commented Jan 17, 2019

I created a demo to test this issue, but I couldn't reproduce it. All tests seem to pass.

Look at this commit, which basically tries to recreate your setup.


To try it yourself:

  1. Clone the repo
  2. Run composer install
  3. Create an .env file and add credentials to an empty database
  4. Run php artisan migrate --seed
  5. Run PHPUnit

All tests pass.

@pszucs
Copy link
Author

pszucs commented Jan 17, 2019

Thanks Joseph.

It seems it's something to do with the 'everything()' method. My test user is someone who has access to everything.

I created a fork of your demo repo and pushed some changes to it, please see the commit here: pszucs/bouncer-issue-378-demo@faab920

  1. I removed the authorization from the controller's method
  2. Moved the authorization into the routes file (and changed a bit so it shows how I use the abilities)
  3. Changed the seeder file so it
  • creates a 'superadmin' role and allows it to do everything
  • creates the test user
  • assigns the 'superadmin' role to the user

If you comment out the 'superadmin' lines and put the 'read-users' ability back, the tests pass. If the 'superadmin' lines are uncommented, the first test passes, the second one fails.

JosephSilber added a commit to JosephSilber/bouncer-issue-378-demo that referenced this issue Jan 20, 2019
@JosephSilber
Copy link
Owner

  1. With your code, none of the tests pass. Not even the first one.

  2. The reason it fails is again because of the missing morph map.

    Adding the morph map makes both tests pass.


I'm thinking of maybe automatically registering the morph map whenever a custom table mapping is added (and whenever a custom model is used) to prevent these kinds of issues.

@JosephSilber
Copy link
Owner

JosephSilber commented Jan 21, 2019

I'm thinking of maybe automatically registering the morph map whenever a custom table mapping is added

I just pushed an update with this. Please try it out on "silber/bouncer": "dev-master" to see if it solves your issue.

@pszucs
Copy link
Author

pszucs commented Jan 21, 2019

1. With your code, none of the tests pass. Not even the first one.

2. The reason it fails is again because of the missing [morph map](https://josephsilber.com/posts/2018/07/02/eloquent-polymorphic-relations-morph-map).
   [Adding the morph map](https://github.com/JosephSilber/bouncer-issue-378-demo/commit/53c2992f62eeb01968e84681185e70449026f6e0) makes both tests pass.

Re 1: The first one did pass.
screenshot from 2019-01-21 08-15-49

Re 2: Yep, tried it on both the sample project and on my 'real' project and your fix works on both of them.

Many thanks!

@zanechua
Copy link

zanechua commented Feb 9, 2019

Would like to comment on this as I am facing this exact issue but with Dusk tests. I am using a custom model and am registering it with Bouncer::useRoleModel(Role::class);.

The first test will run and complete successfully while creating permissions in the permissions table as entity_type App\Models\Role but subsequent tests will create permissions with entity_type roles which I assume is the table name. This happens to me in RC4. I updated bouncer to dev-master and no longer have this issue.

@wojciechgabrys
Copy link

wojciechgabrys commented Feb 23, 2019

Can confirm @zanechua's case.

When creating a new role and ability like this:

Bouncer::allow('Manager')->to('create-roles');
Bouncer::assign('Manager')->to($user);

permissions table's entity_type field is filled with App\Role.

Updating permissions for that role using:

Bouncer::sync($role)->abilities($abilities);

fills permissions table's entity_type field with roles

Updating to dev-master branch fixed this problem – in both cases entity_type fields are filled with roles values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants