Browse AI Field GuideForum Podcast
All ThreadsLeaderboard
  1. Discussions

    1. Popular This Week
    2. Popular All Time
    3. Solved
    4. Unsolved
    5. No Replies Yet

bwrice's avatar

Anyone know a good way to test "then" logic with Laravel 8's new queue batching?

If I have some code like this: Bus::batch([ new FinalizeOrder, new FinalizeOrder, new FinalizeOrder ])->then(function () { CreateOrderReport::dispatch(); })->dispatch(); I want to assert the CreateOrderReport was queued, but when I use Queue::fake(), "then()" never runs because the batched

bwrice's avatar
bwrice's avatar coderjono@...4yrs agoTesting
5
1
Last reply by [email protected] 4yrs ago
gitwithravish's avatar

Cannot open test file

Can someone explain this? This fails vendor/bin/phpunit Tests/Unit/ProductTest.php // Cannot open file "/tests/unit/ProductTest.php" This works vendor/bin/phpunit --filter testAProductHasName

gitwithravish's avatar
gitwithravish's avatar Sinnbeck5yrs agoTesting
1
1
Last reply by Sinnbeck 5yrs ago
Antonella's avatar

Test Mail laravel 8x

about this episode: https://laracasts.com/series/phpunit-testing-in-laravel/episodes/12 Since this episode was recorded in 2016 I wonder if the proposed method is still valid even with Laravel version 8. I also wonder if other more “ou of the box” methods have been planned at the moment.

Antonella's avatar
Antonella's avatar bugsysha5yrs agoTesting
1
1
Last reply by bugsysha 5yrs ago
EckyEckyPtang's avatar

Laravel 8: phpunit giving error on test

Since today, when running phpunit tests, I get: Illuminate\Contracts\Container\BindingResolutionException: Target class [DatabaseSeeder] does not exist. That class is there under the database/seeds directory. I don't know if this is related, but I recently upgraded to Laravel 8 and also used the new schema dump features and pruned all migrations. PHPunit is using an in-memory s

EckyEckyPtang's avatar
EckyEckyPtang's avatar 4unkur5yrs agoTesting
10
1
Last reply by 4unkur 5yrs ago
Antonella's avatar

assert error cypress test E2E expected { Object (userInvocationStack, specWindow, ...) }

I have this table with the following structure: <tr> <th class="px-4 py-6">id</th> <th class="px-4 py-6">status</th> <th class="px-4 py-6">date</th> </tr> <tr id="1"> <td class="border-0 px-4 py-6"><a href="/1">1</a></td> <

Antonella's avatar
Antonella's avatar Antonella5yrs agoTesting
0
1
futurefuture's avatar

schema:dump test sqlite

Love the idea of this feature in L8! However, I am using sqlite in memory for phpunit - anyone know how to implement the schema:dump just for sqlite in memory for tests??

futurefuture's avatar
futurefuture's avatar futurefutu...5yrs agoTesting
3
1
Last reply by futurefuture 5yrs ago
Ajvanho's avatar

Feature test, expected ExactJson

How to get the expected form of json. Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ -'{"data":{"childrens":{"name":"Dr.","slug":"dr"},"name":"Prof.","slug":"prof"}}' +'{"data":[{"childrens":[{"name":"Dr.","

Ajvanho's avatar
Ajvanho's avatar IvanRadoje...5yrs agoLaravel
2
1
Last reply by IvanRadojevic 5yrs ago
justageek's avatar

Jeffrey's test setup

I am watching the what's new in Laravel 8, and I'm curious how Jeffrey can just create a new project and it instantly works, is he using Homestead with some special config or something else, the Laravel built in server?

justageek's avatar
justageek's avatar MarianoMor...5yrs agoLaravel
3
1
Last reply by MarianoMoreyra 5yrs ago
Alphyo's avatar

[Homestead/newbie question] I finally managed to have my first test app up and running. Please, could you tell me how to resume it after restarting/shutting down my laptop?

As per title, the whole process will give me nightmares. Anyway, how do you guys proceed when you have to restart the homestead server and have the site up and running to keep working with it the day after? Should I git bash the Homestead(master) folder under C:\Users\myname\Homestead, running vagrant up, then vagrant ssh? Or should I do the above in the actual project folder?

Alphyo's avatar
Alphyo's avatar Alphyo5yrs agoLaravel
2
1
Last reply by Alphyo 5yrs ago
nafeeur10's avatar

How to Test Get Request using Postman for Laravel API

I am new in Laravel API. Route::group([ 'prefix' => 'data', ], function () { Route::get('stripeKeyStore', 'UserSettingController@stripeKeyStore'); }); This is my api.php route. public function stripeKeyStore() { return "GET WORKING"; //response()->json([$request->all()]); } This is the Function. Now I am trying to Access this using Postm

nafeeur10's avatar
nafeeur10's avatar s4muel5yrs agoLaravel
7
2
Last reply by s4muel 5yrs ago
manuks's avatar

Throttle Middleware fails on multiple ajax test

I am using laravel 5.6, the following resources are used Route::any('throttle3', function(){ return response()->json(['status'=>'success','message'=>'asasas']); })->middleware('throttle:1,0.25'); I have added 4 ajax request in a js function when I call the function first 3 of the request get success and last one request get blocked by Throttle. in my concept first r

manuks's avatar
manuks's avatar manuks5yrs agoLaravel
0
1
wipflash's avatar

Mutation test are failing

My mutation tests are failing with foreach --- Original +++ New @@ @@ { $databases = $request->get("databases"); if (!empty($databases)) { - foreach ($databases as $group) { + foreach (array() as $group) { MigrationProcessor::migrate($group); } }

wipflash's avatar
wipflash's avatar wipflash5yrs agoTesting
0
1
podu-file-plus's avatar

php artisan test not defined

Hi, I'm upgrading my Laravel Application but running my tests doesn't work. I get the error "Command "test" is not defined. Any pointers here?

podu-file-plus's avatar
podu-file-plus's avatar podu-file-...6yrs agoGeneral
2
1
Last reply by podu-file-plus 6yrs ago
Pixelairport's avatar

Get route in feature test

I started with testing and found a lot of examples with: $response = $this->get('/'); But is it also possible to do something like this: $response = $this->route('page.en.cart'); or $response = $this->get(route('page.en.cart')); Because nothing works... Maybe it is a bad idea, but I'm a testing beginner, and this would sound better than use path/url for me. Am I wrong?

Pixelairport's avatar
Pixelairport's avatar Pixelairpo...6yrs agoTesting
3
1
Last reply by Pixelairport 6yrs ago
canadianlover's avatar

PHPUnit test errors after upgrading Homestead

So a couple of days ago I was working on my code when I noticed my Homestead box was crawling on my Windows 10 machine, so I switch over to the NFS file system. One thing led to another where I had to update everything. I updated to Homestead v10 beta and booted up the machine. Now when I run phpunit I get the following 70) Tests\Feature\ReadThreadsTest::test_a_user_can_reque

canadianlover's avatar
canadianlover's avatar canadianlo...6yrs agoTesting
1
1
Last reply by canadianlover 6yrs ago
ddesyllas's avatar

Why by running migrate:refresh on test setUp phase fails to run the migration scripts

On a legacy projects we started to implement migration scripts upon a pre-existing database schema, so using the migration scripts we are able to update the schema BUT NOT to create the database schema from scratch because the migrations run upon a pre-existing schema existed prior even starting writing migrations for it. The approach we use for testing is as follows: namespace

ddesyllas's avatar
ddesyllas's avatar ddesyllas6yrs agoTesting
2
1
Last reply by ddesyllas 6yrs ago
trevorpan's avatar

Test code or tested code did not (only) close its own output buffers & actingAs()

https://laracasts.com/discuss/channels/testing/php-unit-risky-test-whats-the-cause-of-it-and-how-to-avoid Have an unusual error here. It seems to be related to a brew update, but I'm not certain. At any rate I went through the blade views on the risky tests as the above post mentions. That does not seem to have fixed the error. I am concerned it may be a session issue as the fa

trevorpan's avatar
trevorpan's avatar Disciple1yr agoTesting
7
15
Last reply by Disciple 1yr ago
fylzero's avatar

If you are testing with Dusk, do you need to also test with Jest?

I'm wondering if there is strong value in pulling Jest via vue-test-utils into a project? I haven't done much testing of Javascript and I'm looking for some thoughts and opinions on if pulling Jest into the project is worth the effort or if just doing wide tests on the front end is good enough? I realize this is a broad question. Feel free to link to useful articles on the sub

fylzero's avatar
fylzero's avatar fylzero6yrs agoTesting
1
1
Last reply by fylzero 6yrs ago
mstdmstd's avatar

How to test sendgrid email with mailtrap for testing?

Hello, In my Laravel 7.6 app I use sendgrid for email sending with code in control like : \Mail ::to($newContactUs->author_email)-> send(new SendgridMail('emails/contact_us_was_sent', $newContactUs->author_email, '', $subject, $additiveVars, $attachFiles)); with class in app/Mail/SendgridMail.php : <?php namespace App\Mail; use Illuminate\Bus\Queueable;

mstdmstd's avatar
mstdmstd's avatar guybrush_t...6yrs agoLaravel
3
1
Last reply by guybrush_threepwood 6yrs ago
mcbates's avatar

How to assert mail subject and from in test (Laravel v7.8.1)

I fail to assert from and subject in my tests in latest Laravel 7.8.1 use App\Mail\ContactUserMail; … public function testExample() { Mail::fake(); $this->get('/'); Mail::assertSent(ContactUserMail::class, function ($mail) { dd($mail->subject, $mail->from); }); } // ContactUserMail … public function build() {

mcbates's avatar
mcbates's avatar resohead6yrs agoGeneral
1
1
Last reply by resohead 6yrs ago
mahmoudghalayini's avatar

Test that HTTP error code 401 is returned when user is not authenticated

I want to check if use is authenticated or not.

mahmoudghalayini's avatar
mahmoudghalayini's avatar Tray26yrs agoTesting
4
1
Last reply by Tray2 6yrs ago
mcbates's avatar

How to use model factory as setup in multiple test files?

Almost all my tests need a season (as in sports) to be set to run properly. For example every match needs a season that is assigned to it. Right now, in nearly all tests, I need to set up factory(Season::class)->create(). My first idea was to use a setup function function setUp() { factory(Season::class)->create(); parent::setUp(); } Or even put in the global setUp()

mcbates's avatar
mcbates's avatar mcbates6yrs agoGeneral
1
2
Last reply by mcbates 6yrs ago
bngaard's avatar

Valet not working - Opening a google when using .test

Hi, I am new to Laravel and PHP in general. I just completed the intro-videos on Laravel 6, and having issues with Valet. I previously had MAMP/MAMP PRO installed, but its not uninstalled as I followed the instructions and installed PHP and MySQL via Homebrew as per instruction video. I also installed Valet, and followed the instructions, but for some reason it is not working.

bngaard's avatar
bngaard's avatar jeff.held5yrs agoGeneral
2
1
Last reply by jeff.held 5yrs ago
ziggyspider's avatar

Browser Sync with a .test domain NEVER works.

I use laravel homestead by project, so I have this: mix.browserSync({ proxy: "https://mysite.test", host: "mysite.test", port: 3000, open: "external" }); the thing open the browser to: https://mysite.test:3001 and don't show the site, blank page. if I manually go to just https://mysite.test it works. first, why if I say I want port

ziggyspider's avatar
ziggyspider's avatar ziggyspide...6yrs agoMix
0
1
sfsccn's avatar

How to test response content is an exact match?

I'm new to Laravel and am tinkering with tests. The following tests for a substring in the response: $response = $this->get('/hello'); $response->assertSee('Hello World!'); I didn't find a assertion for equality so I'm wondering how to do this. The following seems to work: $response = $this->get('/hello'); $content = $response->getContent(); $this->assertEquals(

sfsccn's avatar
sfsccn's avatar Tray26yrs agoTesting
1
7
Last reply by Tray2 6yrs ago
dan3460's avatar

Selecting using test in model

On a model i have the following: public function granted() { if (Shares::where('albums_id', $this->id) ->where('users_id', Auth::user()->id)) { return true; } else { return false; } } I'm trying to select albums where granted returns true but I'm blanking on how to do it. I wanted to write somethi

dan3460's avatar
dan3460's avatar dan34606yrs agoLaravel
7
1
Last reply by dan3460 6yrs ago
abkrim's avatar

Complete Nova Serie with minimal chapter about how to test with Nova

Hi. I think it would be very good for the community, one more chapter of Nova, in which the issue of testing with Nova will be addressed, which does not have much doc or many articles published on the network.

abkrim's avatar
abkrim's avatar bugsysha6yrs agoRequests
7
2
Last reply by bugsysha 6yrs ago
twiggy99999's avatar

Using the Laravel test suite outside of Laravel

I have inherited a super legacy project that unfortunately I can't convert to Laravel due to time/budget constraints. It has zero tests so I've started adding in Unit tests using PHPUnit. However, when it comes to acceptance/integration tests I'm wondering what the best approach would be? Most online guides for generic PHP push towards setting up a Selenium server but AFAIK Lar

twiggy99999's avatar
twiggy99999's avatar twiggy9999...6yrs agoTesting
5
1
Last reply by twiggy99999 6yrs ago
shantodev's avatar

Run test in Laravel Dusk

Hi, Is there any way to run any specific task in Laravel Dusk? For example, I want to run CommentPageTest.php only instead of all.

shantodev's avatar
shantodev's avatar fylzero6yrs agoTesting
2
1
Last reply by fylzero 6yrs ago
harshamv's avatar

Using .test domain for development in Ubuntu

We are developing multiple subdomain based namespaces in our app so we want to have a local domain to be able to use a subdomain in our development. I am doing the following configuration in the apache available sites but not able to serve the app in the browser. <VirtualHost *:80> ServerAlias skreem.test DocumentRoot /home/admini/Desktop/skreemProduct/public/

harshamv's avatar
harshamv's avatar Sinnbeck6yrs agoLaravel
11
1
Last reply by Sinnbeck 6yrs ago
rhand's avatar

Dusk: Load password into test based on user chosen

Is there an easy way in Laravel Dusk to type in a password you grab from the database based on username? I would like to leave tests a little cleaner. So I would like to pick a user, but with it load the password and then login. How can I make this happen?

rhand's avatar
rhand's avatar rhand6yrs agoLaravel
0
1
duellsy's avatar

How can I test a multi-tenant Postgres app with in memory sqlite?

With our app, we're using Postgres as our DB. We have a public schema that houses all shared data, then each customer has their own schema (company_[ID]) with their own set of identical tables. When a new customer comes on board, we create a new schema for them and migrate all tables to get them up to speed instantly. When it comes to testing though, I'm struggling to find if t

duellsy's avatar
duellsy's avatar duellsy6yrs agoTesting
0
1
jeFFF's avatar

Deploy migrations for test env only

Hello there, I think the question is explicit but let be more precise. A client of mine have a DB which is created and seeded by his system, on top of that I have a few migrations made by Laravel. For testing purposes I need to create Objects created by the tables of my client so I want to create migrations for these "outside" and apply this only in the testing enviro

jeFFF's avatar
jeFFF's avatar da_Mask3yrs agoTesting
7
7
Last reply by da_Mask 3yrs ago
Omda's avatar

My factory is not applied to my test cases

i am working with phpunit when i create model using factory is not create the field i was put in UserFactory, even if i delete UserFactory it created fields, i dont know what is going on.. this userFactory file use Faker\Generator as Faker; $factory->define(\App\User::class, function (Faker $faker) { static $password; return [ 'name' => $faker->name,

Omda's avatar
Omda's avatar Omda6yrs agoTesting
12
2
Last reply by Omda 6yrs ago
derrickrozay's avatar

Laravel Unit Test - how to get meaningful output?

I am using Laravel 5.8 and I am trying to run tests using phpunit in my console but I keep getting Expected status code 200 but received 409. Failed asserting that false is true.. I have validation errors set to return 409, however this error tells me nothing. How can I output or view more meaningful output like the full exception instead of this error message which doesn't hel

derrickrozay's avatar
derrickrozay's avatar ftiersch6yrs agoTesting
3
1
Last reply by ftiersch 6yrs ago
nashan's avatar

When running phpunit test following Error occurs in Building Laravel App with TDD episode 5

vendor/bin/phpunit tests/Feature/ProjectsTest.php PHPUnit 7.5.14 by Sebastian Bergmann and contributors. E.EFF 5 / 5 (100%) Time: 17.61 seconds, Memory: 22.00 MB There were 2 errors: Tests\Feature\ProjectsTest::a_user_can_create_a_project Illuminate\Session\TokenMismatchException: CSRF token mismatch.

nashan's avatar
nashan's avatar nashan6yrs agoLaravel
6
3
Last reply by nashan 6yrs ago
ThePoet444's avatar

Prevent specific migration during test

I have a couple of migrations that basically import data from our old DB that is horribly constructed to a new DB that is slightly less horrible. Probably should be a seeder now that I think about it.. but anyway. I don't need these migrations to run during my tests, the others I need. Is there a command, or a flag I can set somewhere that will prevent certain migrations from r

ThePoet444's avatar
ThePoet444's avatar ThePoet4446yrs agoGeneral
2
1
Last reply by ThePoet444 6yrs ago
SarahS's avatar

Create problem in test

I'm setting up tests to start adding recording activity in my app (like I the Birdboard course). I have this function: function creating_a_client_generates_activity() { $client = factory('App\Client')->create(); $this->assertCount(1, $client->activity); } But when I run it I get: Tests\Feature\ActivityFeedTest::creating_a_client_generates_activity T

SarahS's avatar
SarahS's avatar SarahS746yrs agoLaravel
2
1
Last reply by SarahS74 6yrs ago
BrownieCoffee's avatar

unexpected errors for my test

Hello, I on my tests yet and I have unexpected errors. ............ 23 / 23 (100%) Time: 30.1 seconds, Memory: 30.00 MB There was 1 failure: 1) Tests\Feature\ProjectCreationTest::the_fields_are_filled Session has unexpected errors: [ "Il semblerait que ce titre soit déjà pris", "The thumbnail must be an image

BrownieCoffee's avatar
BrownieCoffee's avatar BrownieCof...6yrs agoTesting
5
1
Last reply by BrownieCoffee 6yrs ago
ahmadsalah's avatar

Handle differences between SQLite and MySQL in test environment

I like to use in-memory SQLite for testing but I always get stuck on the differences between the two for example, regex and full-text search indices are diffrent so how you cope with that?

ahmadsalah's avatar
ahmadsalah's avatar Tray26yrs agoTesting
1
1
Last reply by Tray2 6yrs ago
MiguelStevens's avatar

Method for reusing test data?

I have the following tests public function testReturnsDifferenceInRows() { $eventDate = factory(EventDate::class)->create([ 'id' => 3, 'date_from' => Carbon::now(), 'date_until' => Carbon::now()->addDay(5), 'time_from' => '08:00', 'time_until' => '08:00' ]); $this->a

MiguelStevens's avatar
MiguelStevens's avatar mike.f6yrs agoTesting
3
2
Last reply by mike.f 6yrs ago
giorg's avatar

test not working

Hi, I wrote these 2 tests that are not working: public function testUpdate() { $deposit = factory(Deposit::class, 1)->create(); $deposit->nome = 'armando'; $this->post('deposits/' . $deposit[0]->id_deposito, $deposit[0]->toArray()); $this->assertDatabaseHas('deposito',['id_deposito'=> $deposit[0]->id_deposito , 'nome' =

giorg's avatar
giorg's avatar giorg6yrs agoLaravel
9
2
Last reply by giorg 6yrs ago
emailhelpdesk's avatar

laracasts test dummy without laravel

I've started using laracasts/integrated on my Zend project, and am trying to figure out if I can use laracasts/test dummy too. I can't see how the database connection and models would work. Is this not possible?

emailhelpdesk's avatar
emailhelpdesk's avatar emailhelpd...6yrs agoLaravel
2
1
Last reply by emailhelpdesk 6yrs ago
speedydan's avatar

Regex to test if text contains a URL

Hey, I have a text field that I'm trying to validate where users should not be able to paste in URL's. I kinda had the regex rule working for this, but it was failing when someone added any words that included com - like company for example. Is anyone able to help me out here? :-)

speedydan's avatar
speedydan's avatar speedydan7yrs agoLaravel
3
1
Last reply by speedydan 7yrs ago
aadityarajv's avatar

When i created a new test to delete th replied with the thread, the users profile activity feed not showing and i'm getting this failure in the test..

There was 1 failure: Tests\Feature\CreateThreadsTest::authorized_user_can_delete_a_thread Failed asserting that a row in the table [activities] does not match the attributes { "subject_id": 1, "subject_type": "App\Reply" }. Found: [ { "id": "2", "user_id": "1", "subject_id": "1", "s

aadityarajv's avatar
aadityarajv's avatar aadityaraj...7yrs agoLaravel
0
1
mohammadkaab's avatar

Migrate:rollback Is not working when test stop

Hi guys I have met a really new strange problem, Actually, I have started writing tests for my code (EtoE), now when I want to see the response of the API I need to put dd and check if the API contains the response or not. The problem Is that when DD stops the code. on the next tests, it'll throw an error that XTable already exists which this means that when my DD stopped the c

mohammadkaab's avatar
mohammadkaab's avatar Tray27yrs agoTesting
5
1
Last reply by Tray2 7yrs ago
HarshitBatra's avatar

A User Has a Profile Episode Test Fail due to certain usernames, works in browser for names without special character.

I followed this https://laracasts.com/series/lets-build-a-forum-with-laravel/episodes/22 and created user profiles, when tested in browser some profiles with names such as "John Doe" appear and work fine but other with names like "Mr. Alphonso Osinski" seem to get [Not Found] page with this message: [The requested resource /user/Mr.%20Alphonso%20Osinski was

HarshitBatra's avatar
HarshitBatra's avatar HarshitBat...7yrs agoLaravel
8
3
Last reply by HarshitBatra 7yrs ago
mohammadkaab's avatar

Automatically checks if code contains test or not

Hi guys I'm wondering if there is a way to automatically check the pull-requests code and also check if the code contains tests.

mohammadkaab's avatar
mohammadkaab's avatar mohammadka...7yrs agoLaravel
2
4
Last reply by mohammadkaab 7yrs ago
alois's avatar

Chaining fresh() in Model Methods for Test to Pass

Is it acceptable to chain fresh() in a method of a model so that PHPUnit will return successful? Is there a downside to it?

alois's avatar
alois's avatar tomopongra...7yrs agoLaravel
1
1
Last reply by tomopongrac 7yrs ago
jay_singulara_tech's avatar

Error in unit test when using setUp() function

Getting an error after I add the setUp() function. Also, PHPStorm puts a red underline below the setUp() function name. The code looks to me, exactly like in the lesson but... I get this error from PHPUnit Fatal error: Declaration of Tests\Unit\UserTest::setUp() must be compatible with Illuminate\Foundation\Testing\TestCase::setUp(): void in C:\Projects\MyProject\tests\Unit\Use

jay_singulara_tech's avatar
jay_singulara_tech's avatar codingstuf...3yrs agoLaravel
9
4
Last reply by codingstuff91 3yrs ago

Want us to email you occasionally with Laracasts news?

Nine out of ten doctors recommend Laracasts over competing brands. Come inside, see for yourself, and massively level up your development skills in the process.

Learn
BrowseSeriesCreatorSeriesLaravel PathLarabitsPlayground
Discuss
ForumPodcastSupport
Extras
Gift CertificatesApparelFAQiOS AppTerms
Social
X(Twitter)TikTokYoutube

© Laracasts 2026. All rights reserved. Yes, all of them. That means you, Todd.

Proudly hosted with Laravel Forge and DigitalOcean.

Want us to email you occasionally with Laracasts news?

Nine out of ten doctors recommend Laracasts over competing brands. Come inside, see for yourself, and massively level up your development skills in the process.

Learn
BrowseSeriesCreatorSeriesLaravel PathLarabitsPlayground
Discuss
ForumPodcastSupport
Extras
Gift CertificatesApparelFAQiOS AppTerms
Social
X(Twitter)TikTokYoutube

© Laracasts 2026. All rights reserved. Yes, all of them. That means you, Todd.

Proudly hosted with Laravel Forge and DigitalOcean.