Hi, Im using this package in my project. But after i run my phpunit tests i get a strange output in my log file.
[2016-10-28 04:40:17] testing.ALERT: Could not register permissions
[2016-10-28 04:40:42] testing.ALERT: Could not register permissions
[2016-10-28 04:40:42] testing.ALERT: Could not register permissions
[2016-10-28 04:40:42] testing.ALERT: Could not register permissions
[2016-10-28 04:40:43] testing.ALERT: Could not register permissions
[2016-10-28 04:40:43] testing.ALERT: Could not register permissions
[2016-10-28 04:40:43] testing.ALERT: Could not register permissions
[2016-10-28 04:40:43] testing.ALERT: Could not register permissions
[2016-10-28 04:40:43] testing.ALERT: Could not register permissions
[2016-10-28 04:40:44] testing.ALERT: Could not register permissions
[2016-10-28 04:40:44] testing.ALERT: Could not register permissions
[2016-10-28 04:40:44] testing.ALERT: Could not register permissions
[2016-10-28 04:40:44] testing.ALERT: Could not register permissions
[2016-10-28 04:40:45] testing.ALERT: Could not register permissions
[2016-10-28 04:40:45] testing.ALERT: Could not register permissions
[2016-10-28 04:40:45] testing.ALERT: Could not register permissions
[2016-10-28 04:40:45] testing.ALERT: Could not register permissions
[2016-10-28 04:40:46] testing.ALERT: Could not register permissions
[2016-10-28 04:40:46] testing.ALERT: Could not register permissions
[2016-10-28 04:40:46] testing.ALERT: Could not register permissions
Can u help me with it?
What is the content of the exception at this line?
How can i check that?
Just add a dd or var_dump statement there
On Friday, 28 October 2016, Tim Joosten [email protected] wrote:
How can i check that?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/spatie/laravel-permission/issues/132#issuecomment-256964181,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAdiDRmkNtgDMwTRjoMKRQ8sL3nlq3KOks5q4iDXgaJpZM4KjEyk
.
Freek Van der Herten
https://spatie.be
+32 495 84 27 91
Same issue. Laravel 5.3. Setup a simple test case and include the DatabaseMigrations trait:
<?php
use Illuminate\Foundation\Testing\DatabaseMigrations;
class ExampleTest extends TestCase
{
use DatabaseMigrations;
public function testSomething()
{
$this->assertEquals(true,true);
}
}
Run the test :
[2016-10-29 08:03:43] testing.ALERT: Could not register permissions SQLSTATE[HY000]: General error: 1 no such table: permissions (SQL: select * from "permissions")#0 /home/vagrant/m-api/vendor/laravel/framework/src/Illuminate/Database/Connection.php(717): Illuminate\Database\Connection->runQueryCallback('select * from "...', Array, Object(Closure))
#1 /home/vagrant/m-api/vendor/laravel/framework/src/Illuminate/Database/Connection.php(351): Illuminate\Database\Connection->run('select * from "...', Array, Object(Closure))
#2 /home/vagrant/m-api/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(1648): Illuminate\Database\Connection->select('select * from "...', Array, true)
#3 /home/vagrant/m-api/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(1634): Illuminate\Database\Query\Builder->runSelect()
#4 /home/vagrant/m-api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(613): Illuminate\Database\Query\Builder->get(Array)
#5 /home/vagrant/m-api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(318): Illuminate\Database\Eloquent\Builder->getModels(Array)
#6 /home/vagrant/m-api/vendor/spatie/laravel-permission/src/PermissionRegistrar.php(76): Illuminate\Database\Eloquent\Builder->get()
#7 /home/vagrant/m-api/vendor/laravel/framework/src/Illuminate/Cache/Repository.php(349): Spatie\Permission\PermissionRegistrar->Spatie\Permission\{closure}()
#8 /home/vagrant/m-api/vendor/spatie/laravel-permission/src/PermissionRegistrar.php(77): Illuminate\Cache\Repository->rememberForever('spatie.permissi...', Object(Closure))
#9 /home/vagrant/m-api/vendor/spatie/laravel-permission/src/PermissionRegistrar.php(46): Spatie\Permission\PermissionRegistrar->getPermissions()
#10 /home/vagrant/m-api/vendor/spatie/laravel-permission/src/PermissionServiceProvider.php(31): Spatie\Permission\PermissionRegistrar->registerPermissions()
#11 [internal function]: Spatie\Permission\PermissionServiceProvider->boot(Object(Spatie\Permission\PermissionRegistrar))
#12 /home/vagrant/m-api/vendor/laravel/framework/src/Illuminate/Container/Container.php(508): call_user_func_array(Array, Array)
#13 /home/vagrant/m-api/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(769): Illuminate\Container\Container->call(Array)
#14 /home/vagrant/m-api/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(752): Illuminate\Foundation\Application->bootProvider(Object(Spatie\Permission\PermissionServiceProvider))
#15 [internal function]: Illuminate\Foundation\Application->Illuminate\Foundation\{closure}(Object(Spatie\Permission\PermissionServiceProvider), 13)
#16 /home/vagrant/m-api/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(753): array_walk(Array, Object(Closure))
#17 /home/vagrant/m-api/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php(17): Illuminate\Foundation\Application->boot()
#18 /home/vagrant/m-api/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(203): Illuminate\Foundation\Bootstrap\BootProviders->bootstrap(Object(Illuminate\Foundation\Application))
#19 /home/vagrant/m-api/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(262): Illuminate\Foundation\Application->bootstrapWith(Array)
#20 /home/vagrant/m-api/tests/TestCase.php(29): Illuminate\Foundation\Console\Kernel->bootstrap()
#21 /home/vagrant/m-api/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php(91): TestCase->createApplication()
#22 /home/vagrant/m-api/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php(66): Illuminate\Foundation\Testing\TestCase->refreshApplication()
#23 /home/vagrant/m-api/tests/TestCase.php(36): Illuminate\Foundation\Testing\TestCase->setUp()
#24 phar:///usr/local/bin/phpunit/phpunit/Framework/TestCase.php(950): TestCase->setUp()
#25 phar:///usr/local/bin/phpunit/phpunit/Framework/TestResult.php(701): PHPUnit_Framework_TestCase->runBare()
#26 phar:///usr/local/bin/phpunit/phpunit/Framework/TestCase.php(909): PHPUnit_Framework_TestResult->run(Object(Test2))
#27 phar:///usr/local/bin/phpunit/phpunit/Framework/TestSuite.php(753): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult))
#28 phar:///usr/local/bin/phpunit/phpunit/Framework/TestSuite.php(753): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#29 phar:///usr/local/bin/phpunit/phpunit/TextUI/TestRunner.php(465): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#30 phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php(185): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array, true)
#31 phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php(115): PHPUnit_TextUI_Command->run(Array, true)
#32 /usr/local/bin/phpunit(572): PHPUnit_TextUI_Command::main()
#33 {main}
I haven't looked into it any further since my tests (which cover permissions) still work, though the log file is noisy. I'm using a separate sqlite (in memory DB) for testing.
The tests seem to running fine both on my machine and on Travis, so I think there's a problem with your specific setup.
The stack trace seems to indicate that the permissions table is not created, so you might want to look into that.
I have the same problem, it happens when you use :memory: as testing database as it says here @
I can also confirm this happens when using :memory: as a testing database (sqlite)
If change the database to use :memory: but still the tests seem to pass on Travis.
I think @nisbeti figured it out:
When using in memory sqlite database for testing the migrations may not be run until after the boot method, so the $permissionLoader->registerPermissions(); call will fail if called from boot()
He has created a PR for this. I wasn't able to test this myself.
I'm curious @freekmurze do you also use SQLite in :memory: for your tests? Until now I've always been using MySQL with database transactions. Lately (and after starting the TDD course from Adam) I was thinking about switching to SQLite for faster speed in my tests.
All the tests in the package use :memory:
https://github.com/spatie/laravel-permission/blob/master/tests/TestCase.php#L64
Thanks Freek. I'm going to schedule some time next week to figure it out why I'm getting this problem. If I can find it, I will post it. Thanks again!
I finaly figured it out after looking at the TestCase.php from the package! The trick was to add this method to the TestCase.php in my Project:
protected function reloadPermissions()
{
return app(PermissionRegistrar::class)->registerPermissions();
}
And of course call this method in the setUp() of the testcase.
Thanks @stefro, this worked great!!
Most helpful comment
I finaly figured it out after looking at the TestCase.php from the package! The trick was to add this method to the TestCase.php in my Project:
And of course call this method in the setUp() of the testcase.