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

laravel testbench error 500 while testing

while testing a laravel package with Orchestral/testbench, I'm getting error 500. but the exception handling do not say much why the error happend. here is the TestCase.php
Mohammad Hossein
  • 404
  • 7
  • 21
0
votes
1 answer

i'm doing test in laravel whene run command php artisan test see this error

PS C:\xampp\htdocs\laravel_testing> PHP artisan test Warning: TTY mode is not supported on the Windows platform. RUNS Tests\Unit\AccountantHelperTest • it can find profit Tests: 3 pending FAIL Tests\Unit\AccountantHelperTest ✕ it can find…
0
votes
1 answer

How to generate Passport oauth_clients for testing database?

I'm testing api endpoint which is authenticated with laravel passport. I'm writing a feature test for checking if oauth/token can return a valid access_token. It is working fine in postman but I am using a different database for testing so when I…
Niloy Quazi
  • 107
  • 2
  • 12
0
votes
0 answers

Laravel Feature Tests: Mock Request URI

So in my application I've some routes that need special treatment which is why I have something like this: Route::prefix('external')->group(function () { Route::any(Request::path(), 'ExternalController@handle'); }); Basically every route which…
suben
  • 43
  • 4
0
votes
2 answers

Laravel 8 - Test suite isn't firing Traits and causes "Integrity constraint violation" errors

I have a Trait that I use on multiple models in my app for setting a UUID on the model:
Andy Holmes
  • 7,817
  • 10
  • 50
  • 83
0
votes
1 answer

PHPunit Mocking not returning specified value

I have a my controller class like below Class UserController { public function getName(){ return "test_name" } public function hello(){ return getName()."!" } } An accompanying unit test as seen below use…
0
votes
1 answer

What happens to Laravel Faker data on teardown or end of testing

I am wanting to write an end to end tests that at some stage through the process will search for a model with a certain id and will update some of the data against it. To avoid touching any real data when run on production environments I know we can…
0
votes
2 answers

How can resolve this error "Uncaught SyntaxError: Cannot use import statement outside a module" in Laravel 8 with Chart consoletvs/charts:7.*?

I have followed all of the steps in [https://chartisan.dev/documentationip top1]. With CDN links everything works fine, I can load any chart.
0
votes
0 answers

How with http-tests make tests on ajax event with form opened?

In laravel 6 / bootstrap 4 / jquery: 3.3.1 app I make http-tests with methods in https://laravel.com/docs/6.x/http-tests I need to make test on editor open event, which is triggered when operator clicks on button : $.ajax({ type: "GET", …
mstdmstd
  • 2,195
  • 17
  • 63
  • 140
0
votes
1 answer

Testing Model with Observer in Laravel 7

I'm trying to test a controller which creates a model. There is an observer that listens the created event on the model. The observer is responsible to dispatch jobs to create sub-models(table entries) that depend on the base model/table. I know…
Alchalade
  • 307
  • 1
  • 5
  • 14
0
votes
2 answers

Testing Laravel lighthouse mutations with database

I am trying to use database and laravel-lighthouse in tests. I am using the traits for GraphQL and Database Testing, mutation works but tests don't. class MyTest extends TestCase{ use MakesGraphQLRequests; use RefreshDatabase; public function…
Juan Caicedo
  • 1,425
  • 18
  • 31
0
votes
1 answer

Laravel testing - dataProvider with files?

I don't know how use the dataProvider for laravel testing with a file field: public function requiredFormValidationProvider() { $faker = Faker::create('es_ES'); $password = $faker->password; $avatar =…
Marc Garcia
  • 1,388
  • 1
  • 9
  • 21
0
votes
1 answer

Laravel - Testing API with data dependencies

I'm working on a Laravel application with authentication. The application also has an API. Now I want to test all the API endpoints of the application. The Problem is, that the some Endpoints Need data in the database to "work" with. How is it…
Mike_NotGuilty
  • 2,253
  • 5
  • 32
  • 64
0
votes
1 answer

Not following how to test broadcast events in laravel

So consider the following event: class UpdateApprovedClinicianCountBroadcastEvent implements ShouldBroadcast { use Dispatchable, InteractsWithSockets; public $count; /** * Create a new event instance. * * @return void …
TheWebs
  • 12,470
  • 30
  • 107
  • 211