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

how to upload file with json post request in laravel unit test

i want create a test case for test upload file. it must use my file to test. because i want test upload file excel and import data from this file,after that, check this data from database. i tried: $response =…
The Manh Nguyen
  • 406
  • 6
  • 19
0
votes
2 answers

how to inject a file into http request

i have a test case: $response = $this->postJson('api/unit/'.$unit->id.'/import',['file' =>Storage::get('file/file.xlsx')]); $response->assertJsonFragment(['a'=>'b']); my controller: public function import(Request $request, Unit $unit) { …
The Manh Nguyen
  • 406
  • 6
  • 19
0
votes
1 answer

Dynamic route url change is not reflecting in laravel package

I am creating a package which gives a config file to customize the route url which it will add, I can see config file values in the controller, but same config('app_settings.url') is coming as null in…
Saqueib
  • 3,484
  • 3
  • 33
  • 56
0
votes
0 answers

Event listener never asserts while testing on Laravel / PHPUnit

I'm trying to send a test email and assert (using events) that it was sent. The test runs fine and the event in fact happen (I'm logging the event handler method on LogSendingMessage class), but the expectsEvents never assert, neither before,…
Tiago Gouvêa
  • 15,036
  • 4
  • 75
  • 81
0
votes
0 answers

Laravel testing: coordinate http-request and controller

In the below test we (the humbly well my I am) need to make sure that $utmSource class field received correct value.
Takeshi Tokugawa YD
  • 670
  • 5
  • 40
  • 124
0
votes
1 answer

Mockery. Check parameter on the 100-th call

I'm using Mockery with Laravel 5.6. And currently I need to check what has been passed on the 100-th call. Here is an example check, that I want to perform. Mockery::mock(ShopifySDK::class) ->shouldReceive('get') ->with(['key' =>…
D.R.
  • 2,540
  • 3
  • 24
  • 49
0
votes
1 answer

Response status code [200] is not a redirect status code. Failed asserting that false is true

this is my code laravel unit testing for login public function testClientSucceslogin() { $user = factory(User::class)->create([ 'password' => 'secret', 'status' => User::STATUS_ACTIVE, 'type' => User::TYPE_CLIENT …
flower
  • 989
  • 4
  • 16
  • 34
0
votes
1 answer

return model instance from controller to test class in laravel

i am unit testing in laravel with Phpunit. The situation is i have to return a model instance from the controller back to the testing class. There i will use the attributes of that object to test an assertion. How can i achieve that? Currently i am…
Yeasir Arafat Majumder
  • 1,222
  • 2
  • 15
  • 34
0
votes
1 answer

Testing Laravel custom package by mocking dependency

I'm still in the process of learning about Laravel and Dependency Injection. I understand the concept, but I don't know how to mock a dependency in this specific case: MyController.php use Illuminate\Routing\Controller; use…
TJ is too short
  • 827
  • 3
  • 15
  • 35
0
votes
1 answer

Laravel Testing : Call to undefined function App\Http\Controllers\get()

I am going through a Laravel tutorial and stuck at a "Call to undefined function" error. So far I have 20 Tests with 28 Assertions and only this test fails. I can't find my typo. Tell me please what source code do I have to add additionaly. I am new…
Meteor Newbie
  • 646
  • 2
  • 10
  • 23
0
votes
1 answer

Is dusk is mandatory to write phpunit test cases?how to write phpunit test cases in laravel 5.4?

I am newbie to laravel. I am using laravel 5.4 version, we have requirement of writing phpunit test cases for our application, So I have searched for writing phpunit testcases and also read the documentation in laravel website. I read about the…
0
votes
1 answer

Laravel Trait not found PHP Fatal Error

I am working on a project which has Laravel 5.3 version and using Laravel Infyom Generator, somehow it generated all these traits and other test files such as (ApiTest, RepositoryTest, ...etc). when I try to run PHPUNIT I am getting this error Can…
0
votes
0 answers

Testing a controller method that uses related models in laravel

I am working in laravel-lumen. I have two models. An Organization model and an Apikey model corresponding to an organizations and an apikeys table. The column organization_id in the apikeys table is a foreign key referring to the id field of the…
jai
  • 391
  • 2
  • 6
  • 14
0
votes
1 answer

Testing Vue.js components- Laravel Testing

I am looking at testing some Vue.js components, as part of a Laravel application. So, I have a component that is used in a blade template and makes a GET request during the mounted lifecycle hook. Say this request takes 800 ms. Is it possible to use…
AshMenhennett
  • 1,095
  • 4
  • 14
  • 25
0
votes
2 answers

Error: Base table or view not found when Creating Records on Laravel Test SetUp()?

When creating a record in setUp(): public function setUp(){ parent::setUp(); $company = new App\Company(); $company->company_name = 'MyTest'; $company->save(); } I get the following error: Base table or view not found I am using use…
tread
  • 10,133
  • 17
  • 95
  • 170
1 2 3
11
12