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
0 answers

Laravel SQLite doesn't deleting in cascade

I am using the SQLite in memory to test my Laravel application. Then i define one table Enterprise this way: Schema::create('Enterprise', function(Blueprint $table) { $table->increments('id'); …
Claudivan
  • 304
  • 2
  • 3
0
votes
1 answer

Laravel PHPUnit PDOException exception

I don't know why when I run a PHPUnit test, I get the following error: PDOException: SQLSTATE[HY000] [2002] No such file or directory My testing environment database setting is: return [ 'fetch' => PDO::FETCH_CLASS, 'default' =>…
Kousha
  • 32,871
  • 51
  • 172
  • 296
0
votes
1 answer

Authentication test running strange

I've just tried to write a simple test for Auth: use Mockery as m; ... public function testHomeWhenUserIsNotAuthenticatedThenRedirectToWelcome() { $auth = m::mock('Illuminate\Auth\AuthManager'); …
Pete Houston
  • 14,931
  • 6
  • 47
  • 60
-1
votes
0 answers

How to test cast class in laravel

UserTest class : // test birth_date cast class public function testBirthDateCasting() { $username = 'ali'; // test get method $user = User::factory()->create([ User::USERNAME => $username, User::BIRTH_DATE =>…
Ali Salehi
  • 23
  • 1
  • 8
-1
votes
2 answers

Why I got Unknown option "--env" error making tests?

Making tests ("phpunit/phpunit": "^9.5.10") for laravel ("laravel/framework": "^9.2") site I want to use .env.testing file But I got error running command : $ vendor/bin/phpunit tests/Feature/PagesCrudTest.php --env=testing Unknown option…
Petro Gromovo
  • 1,755
  • 5
  • 33
  • 91
-1
votes
1 answer

how to write mock test in laravel (IOC)

i dont know how to write mock test for my service here is my compressContract Interface interface compressContract { public function compress(); } here is my ZipCompress class
Abbas
  • 117
  • 10
-1
votes
2 answers

Laravel test unable to find vendor class

I'm using laravel7 and codeception; and I have an Api test class called abcCest located inside test/api folder. it looks like this:
Alladin
  • 1,010
  • 3
  • 27
  • 45
-1
votes
1 answer

Laravel request()->all() is empty in booted function when running tests

I created a trait sets up some Global Scopes based on the query parameters. It does that by reading from the request() helper and reading the query parameters from the url. Below is the start of the trait:
Gijs Beijer
  • 560
  • 5
  • 19
-1
votes
1 answer

All test failing after update from laravel 7 to laravel 8

After update from laravel 7 to version 8 all test failing with same error: Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 no such index: IDX_426EF39216FE72E1 (SQL: DROP INDEX IDX_426EF39216FE72E1) I am also using…
knubbe
  • 1,132
  • 2
  • 12
  • 21
-1
votes
1 answer

A facade root has not been set

Laravel 6.5 Laravel Browser Kit ^5.1 I am creating my own packages for something I building and one is causing the issue at hand: A facade root has not been set. when I run my tests. This is routes file App\Game\routes\web.php:
TheWebs
  • 12,470
  • 30
  • 107
  • 211
-1
votes
1 answer

Laravel header null on test

I'm building a multitenancy api with Laravel based on Account Model, i determine the tennant in use by the request reader "Account" by using a trait (AccountScoped) on all tenant models, everything is working on postman, but whyle testing the header…
1 2 3
11
12