@bobbybouwmann I have defined them within autoload-dev
"autoload-dev": {
"classmap": [
"tests/TestCase.php",
"tests/traits/MakeCustomerTrait.php",
"tests/traits/MakeFileTrait.php",
"tests/traits/MakeUserTrait.php",
"tests/ApiTestTrait.php"
]
It worked! but this time when I do on testUserCanLogin I am getting this error :(
Caused by
ErrorException: Trying to get property of non-object in C:\Users\ahmed\dev\myproject\app\Http\Controllers\CustomerController.php:325
Stack trace:
#0 C:\Users\ahmed\dev\myproject\app\Http\Controllers\CustomerController.php(325): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Trying to get p...', 'C:\\Users\\ahmed\\...', 325, Array)
#1 [internal function]: App\Http\Controllers\CustomerController->getCustomerPanel()
LoginTest Code
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class LoginTest extends TestCase
{
use DatabaseTransactions;
/**
* A basic test example.
*
* @return void
*/
public function testLoginUser()
{
$user = factory(App\Models\User::class)->create([
'password' => bcrypt('testpass1234'),
]);
$this->assertFalse(Auth::check());
$this->visit('/login')
->type($user->email, 'email')
->type('testpass1234', 'password')
->press('Login')
->seePageIs('/')
$this->assertTrue(Auth::check());
}
}
and getCustomerPanel code inside CustomerController
//Customer Panel
public function getCustomerPanel(){
$user = User::find(Auth::user()->id);
$news = News::orderBy('created_at', 'desc')->get();
if ($user->isAdmin()){
$devices= Device::all();
}
else {
$devices = $user->customer->devices;
}
return view('customers.customerpanel.index')
->with('devices', $devices)
->with('news', $news);
}