Questions tagged [laravel-testing]

Use this tag for question about Laravel testing

Laravel is built with unit testing in mind. In fact, support for testing with PHPUnit is included out of the box, and a phpunit.xml file is already setup for your application. An example test file is provided in the tests directory.

Defining & Running Tests

To create a test case, simply create a new test file in the tests/Unit or tests/Feature directory. The test class should extend TestCase. You may then define test methods as you normally would when using PHPUnit.

An Example Test Class

class FooTest extends TestCase {

    public function testSomethingIsTrue()
    {
        $this->assertTrue(true);
    }

}

You may run all of the tests for your application by executing the php artisan test (or phpunit) command from your terminal.

Note: If you define your own setUp method, be sure to call parent::setUp.

Reference

177 questions
0
votes
1 answer

laravel windows local phpunit.bat became empty

I have been working away on dusk broswer tests, and went back to some of my phpUnit unit tests, and ran: cd {laravelHomeFolder} {laravelHomeFolder}> vendor\bin\phpunit.bat and to my suprise, nothing happened! I found that the phpunit.bat file was…
NULL pointer
  • 1,116
  • 1
  • 14
  • 27
0
votes
1 answer

How can I share code between Laravel Dusk Browser tests, unit tests, and functional tests

Unit tests created with php artisan make:test -- unit UnitTestClassName extends \Tests\TestCase Functional Tests create with php artisan make:test FunctionalTestClassName also extends \Tests\TestCase \Tests\TestCase extends…
NULL pointer
  • 1,116
  • 1
  • 14
  • 27
0
votes
2 answers

Laravel test. assert exact JSON structure

I have a laravel API project. There is a lot security data, that shouldn't be shown for users in API responses. I need some way to write tests where I can get true if only the response structure is exact same as a pre-set structure in test. So, if…
Denys Siebov
  • 198
  • 4
  • 16
0
votes
1 answer

Echo Warning and notice while testing Laravel project

I want to echo warnings manually in some situation while testing Laravel project.
Amin Shojaei
  • 5,451
  • 2
  • 38
  • 46
0
votes
1 answer

Laravel Testing API Endpoint - POST Parameters Missing

I have a API endpoint that I wish to test, it receives a POST payload. The endpoint basically invokes the Omnipay Sage Pay library to handle a Server Notification. I can POST to this endpoint using Postman client fine, but when using a Laravel…
Snaver
  • 434
  • 3
  • 6
0
votes
2 answers

How to successfully execute test via phpunit within relationship between two models?

I'm new in Laravel. I have 2 tables Productions and Products. Also, I have 2 factories ProductionFactory and ProductFactory. I want to test them via phpunit. Their connection is via production_id. Error is ErrorException: Undefined variable:…
JohnnyJP
  • 7
  • 5
0
votes
1 answer

When I run command phpunit in terminal, I got php warning

When I run a phpunit command in terminal console, I got Php warning. I've tried to run vendor/bin/phpunit but the result is the same. This is an error: PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use…
JohnnyJP
  • 7
  • 5
0
votes
1 answer

Reset Redis database after each test in laravel

In my laravel application, I use Redis to store some cache (e.g. the list of items to show on the front page). I always access Redis through the Facade: Illuminate\Support\Facades\Redis. I created a different Redis database for testing (1 instead of…
gbalduzzi
  • 9,356
  • 28
  • 58
0
votes
1 answer

Test.Error Expected status code 200 but received 200.How to fix it?

I created test for CompanyController, public function testCompanyIndex() { $user = factory(User::class)->create(); $response = $this->actingAs($user, 'web')->get('company/index'); $response->assertStatus('200'); …
Loctarogar
  • 540
  • 3
  • 10
  • 29
0
votes
1 answer

How to run php tests in Laravel project for my own package?

I have my own Laravel package and I want to be able to write and create tests for it. My project is installed on the following directory within my project ROOT/CompayName/package-name. My tests are located in ROOT/CompanyName/package-name/tests…
Junior
  • 11,602
  • 27
  • 106
  • 212
0
votes
1 answer

Laravel 5.6: assertSessionHasErrors resulting in "Integrity constraint violation: 19 NOT NULL constraint failed" Error

I'm trying to set up a test that checks that incomplete forms cannot be submitted to a database and I keep running into issues, currently every time I run phpunit this is what I get: My test is set up as so: public function…
EJ Willis
  • 89
  • 1
  • 11
0
votes
0 answers

Cannot coverage phpunit report to html

when i run this command: ./vendor/bin/phpunit --coverage-html testResult it is runing, but export an error: No code coverage driver is available and this is php.ini: [xdebug] zend_extension =…
The Manh Nguyen
  • 406
  • 6
  • 19
0
votes
0 answers

How to test array console input

I prefer to use "almost TDD" in my daily workflow. And a few days ago I've faced this issue. Imagine a command with such signature. protected $signature = 'sync:store {--storeId= : Sync stores}'; In my test-suite I've added …
D.R.
  • 2,540
  • 3
  • 24
  • 49
0
votes
2 answers

disable exception handling in laravel test

I've been trying to disable exception handling in my test so I can see the errors, but it's not working even if I intentionally break the code. I'm just getting this generic response and it's not helping much. Invalid JSON was returned from the…
Daniel
  • 67
  • 1
  • 7
0
votes
1 answer

File created in testing is not uploading to public folder as default using move method in Laravel 5.7

I am trying to create a test in laravel 5.7 that involves creating a fake image object which is further consumed by a service that moves it to a desired directory in public folder. My service works fine if I upload file through browser but if I run…
DevOps
  • 438
  • 6
  • 21