Laravel Lumen PHPUnits [ReflectionException] Class command.laracasts.seed does not exist - php

I'm running a PHP project based on Laravel Lumen
Whenever I run my test suite (CodeCeption framework), I run the artisan command $this->artisan("db:Seed"); at the begining of each test (in the setup method) and I get the following error:
[ReflectionException] Class command.laracasts.seed does not exist
#1 /app/vendor/illuminate/container/Container.php:753
#2 /app/vendor/illuminate/container/Container.php:631
#3 /app/vendor/illuminate/container/Container.php:586
#4 /app/vendor/laravel/lumen-framework/src/Application.php:230
#5 /app/vendor/illuminate/console/Application.php:228
#6 /app/vendor/illuminate/console/Application.php:242
#7 /app/vendor/illuminate/support/ServiceProvider.php:267
#8 /app/vendor/illuminate/console/Application.php:147
#9 /app/vendor/illuminate/console/Application.php:70
#10 /app/vendor/laravel/lumen-framework/src/Console/Kernel.php:165
For information I don't get the error if I run one test class at a time, I only get it when I run a test suite.

Related

Yii2 - Getting unknown property: yii\console\Request::userAgent and Class db does not exist

I have a problem with Yii2 framework version 2.0.42.1, with a yii2 advanced app template project.
When I run the yii php script: php yii.
It returns me the following error:
Exception 'yii\base\UnknownPropertyException' with message 'Getting unknown property: yii\console\Request::userAgent'
in /usr/src/app/vendor/yiisoft/yii2/base/Component.php:155
Stack trace:
#0 /usr/src/app/common/components/VerificationNavigateur.php(23): yii\base\Component->__get('userAgent')
#1 /usr/src/app/vendor/yiisoft/yii2/base/BaseObject.php(109): common\components\VerificationNavigateur->init()
#2 /usr/src/app/common/components/AppBootstrap.php(20): yii\base\BaseObject->__construct()
#3 /usr/src/app/vendor/yiisoft/yii2/base/Application.php(333): common\components\AppBootstrap->bootstrap(Object(yii\console\Application))
#4 /usr/src/app/vendor/yiisoft/yii2/base/Application.php(279): yii\base\Application->bootstrap()
#5 /usr/src/app/vendor/yiisoft/yii2/console/Application.php(125): yii\base\Application->init()
#6 /usr/src/app/vendor/yiisoft/yii2/base/BaseObject.php(109): yii\console\Application->init()
#7 /usr/src/app/vendor/yiisoft/yii2/base/Application.php(212): yii\base\BaseObject->__construct(Array)
#8 /usr/src/app/vendor/yiisoft/yii2/console/Application.php(90): yii\base\Application->__construct(Array)
#9 /usr/src/app/yii(22): yii\console\Application->__construct(Array)
Everything was fine until I ran composer install.
Even If I try to downgrade the framework composer require yiisoft/yii2:2.0.41, that doesn't change anything.
When I try to run the php script from the vendor folder everything is fine php vendor/bin/yii
But when I try to run migrations php vendor/bin/yii migrate, this error occurs :
Yii Migration Tool (based on Yii v2.0.42.1)
Exception 'yii\di\NotInstantiableException' with message 'Failed to instantiate component or class "db".'
in /usr/src/app/vendor/yiisoft/yii2/di/Container.php:510
Caused by: Exception 'ReflectionException' with message 'Class db does not exist'
in /usr/src/app/vendor/yiisoft/yii2/di/Container.php:508
Stack trace:
#0 /usr/src/app/vendor/yiisoft/yii2/di/Container.php(508): ReflectionClass->__construct('db')
#1 /usr/src/app/vendor/yiisoft/yii2/di/Container.php(386): yii\di\Container->getDependencies('db')
#2 /usr/src/app/vendor/yiisoft/yii2/di/Container.php(171): yii\di\Container->build('db', Array, Array)
#3 /usr/src/app/vendor/yiisoft/yii2/di/Instance.php(176): yii\di\Container->get('db')
#4 /usr/src/app/vendor/yiisoft/yii2/di/Instance.php(145): yii\di\Instance->get(NULL)
#5 /usr/src/app/vendor/yiisoft/yii2/console/controllers/MigrateController.php(183): yii\di\Instance::ensure(Object(yii\di\Instance), 'yii\\db\\Connecti...')
#6 /usr/src/app/vendor/yiisoft/yii2/base/Controller.php(179): yii\console\controllers\MigrateController->beforeAction(Object(yii\base\InlineAction))
#7 /usr/src/app/vendor/yiisoft/yii2/console/Controller.php(184): yii\base\Controller->runAction('up', Array)
#8 /usr/src/app/vendor/yiisoft/yii2/base/Module.php(534): yii\console\Controller->runAction('up', Array)
#9 /usr/src/app/vendor/yiisoft/yii2/console/Application.php(181): yii\base\Module->runAction('migrate/up', Array)
#10 /usr/src/app/vendor/yiisoft/yii2/console/Application.php(148): yii\console\Application->runAction('migrate/up', Array)
#11 /usr/src/app/vendor/yiisoft/yii2/base/Application.php(392): yii\console\Application->handleRequest(Object(yii\console\Request))
#12 /usr/src/app/vendor/yiisoft/yii2/yii(37): yii\base\Application->run()
#13 {main}
My database configuration connection file didn't change, common/config/main-local.php:
<?php
return [
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'pgsql:host=172.21.0.3;dbname=dev',
'username' => 'dev',
'password' => 'dev',
'charset' => 'utf8',
],
...
PHP version: 7.4
Linux distribution: Ubuntu 20.04
And the Yii2 forum is down for maintenance for a while now.
The problem is in this component common\components\VerificationNavigateur.
You are accessing Yii::$app->request->userAgent in its init() method. This property is only available in yii\web\Request.
In your app the component common\components\VerificationNavigateur is bootstrapped even for your console app. But in that case the property Yii::$app->request contains instance of yii\console\Request that doesn't have property userAgent.
If you don't need that component in your console app you should remove it in your console config. If you need that component in console app you should modify its init() method to check if the Yii::$app->request is instance of yii\web\Request before accessing userAgent property for example like this:
if (\Yii::$app->request instanceof \yii\web\Request) {
// ... do something with Yii::$app->request->userAgent
}
In case of php vendor/bin/yii your app config is not used. That's why that component is not bootstrapped and you don't encounter that error. But, because the config is not loaded, there is no configuration for db component and migration is not working.

500 Error with laravel when creating a new project

I try to learn laravel and after creating a project with.
i created a new project by typing "laravel new projectname" in cmd, installing composer and node.js, changed in cmd to the project directory and installed composer there and tryed to run "php artisan serve" comand. i got the message "Laravel development server started: http://127.0.0.1:8000"
when i open http://127.0.0.1:8000 i get a 500 Error (not from the browser. the error is from laravel).
I have absolutly no idea what could be wrong. I went by 3 guides for starters and they did not have this problem.
Is there anything i can do ti fix this error?
thank you very much in advance
edit: here is the logfile from storage/logs
[2019-10-12 20:13:12] production.ERROR: No application encryption key has been specified. {"exception":"[object] (RuntimeException(code: 0): No application encryption key has been specified. at C:\\Users\\Rjinxil\\testproject\\vendor\\laravel\\framework\\src\\Illuminate\\Encryption\\EncryptionServiceProvider.php:44)
[stacktrace]
#0 C:\\Users\\Rjinxil\\testproject\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\helpers.php(424): Illuminate\\Encryption\\EncryptionServiceProvider->Illuminate\\Encryption\\{closure}(NULL)
#1 C:\\Users\\Rjinxil\\testproject\\vendor\\laravel\\framework\\src\\Illuminate\\Encryption\\EncryptionServiceProvider.php(48): tap(NULL, Object(Closure))
#2 C:\\Users\\Rjinxil\\testproject\\vendor\\laravel\\framework\\src\\Illuminate\\Encryption\\EncryptionServiceProvider.php(24): Illuminate\\Encryption\\EncryptionServiceProvider->key(Array)
#3 C:\\Users\\Rjinxil\\testproject\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(800): Illuminate\\Encryption\\EncryptionServiceProvider->Illuminate\\Encryption\\{closure}(Object(Illuminate\\Foundation\\Application), Array)
#4 C:\\Users\\Rjinxil\\testproject\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(682): Illuminate\\Container\\Container->build(Object(Closure))
#5 C:\\Users\\Rjinxil\\testproject\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(630): Illuminate\\Container\\Container->resolve('encrypter', Array)
#6 C:\\Users\\Rjinxil\\testproject\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Application.php(768): Illuminate\\Container\\Container->make('encrypter', Array)
#7 C:\\Users\\Rjinxil\\testproject\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(946): Illuminate\\Foundation\\Application->make('encrypter')
#8 C:\\Users\\Rjinxil\\testproject\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(874): Illuminate\\Container\\Container->resolveClass(Object(ReflectionParameter))
#9 C:\\Users\\Rjinxil\\testproject\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(835): Illuminate\\Container\\Container->resolveDependencies(Array)
#10 C:\\Users\\Rjinxil\\testproject\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(682): Illuminate\\Container\\Container->build('App\\\\Http\\\\Middle...')
#11 C:\\Users\\Rjinxil\\testproject\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(630): Illuminate\\Container\\Container->resolve('App\\\\Http\\\\Middle...', Array)
#12 C:\\Users\\Rjinxil\\testproject\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Application.php(768): Illuminate\\Container\\Container->make('App\\\\Http\\\\Middle...', Array)
#13 C:\\Users\\Rjinxil\\testproject\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(215): Illuminate\\Foundation\\Application->make('App\\\\Http\\\\Middle...')
#14 C:\\Users\\Rjinxil\\testproject\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(189): Illuminate\\Foundation\\Http\\Kernel->terminateMiddleware(Object(Illuminate\\Http\\Request), Object(Illuminate\\Http\\Response))
#15 C:\\Users\\Rjinxil\\testproject\\public\\index.php(60): Illuminate\\Foundation\\Http\\Kernel->terminate(Object(Illuminate\\Http\\Request), Object(Illuminate\\Http\\Response))
#16 C:\\Users\\Rjinxil\\testproject\\server.php(21): require_once('C:\\\\Users\\\\Rjinxi...')
#17 {main}
"}
So close your terminal session and run this command in your CMD:
php artisan key:generate
in the project folder. Make sure you have .env file created. Then serve your application once again.
Try Below steps :
php artisan config:cache
php artisan cache:clear
php artisan key:generate

array_merge(): Argument #2 is not an array after adding class into providers

I am using pbmedia/laravel-ffmpeg as soon as I installed and added the providers and alias, it shows me the following error. This code was simply working on another machine
array_merge(): Argument #2 is not an array
I have tried the following things
Composer update/ and Fresh install
Cleaning the bootstrap/cache/
Checked the config file for laravel-ffmpeg it's there and fine
Publish the config file using the artisan CLI tool: php artisan vendor:publish --provider="Pbmedia\LaravelFFMpeg\FFMpegServiceProvider"
Here is the portion from laravel.log when I tried to run.
[2019-06-19 00:34:40] local.ERROR: ErrorException: array_merge(): Argument #2 is not an array in /Users/damanmokha/edetyv2/vendor/laravel/framework/src/Illuminate/Support/ServiceProvider.php:59
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'array_merge(): ...', '/Users/damanmok...', 59, Array)
#1 /Users/damanmokha/edetyv2/vendor/laravel/framework/src/Illuminate/Support/ServiceProvider.php(59): array_merge(Array, 1)
#2 /Users/damanmokha/edetyv2/vendor/pbmedia/laravel-ffmpeg/src/FFMpegServiceProvider.php(25): Illuminate\Support\ServiceProvider->mergeConfigFrom('/Users/damanmok...', 'laravel-ffmpeg')
#3 /Users/damanmokha/edetyv2/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(565): Pbmedia\LaravelFFMpeg\FFMpegServiceProvider->register()
#4 /Users/damanmokha/edetyv2/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php(74): Illuminate\Foundation\Application->register(Object(Pbmedia\LaravelFFMpeg\FFMpegServiceProvider))
#5 /Users/damanmokha/edetyv2/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(540): Illuminate\Foundation\ProviderRepository->load(Array)
#6 /Users/damanmokha/edetyv2/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/RegisterProviders.php(17): Illuminate\Foundation\Application->registerConfiguredProviders()
#7 /Users/damanmokha/edetyv2/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(203): Illuminate\Foundation\Bootstrap\RegisterProviders->bootstrap(Object(Illuminate\Foundation\Application))
#8 /Users/damanmokha/edetyv2/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(267): Illuminate\Foundation\Application->bootstrapWith(Array)
#9 /Users/damanmokha/edetyv2/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(113): Illuminate\Foundation\Console\Kernel->bootstrap()
#10 /Users/damanmokha/edetyv2/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 {main}
if I don't add these providers it works fine, but then I am not able to use ffmpeg without that.
Laravel Version 5.3
pbmedia/laravel-ffmpeg 1.3
php version: 7.1

Yii2 console app - cookieValidationKey config errors

I have configured the cookieValidationKey inside my backend\config\main.php and frontend\config\main.php and removed it from common\config\main.php. But when I run php yii inside command line. I get this error.
Even before I set it inside to my backend config the error showed up when I used the command line.
$ php yii
Exception 'yii\base\UnknownPropertyException' with message 'Setting unknown property: yii\console\Request:
:cookieValidationKey'
in D:\web\wamp64\www\html\royall.dev\vendor\yiisoft\yii2\base\Component.php:201
Stack trace:
#0 D:\web\wamp64\www\html\royall.dev\vendor\yiisoft\yii2\BaseYii.php(525): yii\base\Component->__set('cook
ieValidatio...', '9H2hvsco52yQ0N2...')
#1 D:\web\wamp64\www\html\royall.dev\vendor\yiisoft\yii2\base\Object.php(105): yii\BaseYii::configure(Obje
ct(yii\console\Request), Array)
#2 [internal function]: yii\base\Object->__construct(Array)
#3 D:\web\wamp64\www\html\royall.dev\vendor\yiisoft\yii2\di\Container.php(381): ReflectionClass->newInstan
ceArgs(Array)
#4 D:\web\wamp64\www\html\royall.dev\vendor\yiisoft\yii2\di\Container.php(156): yii\di\Container->build('y
ii\\console\\Req...', Array, Array)
#5 D:\web\wamp64\www\html\royall.dev\vendor\yiisoft\yii2\BaseYii.php(344): yii\di\Container->get('yii\\con
sole\\Req...', Array, Array)
#6 D:\web\wamp64\www\html\royall.dev\vendor\yiisoft\yii2\di\ServiceLocator.php(135): yii\BaseYii::createOb
ject(Array)
#7 D:\web\wamp64\www\html\royall.dev\vendor\yiisoft\yii2\console\Application.php(219): yii\di\ServiceLocat
or->get('request')
#8 D:\web\wamp64\www\html\royall.dev\vendor\yiisoft\yii2\base\Application.php(380): yii\console\Applicatio
n->getRequest()
#9 D:\web\wamp64\www\html\royall.dev\yii(27): yii\base\Application->run()
#10 {main}
Why is this happening? I did not have cookieValidationKey inside my console\config\main.php so it should not Popup this error.
I use windows and wamp-server but I tested it on an Ubuntu server and it's returning the same error.
That's because your console command combined all configs before executing the actual action. There are some config params which are invalid to console actions but useful to web requests. The solution is to remove these params before executing console actions.
Add the following line
unset($config['components']['request']);
before
$application = new yii\console\Application($config);
in file yii.
Because I run web server via vagrant, I didn't test if there's side effect to web app run via yii command.

Laravel Excel Installation

I've just used composer to get Maatwebsite Laravel-Excel. I am about to use it but I am brand new to installing/using packages. So far I've only used what is shipped with Laravel.
I'm reading the documentation and am following the steps (I've done the first three steps) but I am confused by this line;
The class is binded to the ioC as excel
$excel = App::make('excel');
I don't really know what most of that means. I have read up a little on ioC and then Dependency Injection (also new to me). But I still don't know - is this part of the docs telling me to do something?? I ran php artisan on the command line (for another purpose) and I got this back;
[2015-04-23 13:42:09] local.ERROR: exception 'BadMethodCallException' with message 'Call to undefined method [package]' in /vagrant/source/laravel-excel/vendor/laravel/framework/src/Illuminate/Support/ServiceProvider.php:226
Stack trace:
#0 /vagrant/source/laravel-excel/vendor/maatwebsite/excel/src/Maatwebsite/Excel/ExcelServiceProvider.php(45): Illuminate\Support\ServiceProvider->__call('package', Array)
#1 /vagrant/source/laravel-excel/vendor/maatwebsite/excel/src/Maatwebsite/Excel/ExcelServiceProvider.php(45): Maatwebsite\Excel\ExcelServiceProvider->package('maatwebsite/exc...')
#2 [internal function]: Maatwebsite\Excel\ExcelServiceProvider->boot()
#3 /vagrant/source/laravel-excel/vendor/laravel/framework/src/Illuminate/Container/Container.php(523): call_user_func_array(Array, Array)
#4 /vagrant/source/laravel-excel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(703): Illuminate\Container\Container->call(Array)
#5 /vagrant/source/laravel-excel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(685): Illuminate\Foundation\Application->bootProvider(Object(Maatwebsite\Excel\ExcelServiceProvider))
#6 [internal function]: Illuminate\Foundation\Application->Illuminate\Foundation\{closure}(Object(Maatwebsite\Excel\ExcelServiceProvider), 19)
#7 /vagrant/source/laravel-excel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(686): array_walk(Array, Object(Closure))
#8 /vagrant/source/laravel-excel/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php(15): Illuminate\Foundation\Application->boot()
#9 /vagrant/source/laravel-excel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(181): Illuminate\Foundation\Bootstrap\BootProviders->bootstrap(Object(Illuminate\Foundation\Application))
#10 /vagrant/source/laravel-excel/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(195): Illuminate\Foundation\Application->bootstrapWith(Array)
#11 /vagrant/source/laravel-excel/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(92): Illuminate\Foundation\Console\Kernel->bootstrap()
#12 /vagrant/source/laravel-excel/artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 {main}
php artisan ran sucessfully when I took out the maatwebsite references in config/app.php - so there must be more to do here but I don't know what.
Looks like the documentation is listing the wrong version. The 1.x branch is meant for Laravel 4.x. The GitHub page provides a better guide for Laravel 5 users. Try changing the version to 2.* in your composer.json and re-run composer update. Add the correct references back to your app.php you should be able to run php artisan without errors.
The App::make('excel') command should also work after that.

Categories