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

keizah7's avatar

Laravel 8 example test factory

I created new laravel project and seems that factories is not working.. Process finished with exit code 11 I have another project with laravel 8, and tests are running successfully with factories.. Where problem can be? /** * A basic test example. * * @return void */ public function testBasicTest() { dd(Category::factory()->create()); $response = $this->get('/

keizah7's avatar
keizah7's avatar keizah5yrs agoTesting
1
1
Last reply by keizah 5yrs ago
gadreel's avatar

PHPUnit runs only one test.

Hi, I am trying to test a sample class and and when I run vendor/bin/phpunit it only runs one test and stops. For example for the below it just outputs a dot (.) that according to the documentation it pass the tests. But if you look at the second method it expects to be true but I set it to false and it stills outputs a dot. Is like PHP Unit runs only the first method and it st

gadreel's avatar
gadreel's avatar lazos995yrs agoTesting
1
1
Last reply by lazos99 5yrs ago
webcu's avatar

Test that the elements in a collection belongs to an user

Hi! I'm writing a Livewire component called Habits. I would like to test that the user only see the habits that belong to him. This is the current code of the render method. public function render() { return view('livewire.habit.index', [ 'habits' => Habit::where('user_id', Auth::id())->paginate(10), ]); } I tried moving habits to a public property, but t

webcu's avatar
webcu's avatar Tray25yrs agoLivewire
3
1
Last reply by Tray2 5yrs ago
chiefguru's avatar

Default Feature Test fails with 404 error

I have a clean L8 installation running under MAMP 6.0 on a Mac and I'm using PHPStorm as IDE. When I try and run the test tests/Feature/ExampleTest.php from within Storm, the assertion fails with a 404 error. It also fails when run from artisan, so my Storm config isn't the issue. My APP_URL is set correctly to run the app APP_URL=http://localhost:8888/Laravel8/simple-site/publ

chiefguru's avatar
chiefguru's avatar chiefguru5yrs agoTesting
2
1
Last reply by chiefguru 5yrs ago
sboulahr's avatar

Unit test orWhereHas,whereHas Conditions using fakers

Should i test the orWhereHas,whereHas Conditions using fakers ? Thank you

sboulahr's avatar
sboulahr's avatar bugsysha5yrs agoLaravel
3
1
Last reply by bugsysha 5yrs ago
pratamatama's avatar

Why my test fails when I set $this->withoutExceptionHandling()?

I created a test for my app and find something weird with the authorization stuff which is failing when I enable the exception handling by command described by the title above. This is the result when $this->withoutExceptionHandling() commented out: PASS Tests\Unit\SubscriptionTest ✓ subscription table has expected columns ✓ subscription table are seedable th

pratamatama's avatar
pratamatama's avatar tykus5yrs agoTesting
5
1
Last reply by tykus 5yrs ago
sboulahr's avatar

Unit test the update method with laravel 8 and fakers

Alright so I'm pretty new to both unit testing, Fakers and laravel. I'm trying to unit test my resource controller, but I'm stuck at the update function. Here's my controller: public function update(Request $request, $id) { DB::beginTransaction(); try { // update the status if ($bChangeStatus && $request->status === '

sboulahr's avatar
sboulahr's avatar sboulahr5yrs agoLaravel
6
1
Last reply by sboulahr 5yrs ago
faraz73's avatar

Error : no such table exist in test laravel 8

Hi .. i just want to factory a model in my test .. and I got an error like this SQLSTATE[HY000]: General error: 1 no such table: threads ... but it does exist and I have modified phpunit.xml and I have done migration and factoring (i can factory my model in tinker ) idk where is my problem This is my test <?php namespace Tests\Feature; use App\Models\Thread; use Illumina

faraz73's avatar
faraz73's avatar tykus5yrs agoTesting
2
1
Last reply by tykus 5yrs ago
jgravois's avatar

Changing Test Database and Deleting My Local THREE times

Given that I have accidentally deleted and had to restore my local database three times in the last 2 hours, I am reaching out for help. I have been using sqlite in :memory: for testing but I am starting to use some features not available in sqlite so I want to test on a mysql ddb. [1] I created a new database called atc_phpunit (atc is the prod database) [2] I modified my phpu

jgravois's avatar
jgravois's avatar jgravois5yrs agoTesting
10
1
Last reply by jgravois 5yrs ago
CookieMonster's avatar

Does unit test match the actual data in order to pass?

I wrote a unit test to get all the listings of my concert like below: /** @test */ public function user_can_view_all_concert_listing(){ $this->withoutExceptionHandling(); //Given we have a user, when we visit home page $concert = Concert::factory()->create(); //If we visit the concert page $response= $this->get('/concerts')

CookieMonster's avatar
CookieMonster's avatar martinbean5yrs agoLaravel
6
1
Last reply by martinbean 5yrs ago
Ricardo's avatar

Test with event works on Laravel 7 but not in Laravel 8

Hi there, In the functional test that fires an event when a user is updated, the listeners are fired when using Laravel 7, in Laravel 8 the listeners are not triggered. Did someone has any clue what I'm missing?

Ricardo's avatar
Ricardo's avatar Talinon5yrs agoTesting
16
1
Last reply by Talinon 5yrs ago
behrooznik's avatar

why this test is not working?

this is my test: public function a_user_can_unfollow_others() { $ali=$this->SignIn(); $behrooz=factory(User::class)->create(); $this->post($behrooz->profile('follow')); $this->assertCount(1,$ali->fresh()->follows); $this->assertDatabaseHas('follows',['following_user_id'=>$behrooz->id]); $this-&g

behrooznik's avatar
behrooznik's avatar behrooznik5yrs agoTesting
11
1
Last reply by behrooznik 5yrs ago
behrooznik's avatar

what is the problem of this test?

after running the following test i got this Error: Failed asserting that actual size 0 matches expected size 1. this is my test: public function a_user_can_toggle_following() { $john=$this->SignIn(); $this->assertCount(0, $john->follows ); $sally=factory(User::class)->create(); $nick=factory(User::class)->create(); $john->follow($sally); $this

behrooznik's avatar
behrooznik's avatar tykus5yrs agoTesting
1
1
Last reply by tykus 5yrs ago
TobiasS's avatar

Test assertStatus(403) fails when $this->withoutExceptionHandling();

Hi! I get an error, This action is unauthorized. when $this->withoutExceptionHandling(); is in the test. Any ideas why? TEST: test('Boss can view users on clinic /users', function() { $this->withoutExceptionHandling(); actingAs($this->boss)->get('/users')->assertOk(); actingAs($this->user)->get('/users')->assertStatus(403); actingAs($

TobiasS's avatar
TobiasS's avatar tykus5yrs agoTesting
5
1
Last reply by tykus 5yrs ago
connecteev's avatar

access base_path() from within a unit test?

Trying to call base_path from setupBeforeClass() php artisan test --filter=PaymentsAndSubscriptionsTest public static function setUpBeforeClass(): void { $path = base_path('tests') . "/Feature/listen_for_stripe_webhooks.sh"; exec("bash $path"); and it throws this error: • Tests\Feature\PaymentsAndSubscriptionsTest > can reseed

connecteev's avatar
connecteev's avatar Regi441yr agoTesting
4
1
Last reply by Regi44 1yr ago
XiaTesting's avatar

How to test I get the same number of categories as same as the database

Here is my test, I use factory first to create some categories, then hit the endpoint /categories , but I don't know how to test if I get the same number of categories, and also in my test I am not approaching my $response from the endpoint. public function test_it_can_retrive_list_of_categories() { Category::factory()->count(5)->create(); $response = $this->

XiaTesting's avatar
XiaTesting's avatar XiaTesting5yrs agoTesting
2
1
Last reply by XiaTesting 5yrs ago
Antonella's avatar

test payment automatic Cypress

i have this problem with test cypress:

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

Test failed when running queries in Service Provider

Is running db query in service provider a bad practice? For example, I want to have configuration (stored in the database) set & available everywhere via service provider in every call. It works fine in the development & production. But when I run test, it fails. It says "no such table : configs found". Any suggestions?

VinayKesharwani's avatar
VinayKesharwani's avatar martinbean5yrs agoTesting
2
1
Last reply by martinbean 5yrs ago
Acki's avatar

Laravel unable to read embedded file during unit test on gitlab ci

Hi laracast, first of all .. I'm very sorry for my rusty english. :D I've been playing around with setting up my unit test for 2 days now, but I'm unable to embed an image in my html - mail. In my dev-environment on my mac there is no problem for phpunit to send an email with the this image attached, so it must be related to my docker-ci environment. I've updated all my compone

Acki's avatar
Acki's avatar Acki5yrs agoTesting
0
1
XiaTesting's avatar

How to test to "delete multiple records"

Hi guys, recently I really enjoy test before code, however, I have a problem here: I want to test delete multiple records according to id(array), here is my test: public function test_it_can_delete_multiple_events() { Event::factory()->count(5)->create(); $eventsIds = Event::inRandomOrder() ->limit(2) ->pluck('id') ->toArray();

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

Test Laravel 8x: mail reception

Is it possible to test receiving an email with Laravel? or can I use only mock mail tests? I haven't found much about the documentation, just this: https://laravel.com/docs/8.x/mocking#mail-fake

Antonella's avatar
Antonella's avatar Sinnbeck5yrs agoLaravel
4
1
Last reply by Sinnbeck 5yrs ago
Zhen's avatar

Unable to test BelongsToMany relationships

I'm working with a ProfileFactory that randomly attaches BelongsToMany relationships which works great when seeding the database. It also works fine when running the factory in tinker $profile = factory(\App\Profile::class)->create(); $profile->spokenLanguages; This will neatly print out all the randomly attached spokenLanguages. However, whenever I run the factory in my

Zhen's avatar
Zhen's avatar Zhen5yrs agoTesting
1
1
Last reply by Zhen 5yrs ago
Antonella's avatar

test APi token with permissions problem

i generated two tokens: tokenA = As2 ... xxxxx //can perform ONLY create tokenB = Bs2 ... xxxxx //can perform ONLY update i have the following problem $response = $this->withHeaders([ 'Accept' => 'application/json', 'Authorization' => 'Bearer '.$tokenA], ])->post('/api/store',$data); $response->assertStatus(201); //the s

Antonella's avatar
Antonella's avatar gianmarx5yrs agoLaravel
6
1
Last reply by gianmarx 5yrs ago
Antonella's avatar

test API Sanctum POST it does not take the data

I am testing the following API with POST: $data = [ "A" => "a", "B" => "b", "filedJson" => ["a"=> "yes", "b"=> "no"] ]; $response = $this->withHeaders([ 'Content-Type' => 'application/json', 'Accept' => 'application/j

Antonella's avatar
Antonella's avatar Sergiu175yrs agoLaravel
1
1
Last reply by Sergiu17 5yrs ago
madsem's avatar

Test passes locally, but fails during CI (GH actions)

I'm having a curious case of a feature test here. During an import of a large csv file, a temporary mysql table is created. The csv file is loaded into the tmp table using LOAD DATA LOCAL INFILE. Then, using a raw Insert ON DUPLICATE KEY UPDATE query, the data from the temporary table is written into the final models table. The tests are passing local (funnily though only when

madsem's avatar
madsem's avatar madsem5yrs agoTesting
1
1
Last reply by madsem 5yrs ago
Antonella's avatar

test API token Authorization:Bearer

I should test some bees with jetstream / Sanctum to test bees with Insomnia just send the request as follows: GET: http://laravel.test/api Content-Type:application/json Accept:application/json Authorization:Bearer 37b3mWZ9BHc....LRZwbTnYBKtcQss but if I have to test it from code? obviously with active middleware ! without token before i tested the api as follows from code $ da

Antonella's avatar
Antonella's avatar DauletAuto...4yrs agoLaravel
4
1
Last reply by DauletAutomation 4yrs ago
FrazeColder's avatar

Vue.js components test or Laravel Dusk?

Hi, I want to test my Vue.js components but I don't know if I should use Laravel Dusk or Vue.js to test my components. I know it's possible to test the state of Vue components with Laravel Dusk as well.. However, what are the pros and cons on testing Vue components with Laravel Dusk or with Vue.js itself? Testing it with both, Laravel Dusk and Vue.js, wouldn't make sense I gues

FrazeColder's avatar
FrazeColder's avatar FrazeColde...5yrs agoGeneral
0
1
pknad505's avatar

Laravel Feature Test but data doesnt appear until after a request

I'm having troubles with feature tests and data seeming to both exist and not exist depending on where and when that data is being retrieved from. My test only seems to work if I run them one at a time but if run them all together using php artisan test then there seems to be no data so the test fails This is my class: <?php namespace Tests\Feature; use App\AssetGroup; us

pknad505's avatar
pknad505's avatar pknad5055yrs agoLaravel
2
1
Last reply by pknad505 5yrs ago
Ajvanho's avatar

Unit test is not execute

This unit test is does not recognize at all? <?php namespace Tests\Unit\Categories; //use PHPUnit\Framework\TestCase; use Tests\TestCase; use Illuminate\Foundation\Testing\RefreshDatabase; class Categorytest extends TestCase { use RefreshDatabase; /** @test */ public function it_have_many_childrens() { $category = factory('App\Category')->create();

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

Laravel Test Pass when run single test, but fails when running all tests

Hi, everyone, So I just got stuck on testing, because when I ran my test individually it got success. When I run all tests, that test fails. When I enable processIsolation in phpunit.xml, and run all tests I got success. Any ideas what might would be? note: I don't want to use processIsolation because testing time increases 5 times

miguellima's avatar
miguellima's avatar miguellima5yrs agoTesting
4
1
Last reply by miguellima 5yrs ago
ZMChris's avatar

Laravel 7 HTTP test with a Mock Object

Hi there, We are struggling to see how we might be able to test a payment platform (it's an SDK written by the provider themselves and it uses their own built cURL library which we cannot tap into (e.g., with Http::fake()). We are unsure how we can combine mocking an object with HTTP tests. We would like to do something like: public function test_That_We_Get_An Unsuccessful_Aut

ZMChris's avatar
ZMChris's avatar ZMChris5yrs agoTesting
0
1
sarathiscookie's avatar

How to unit test cron jobs in Laravel?

I created a cron job to send notification emails. Cron job is working perfectly. I need to test the cron job using the unit test. How can I write a unit test to check user data is existing or not? I tried to implement a unit test for a cron job, but it is not working. I didn't try the unit test before. Any help would be appreciated. I am using Laravel6. Database Name = cronjob,

sarathiscookie's avatar
sarathiscookie's avatar PropaySyst...3yrs agoLaravel
1
1
Last reply by PropaySystems 3yrs ago
yoeriboven's avatar

Test validation without HTTP session

I'm picking up some techniques from Jetstream but testing isn't optimal. Here's my action class and test. namespace App\Actions; class UpdateUserDetails { public function update(User $user, array $input) { Validator::make($input, [ 'name' => 'required|min:3|max:50', ... ])->validate(); ... } } /** @test */ public fun

yoeriboven's avatar
yoeriboven's avatar yoeriboven5yrs agoTesting
0
1
Antonella's avatar

Test E2E Cypress Jetstream fail click

I wrote the following test in cypress that registers but gives me problems in click management account: import faker from 'faker' describe('Registration', () => { const email = faker.internet.email() const password = faker.internet.password() it('successfully registering', () => { cy.visit('http://l8.test/register') cy.get('input[name=name]').type(faker.name.findN

Antonella's avatar
Antonella's avatar Antonella5yrs agoLaravel
0
1
Antonella's avatar

Jetstream end to end test with cypress

if i use jetstream to create a dashboard that shows a series of data from the db, can i test what i have developed with cypress both the native jetstream features such as login and my page that displays the data?

Antonella's avatar
Antonella's avatar Antonella5yrs agoLaravel
0
1
Antonella's avatar

Test Laravel Jetstream

possible to test jetstream? for example with end to end tests?

Antonella's avatar
Antonella's avatar gianmarx5yrs agoLaravel
2
1
Last reply by gianmarx 5yrs ago
Brainmaniac's avatar

Run all my dusk test files

Hi! I have two different files containing one dusk test each. How can I run both/all my files? They are both placed in the Browser folder. When I run php artisan duskonly one file gets executed.. I can run each individually by specifying a path. But it would be nice to have them both run..

Brainmaniac's avatar
Brainmaniac's avatar Brainmania...5yrs agoTesting
1
1
Last reply by Brainmaniac 5yrs ago
knubbe's avatar

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 legacy-factories package for old factories approach

knubbe's avatar
knubbe's avatar knubbe5yrs agoLaravel
0
1
xico2k's avatar

Multiple User Session on same Feature Test

Hey Guys, So I need to build a test, and the goal is to have the same user login on multiple devices, and after a threshold on users logged in it will remove the session for the older one, kinda like Netflix. Can't find anything on the web to do the multiple logins (without logging out) on the same test, Can you help me? Thanks.

xico2k's avatar
xico2k's avatar xico2k5yrs agoTesting
0
1
Charrua's avatar

TDD how do you test backend and frontend

Hi, I'm new to TDD. As I'm developing my app at the moment I'm only using phpunit with assertions and HTTP tests. At this moment I'm testing features, functionalities and some information that is rendering on blade templates with HTTP tests. Do you use this tests for what's rendering on the browser, like HTTP tests or do you write separate tests in another package like Laravel

Charrua's avatar
Charrua's avatar martinbean5yrs agoTesting
6
1
Last reply by martinbean 5yrs ago
Troj's avatar

Unit test keeps failing

I make use of laravel-boilerplate but i added some fields to the usertable, for example a username (required field) and some other additional fields. But now the UpdateUserTest keeps failing and i cant figure out what goes wrong. I dont understand the error either. FAIL Tests\Feature\Backend\User\UpdateUserTest ✓ an admin can access the edit user page ✕ a user can be u

Troj's avatar
Troj's avatar automica5yrs agoLaravel
19
1
Last reply by automica 5yrs ago
Owerll1984's avatar

Seed method works only once in Test classes

Hello everybody! I encounter a weird issue using Artisan commands (directly or indirectly) in the setUp method of my integration test classes. In order to get test data, I want to migrate and seed data in a test database before running my tests. To do so, I use the setUp method: public function setUp(): void { parent::setUp(); $this->seed(); } I

Owerll1984's avatar
Owerll1984's avatar Owerll19845yrs agoLaravel
3
1
Last reply by Owerll1984 5yrs ago
vincent15000's avatar

Middleware to test something else than User

Hello, Is it possible to use a middleware to test for example if the registrations are open for a game ? if (! $game->registrationsAreOpen()) { return redirect()->... } return $next($request); I have checked the documentation, but I do not understand how it could be possible to add a parameter like $game (which could be the game that is used at the moment in the code).

vincent15000's avatar
vincent15000's avatar vincent150...5yrs agoLaravel
2
1
Last reply by vincent15000 5yrs ago
knubbe's avatar

How to wrote a test for method in controller with DI?

I have invocable controller for rendering some pdf. In route I only need to pass some string as parameter but my method look like this: public function __invoke( Request $request, IncidentPdfGenerationService $incidentPdfGenerationService, string $report ) { $pdf = $incidentPdfGenerationService->getRawPdf($request, $report); $name

knubbe's avatar
knubbe's avatar knubbe5yrs agoTesting
2
1
Last reply by knubbe 5yrs ago
vincent15000's avatar

Query to test if a row exists ?

Hello, I have a many-to-many relationship between two tables. public function users() { return $this->belongsToMany('App\Models\User', 'users_games') ->withPivot('score') ->withTimestamps(); } I want to test if a user is registered in a game. So I added this method. public function isCurrentUserRegistered() { $count = $this->withCount(['user

vincent15000's avatar
vincent15000's avatar vincent150...5yrs agoEloquent
6
1
Last reply by vincent15000 5yrs ago
user86516512's avatar

Local environment to test API from Android/iOS?

How would I go about setting up a local Laravel environment so I can test my API with Android/iOS emulators? The last time I tried it, there were a number of major issues that made it either impossible or extremely time-taxing to get around in order to get it to work.

user86516512's avatar
user86516512's avatar martinbean5yrs agoGeneral
2
1
Last reply by martinbean 5yrs ago
mahmoud_ayad's avatar

why i make test to my projects ?

I see some videos to laracasts for TTD and can not understand why i make test to projects

mahmoud_ayad's avatar
mahmoud_ayad's avatar JeffreyWay5yrs agoLaravel
4
2
Last reply by JeffreyWay 5yrs ago
Gabotronix's avatar

Stripe CLI sends webhooks with fake data, how am I supossed to test my integration

Hi everybody, I'm working on a website with Stripe payments, it's europe based so I'll have to deal with SCA 3D Secure auth, stripe docs recommend me to deal with payment fulfillement asynchronously instead of waiting for confirmCardPayment promise to resolve, to accomplish this you have to use webhooks. Something I noticed is webhooks send fake data in events, if data is fake

Gabotronix's avatar
Gabotronix's avatar martinbean5yrs agoGeneral
4
1
Last reply by martinbean 5yrs ago
Sajjad Ali's avatar

Test is passing with assertSee() while Error in browser

This is my test. /** @test */ public function a_user_can_post_a_video() { //$this->withoutExceptionHandling(); $this->actingAs(factory('App\User')->create()); $attributes = [ 'title' => $this->faker->sentence, 'description' => $this->faker->paragraph, 'video_url' => $this->faker

Sajjad Ali's avatar
Sajjad Ali's avatar GeordieJac...5yrs agoTesting
3
1
Last reply by GeordieJackson 5yrs ago
LiamA's avatar

SImple Dusk test from manual fails

I'm trying to follow the instructions here: https://laravel.com/docs/7.x/dusk#creating-browsers But the assertPathIs test keeps failing. The generated screenshot shows a "credentials do not match our records". I should mention that I also tried setting the password for the user when its created by the factory (bcrypted, of course). I have a .env.dusk.local configuarat

LiamA's avatar
LiamA's avatar LiamA5yrs agoTesting
9
1
Last reply by LiamA 5yrs 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.