Questions tagged [laravel-unit-test]

12 questions
2
votes
2 answers

Laravel login test failed in phpunit

I am trying to do login test by phpunit in laravel. I have 5.5 so visit method is not supported. Here is what I am doing public function testLoginPost(){ Session::start(); $response = $this->call('POST', 'login', [ 'email' =>…
Rahman
  • 31
  • 4
1
vote
0 answers

Nova Laravel Unit Testing Expecting Return 201, But Return 403

I'm gonna make a Unit Testing for my resource. Here my testing function below : public function testCreateMyResource() { $user = factory(\App\User::class)->states('admin')->create(); $this->actingAs($user); $data = [ 'Field' =>…
1
vote
2 answers

Undefind withoutExceptionHandling()

I'm trying to run my UnitTest on laravel 6 (windows 10) with the famous: this->withoutExceptionHandling(); But I get this error: Error: Call to undefined method Tests\Unit\ExampleTest::withoutExceptionHandling() I didn't change any setting and…
Mojtaba Barari
  • 1,127
  • 1
  • 15
  • 49
1
vote
1 answer

Laravel unit testing assert functions always failing

I have created a very basic unit testing class under Laravel root-->tests-->Unit-->SimpleTest.php Inside the file i have import the controller class that i need to test. And test function is like this. class SimpleTest extends TestCase { public…
CodeCanyon
  • 929
  • 2
  • 11
  • 36
1
vote
1 answer

phpuint Illuminate\Auth\Access\AuthorizationException: This action is unauthorized

I have index method in controller like this public function index() { $this->authorize('index', Contact::class); .... } and index method in ContactPolicy public function index() { return Auth::user()->can('view_Contact'); } and test…
1
vote
2 answers

Laravel 5.8 Illuminate\Validation\ValidationException: The given data was invalid

I have store method in my controller like this public function store() { request()->validate(['family'=>'required']); User::create(request()->all()); return redirect('/users'); } and test method like this /** @test */ public function…
paranoid
  • 6,799
  • 19
  • 49
  • 86
0
votes
0 answers

How to make unit test for repository with laravel?

Example: I have repository A inside __construct(repo B, repo C) and I want make unit test for function inside repo A but inside it has call b->func_b1 and C->func_c1, how to make? thank you so much! #Repo A public function __construct( …
Luân Tào
  • 11
  • 3
0
votes
1 answer

Laravel 5.7 testing with RefreshDatabase trait throws ErrorException: Trying to access array offset on value of type int

so as I stated in the title, I am working on Laravel 5.7 project and am making first tests in this application (big system). We did not make any tests in here yet, so this problem is the first time here. For every test, this is how the controller…
Lukas Grofcik
  • 457
  • 1
  • 3
  • 15
0
votes
2 answers

How to pass an object as parameter in unit test? (laravel)

I have a data object below that I tried to test using postman. I just don't know how to make this possible also in laravel's unit testing. I have visited this link but it doesn't helped in my case. { "user_id": 1, "name": "juan", …
0
votes
1 answer

ErrorException: Trying to get property 'id' of non-object --Laravel unit test

Recently I am working on a project 'facebook-clone' using Laravel and vue.js. I have been using unit test for the first time. After performing the test I found this error, Error: "ErrorException: Trying to get property 'id' of non-object" For…
0
votes
1 answer

PHPUnit show errors but not show successful alert

I use Laravel 5.8 and phphunit version 7.5. When I run PHPUnit with error, show me error but when not has error show me only this line PHPUnit 7.5.0 by Sebastian Bergmann and contributors. My test class: use Tests\TestCase; class leadTest…
paranoid
  • 6,799
  • 19
  • 49
  • 86
-1
votes
1 answer

laravel unit testing error 'call to member function call() on null'

I want to write a unit test for a form post request. public function addForm(SaveFormRequest $request) { $this->servicelayer->addFormDetails($request->validated()); return redirect->route('register'); } How can I mock…
Balaguru Murugan
  • 463
  • 2
  • 7
  • 21