PHPUnit : Call to a member function connection() on null - laravel-4

I am using PHPUnit 4 and getting following error while running the unit test:
PHP Fatal error: Call to a member function connection() on null

Related

[Symfony\Component\Debug\Exception\FatalThrowableError]

I am not able to seed the db and having this error. [Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'Channel' not found
This is for laravel 5.3 running mysql.
function run()
{
$channel1=['title'=>'Laravel'];
$channel2=['title'=>'Css3'];
$channel3=['title'=>'Vue.Js'];
$channel4=['title'=>'CakePhp'];
$channel5=['title'=>'Node.js'];
$channel6=['title'=>'Javascript'];
Channel::create($channel1);
Channel::create($channel2);
Channel::create($channel3);
Channel::create($channel4);
Channel::create($channel5);
Channel::create($channel6);
}
I am expecting to seed the db

How to fix null given error in laravel-dump-server?

I added "beyondcode/laravel-dump-server": "^1.2"
to my Laravel 5.7 application and sometimes I got error
[2018-10-18 03:44:02] local.ERROR: Argument 1 passed to Symfony\Component\VarDumper\Dumper\HtmlDumper::dump() must be an instance of Symfony\Component\VarDumper\Cloner\Data, null given, called in /mnt/_work_sdb8/wwwroot/lar/Votes/vendor/symfony/var-dumper/Command/Descriptor/HtmlDescriptor.php on line 47 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Argument 1 passed to Symfony\\Component\\VarDumper\\Dumper\\HtmlDumper::dump() must be an instance of Symfony\\Component\\VarDumper\\Cloner\\Data, null given, called in /mnt/_work_sdb8/wwwroot/lar/Votes/vendor/symfony/var-dumper/Command/Descriptor/HtmlDescriptor.php on line 47 at /mnt/_work_sdb8/wwwroot/lar/Votes/vendor/symfony/var-dumper/Dumper/HtmlDumper.php:111)
[stacktrace]
I run server in my console as :
php artisan dump-server --format=html > public/dump.html
I added wrapper method to commom trait of my app:
<?php
namespace App\Http\Traits;
use File;
use Barryvdh\Debugbar\Facade as Debugbar;
use Carbon\Carbon;
use Config;
use Intervention\Image\Facades\Image as Image;
trait funcsTrait
{
public function d($data)
{
if (empty($data)) {
return;
}
dump($data);
}
and calling this method in my control :
$this->d('ProfilePageTest Test51:: $newUserSessionData::' . print_r($newUserSessionData, true));
And sometimes I got error described above.
In my wrapper I tried to exclude calling of dump with empty value, supposing that empty value could be reason of this error ?
But looks like the reason was different. If there is a way make work it properly?
Thanks!

function connection() on null when use database

i'm new on lumen , i start a lumen project with some table. but when I want get some table use this code
Course::all();
lumen said Call to a member function connection() on null
FatalErrorException in Model.php line 3245:
Call to a member function connection() on null
what's wrong ?
in lumen by default Eloquent is off , you should enable that.
for that you should write this code on your app.php in bootstrap folder
$app->withEloquent()

Laravel PHPUnit Call to a member function connection() on null

I am learning testing on Laravel and I am unable to continue testing Eloquent by this error:
Error: Call to a member function connection() on null
This is my code:
public function test_users_can_follow_each_other()
{
$this->userOne = User::find(1);
$this->userTwo = User::find(2);
$this->userOne->followedBy($this->userTwo->id);
$this->assertTrue($this->userTwo->isFollowedBy($this->userOne->id));
}
I am also using the trait use DatabaseTransactions;
The database is already created with 2 records on users table. Do I need to config anything else, thanks!
replace
PHPUnit\Framework\TestCase
with
Tests\TestCase

Smarty trying to echo the config item its not working

Smarty codeigniter3 print config item not working. I am trying to do the following thing
{$this->session->userdata('userid')}
{$this->config->item(base_url)}
I am getting this error,
A PHP Error was encountered
Severity: Error
Message: Call to a member function item() on a non-object
You need to write a array as data in controller like this
public function myFunction()
{
$data['base']=$this->config->item('base_url');
$data['userid']=$this->session->userdata('userid');
$this->smarty->view('yourview.tpl',$data);
}
then in your smarty page write this
{$userid}{$base}

Resources