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

cdgraham's avatar

Apache not return Laravel json validation errors on Test but works on Dev

I've been working on a Laravel 9 API with validation. On my dev system, using Windows/Apache/PHP 8.1, the POST requests return a 422 with the json validation errors. My request header includes "Accept: application/json". { "message": "The name field is required.", "errors": { "name": [ "The name

cdgraham's avatar
cdgraham's avatar amitshahc3yrs agoLaravel
2
1
Last reply by amitshahc 3yrs ago
CLab's avatar

Run different migration in test

I have a migration which is altering a column in a table in Postgres (dev) to JSON. This is a custom query like. DB::statement('ALTER TABLE users ALTER COLUMN options TYPE JSON USING (options)::json'); However due to this migration my tests are failing as I am using SQLite in testing. How can I run a different alteration command for test vs dev? I am looking for so

CLab's avatar
CLab's avatar CLab4yrs agoTesting
6
1
Last reply by CLab 4yrs ago
sr57's avatar

Event simple test - How to?

First time I want to test an event and still get the msg "The expected [app\Events\TestEvent] event was not dispatched" The event : TestEvent.php class TestEvent implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; public $message; public function __construct() { $this->message = '...'; } public function broadcastOn(){ retu

sr57's avatar
sr57's avatar MohamedTam...4yrs agoLaravel
4
1
Last reply by MohamedTammam 4yrs ago
lat4732's avatar

Running php artisan test results in 3 failed, 4 skipped, 26 passed

Hey! This is the first time I have run the php artisan test since working on the application (Laravel 8) and the result is Tests: 3 failed, 4 skipped, 26 passed I haven't touched anything in the tests folder ever which makes me think that these tests should actually be 100% passed no matter what, because they are provided out of the box and for reason. Here are the 3 failed t

lat4732's avatar
lat4732's avatar Laralex4yrs agoLaravel
15
1
Last reply by Laralex 4yrs ago
FarhadMohammadi's avatar

Test Database MYSQL Migration impress On main Application Database

I use MYSQL test database by docker testdb: container_name: "${SERVICE_NAME}-testdb" image: mariadb:10.5 tmpfs: /var/lib/mysql environment: - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} - MYSQL_PASSWORD=${MYSQL_PASSWORD} - MYSQL_DATABASE=${MYSQL_DATABASE} - MYSQL_USER=${MYSQL_USER} restart: always

FarhadMohammadi's avatar
FarhadMohammadi's avatar FarhadMoha...4yrs agoLaravel
1
1
Last reply by FarhadMohammadi 4yrs ago
FarhadMohammadi's avatar

why RefreshDatabase not work for each test?

I use laravel 8 and I wrote some feature test for saving patient in my systems. it seems RefreshDatabase not clear previous test patient records and $this->assertCount(1, Patient::all()) not worked. public function testPatientCanSavePatientWithCorrectData() { $this->withoutExceptionHandling(); $this->actingAs(User::factory()->create()); $response = $this-

FarhadMohammadi's avatar
FarhadMohammadi's avatar FarhadMoha...4yrs agoLaravel
3
1
Last reply by FarhadMohammadi 4yrs ago
bobwurtz's avatar

Dusk Test for Livewire Pull Request

Hey All, I use Livewire in my applications and there is currently a pull request that is waiting on tests to be written before it can be approved. I have done some simple browser tests before so I was trying to write a test for this PR to get things moving. I've run into some issues and I'm hoping someone can point me in the right direction. Also, I've never attempted to contri

bobwurtz's avatar
bobwurtz's avatar bobwurtz4yrs agoLivewire
2
1
Last reply by bobwurtz 4yrs ago
lukas653's avatar

How to test static Eloquent model

Hi, I have an issue with testing my classes and services. When my service classes have an Eloquent model inside. I try to use Mockery::mock('overload:'.Subscription::class), but unfortunately, I receive an error Mockery\Exception\RuntimeException : Could not load mock App\Subscription, class already exists even docblock on the top of the function does not help. Could you please

lukas653's avatar
lukas653's avatar lukas6534yrs agoTesting
0
1
craig_lovelock's avatar

How would you test an external DB (Salesforce)

Hi, been at a company for almost a year now and cannot think of a decent way to start building some tests into the projects. The issue I face is that almost everything goes to external services but mainly they use Salesforce as their 'database' and an Eloquent wrapper to make it feel local. I have toyed with the idea of creating some custom work that will essentially call delet

craig_lovelock's avatar
craig_lovelock's avatar Braunson4yrs agoTesting
1
1
Last reply by Braunson 4yrs ago
amoktar's avatar

How can I count html elemets in laravel test

Is there a way to count html dom elements with laravel test, with css or xpath selectors I've tried this but getting error below $this->assertCount($number, $this->crawler->filter($selector)); Undefined property: Tests\Feature\PublicUrlsTest::$crawler Thanks

amoktar's avatar
amoktar's avatar amoktar4yrs agoTesting
2
1
Last reply by amoktar 4yrs ago
CrastyCrap's avatar

Laravel Test

Greeting everyone, I am working on an e-commerce project this project contains multi-store accordingly to reach any store you have to call route /store_name and this store name i want to make a test to check that all store pages work fine so i make simple test to do that work public function store_main_test() { $stores = DB::table('stores')->where('activate',1)-

CrastyCrap's avatar
CrastyCrap's avatar CrastyCrap4yrs agoLaravel
2
1
Last reply by CrastyCrap 4yrs ago
Eddie D's avatar

Migrate new test DB => Database(x) does not exist

I've been developing tests in my "production" mysql database(app is unreleased) and realize I should have a separate test database so setting one up now. I'm following the Laracast on how to set up a test sqlite database, but it's not working I'm getting the error: eddie@production:~/projects/production2.0$ php artisan migrate --database=sqlite_testing ***************

Eddie D's avatar
Eddie D's avatar tykus4yrs agoLaravel
5
1
Last reply by tykus 4yrs ago
jan_zikmund's avatar

Test function using 3rd party OAuth2

Hi, is there any convenient way to write a PHPUnit test for a functionality, which consumes 3rd party API authenticated with OAuth2? I don't need to test the OAuth2 flow itself, I just have one route which connects to their API, gathers some data and shows them, and this route I want to test. Obviously, when I am not authenticated, no data is gathered, so the test fails. But he

jan_zikmund's avatar
jan_zikmund's avatar SereySoksa...2yrs agoTesting
6
1
Last reply by SereySoksan 2yrs ago
lat4732's avatar

How to test Laravel Cashier Stripe subscriptions in test mode properly

Hey! I've almost finished my app, the next thing I need to do is to actually test the subscriptions. Till now I've tested them by creating a new invoice to the existing stripe user and this way I simulate a new unpaid invoice. But I'm pretty sure that's not the right way to do this. Do you guys have any ideas how to test these subscriptions? Something like changing the subscrip

lat4732's avatar
lat4732's avatar Laralex4yrs agoLaravel
1
1
Last reply by Laralex 4yrs ago
ronmakeszens's avatar

Public doesn't work during test

An image saved to the (public) disk is found by the browser & by MacOS (so the storage:link symlink works) , but in test (with php artisan test) I get a NotFoundHttpException. $response = $this->json('POST', '/api/photos', [ 'file'=>UploadedFile::fake()->image('img.jpg', 10, 10)->size(1) ]); // 200 $response = $this->get($response[

ronmakeszens's avatar
ronmakeszens's avatar Sinnbeck4yrs agoTesting
3
1
Last reply by Sinnbeck 4yrs ago
pakistanigeek's avatar

IOC Container Bindings are not available in Unit Test

Hi, I have bound an Interface in IOC Container using Service provider, I found it working while resolving it using tinker but when I use it in unit test it doesn't find any binding. Could someone help me to resolve this issue. Thanks in advance. Code in service provider. // Private chat $this->app->bind(IPrivateChat::class, function ($app){ return

pakistanigeek's avatar
pakistanigeek's avatar pakistanig...4yrs agoLaravel
8
1
Last reply by pakistanigeek 4yrs ago
mrcrmn's avatar

How to test against an existing Database?

If you need to create an application that interacts with an existing database. What would be the best way to test your application? I was thinking about: Creating migrations for the existing tables which only run in the testing environment. Override the connection to the "default" one in the boot method of the Models Or is there a better way to do it?

mrcrmn's avatar
mrcrmn's avatar mrcrmn4yrs agoTesting
4
1
Last reply by mrcrmn 4yrs ago
FvsJson's avatar

Config helper in pest unit test

Im new to pest test and Laravel and I would like to know how to user the config helper inside my pest unit tests?

FvsJson's avatar
FvsJson's avatar FvsJson4yrs agoLaravel
2
1
Last reply by FvsJson 4yrs ago
ramirushi7997's avatar

What is the correct way to test the eloquent models and relationships?

Hello everyone, I am relatively new to Laravel and testing. I wondered the correct way to test the eloquent model and its relationships. I have played around for a while and made these tests below for relationships. But it feels like this should not be an excellent way to test things. <?php namespace Models; use App\Models\User; use Illuminate\Database\Eloquent\Relations\B

ramirushi7997's avatar
ramirushi7997's avatar axeloz3yrs agoTesting
1
1
Last reply by axeloz 3yrs ago
bor1904's avatar

How to deal with test needed a lot of related data

Hello, I have some doubts about creating models via factories under testing process. For example I have service desk system with tickets as a main objects and if I want to make any feature test on ticket then I need to: create ticket by factory but ticket as we know need assigned person who open ticket so we need to.. create a agent... but agent to be agent have to has role &q

bor1904's avatar
bor1904's avatar sr574yrs agoTesting
3
1
Last reply by sr57 4yrs ago
eriktobben's avatar

Laravel Event from Livewire not dispatched in test

Hi! I have a Livewire component that dispatches a Laravel Event from an action. The Listener is implementing ShouldQueue. This is working fine when manually testing, but when testing with PHPunit, the event is not fired. The test fails with the following error: The expected [App\Events\ProductVideosChanged] event was not dispatched. Livewire Component: public function deleteVid

eriktobben's avatar
eriktobben's avatar eriktobben4yrs agoTesting
2
1
Last reply by eriktobben 4yrs ago
devlob's avatar

Coderbyte test for laravel developer

Could you please guide me on how can I prepare & clear the Coderbyte interview test? Thanks

devlob's avatar
devlob's avatar Sinnbeck4yrs agoLaravel
1
1
Last reply by Sinnbeck 4yrs ago
pakistanigeek's avatar

Laravel Test Case custom headers doesn't found in RouteServiceProvider

Hi, I have multiple API versions and each version have a dedicated route file, whenever API is called with a client it provides a specific API version in headers which is being retrieved in RouteServiceProvider. The problem is that when I am performing a test the request doesn't have the custom headers which I am providing with the JSON call. Below is the test case code. $re

pakistanigeek's avatar
pakistanigeek's avatar pakistanig...4yrs agoLaravel
5
1
Last reply by pakistanigeek 4yrs ago
jivanrij's avatar

How to test an event that is triggered by a request done with something different then $this->get()

I'm trying to find the best way to test if an event is triggered when a specific endpoint of my API is requested. Normally I'm testing events like this: Event::fake([ MyEvent::class, ]); SomeClass::doSomethingThatTriggersTheEvent(); Event::assertDispatched(function (MyEvent $event) { return $event->my_value == 'something-to-check'; }); But when I can't trigger the

jivanrij's avatar
jivanrij's avatar MohamedTam...4yrs agoTesting
5
1
Last reply by MohamedTammam 4yrs ago
itachi's avatar

How to test a static request payload?

I am working on PayPal seller onboarding flow. https://developer.paypal.com/docs/multiparty/seller-onboarding/build-onboarding/ As you see in the document I have a static payload to generate a seller signup link. Where do I write test cases for the payload? Should I write it as a Unit test or an Integration test.

itachi's avatar
itachi's avatar itachi4yrs agoTesting
2
1
Last reply by itachi 4yrs ago
Ligonsker's avatar

How to test my Soketi server?

I'm not an expert servers person, so my following setup might be wrong: I setup 3 Ubuntu 20.04 Server virtual machines as follows: (And I'm not sure that's enough for that test either because I'm also using php artisan serve which is using PHP's development server, so not sure it's suitable for the test) 192.168.10.10 - Soketi Server - 2 Cores, 2GB RAM 192.168.10.11 - Larave

Ligonsker's avatar
Ligonsker's avatar Sinnbeck4yrs agoServers
22
29
Last reply by Sinnbeck 4yrs ago
LiamDot's avatar

"This test did not perform any assertions" while it does

Hey everyone, I hope you are doing well. While I was trying to pass my test, it gave me an alert for having a "risky test" that does not perform any assertions. My test is this: class ProjectTaskTest extends TestCase { use RefreshDatabase; public function test_a_project_can_have_tasks() { $this->signIn(); $project = auth()->user()-&

LiamDot's avatar
LiamDot's avatar Nakov4yrs agoTesting
1
1
Last reply by Nakov 4yrs ago
dannyyounes's avatar

Cypress test not display date format

Performing a Cypress test on a date dayjs(15).format('Do') + " of every month"; So this should display 15th of every month but in the cypress test in display Invalid Date of every month. Outside the test it displays fine.

dannyyounes's avatar
dannyyounes's avatar dannyyoune...4yrs agoTesting
2
1
Last reply by dannyyounes 4yrs ago
ryan_'s avatar

Test Won't work

when i create a unit test even when i do every thing correct the test fails, but when i move the same test to feature test it passes . any ideas

ryan_'s avatar
ryan_'s avatar Sarah Smit...4yrs agoTesting
7
1
Last reply by Sarah Smith 4yrs ago
nafeeur10's avatar

Writing Unit Test for CSV file upload in Laravel

I have an CSV file with two columns: id amount ------------- 1 1000 2 1500 3 5800 Now I want to write Unit Test for this. After uploading this file which steps I need to follow to write proper test case?

nafeeur10's avatar
nafeeur10's avatar tisuchi4yrs agoLaravel
1
1
Last reply by tisuchi 4yrs ago
DcDev's avatar

Test assertSee and hidden modal

Ia have a modal create form: <div id="edit-form" x-data x-cloak x-show="$wire.showEditForm">Some Content</div> It is hidden by default: public bool $showEditForm = false; Visibility is toggled with action on button: <button type="button" wire:click="create" wire:loading.attr="disabled">Open modal<

DcDev's avatar
DcDev's avatar DriverCat4yrs agoLivewire
1
1
Last reply by DriverCat 4yrs ago
laravel_user's avatar

Integration Test: Determine all Nova Resources

Hello everyone, I am trying to write a PHPUnit integration test that tests the API all Nova resources to catch the most obvious bugs. The way I am thinking to go about this is: Determine all resource classes Determine the URI key Call the appropriate URLs with /app/resources/<uriKey> and /nova-api/<uriKey>/<lenses/filters/actions> and assert a status code of

laravel_user's avatar
laravel_user's avatar laravel_us...4yrs agoNova
0
1
cooperino's avatar

Is there a way to clone dev db data to test db?

I am just now starting to learn about testing At first I ran php artisan test and it showed me that I am missing the test database so I simply created an empty db. Then the tests started running and I saw that the test database have the same tables as the app's database. Was what I did correct? i.e to create an empty database and then let php artisan test create the app's db. A

cooperino's avatar
cooperino's avatar cooperino4yrs agoTesting
8
2
Last reply by cooperino 4yrs ago
jred_lewis's avatar

How to test generator command?

Over the holiday weekend, I made an artisan command for my project to generate Action classes (extending the built-in GeneratorCommand class. I made a basic test to check both the folder and file exists, and it is returning green. But, I was wondering what other use cases I should test against?

jred_lewis's avatar
jred_lewis's avatar ckalita3yrs agoTesting
1
1
Last reply by ckalita 3yrs ago
seongbae's avatar

How to test bad credit card when purchasing new subscription

HI, On our website, users create payment methods using credit card. Once payment method has been added, they can purchase subscription. Recently, we've had a few instances where users had their credit card lost/stolen and their card is no longer valid. Then they try to purchase a new subscription with the same card (because it was added when the card was in good status). Th

seongbae's avatar
seongbae's avatar seongbae4yrs agoLaravel
3
1
Last reply by seongbae 4yrs ago
automica's avatar

Mocking passport for feature test

Hi all, I'm working on a feature for an api where a user can login directly after registration. I'm doing this by generating a token using passport: $token = $user->createToken('token')->accessToken; and then passing it back in the response. Whilst I've tested this against the dev db using postman (and get a token back correctly), I'm having some issues with this as par

automica's avatar
automica's avatar automica4yrs agoTesting
3
1
Last reply by automica 4yrs ago
thomasdiluccio's avatar

Add a phpdbg support for L9 test coverage

Hi, Do you know in what package is the --coverage parameter of the artisan test command handled? I'd like to add a Phpdbg support for that feature. XDebug and PCov have known side-effects with Blackfire. Cannot locate it yet. Thanks

thomasdiluccio's avatar
thomasdiluccio's avatar thomasdilu...4yrs agoTesting
2
1
Last reply by thomasdiluccio 4yrs ago
vincent15000's avatar

Command "laravel new test" for v9.x ?

Hello, I'm trying to install a test project with Laravel V9.x but it doesn't work. laravel new test It installs me the v8.x version. Do I have something special to do to have the v9 with the laravel command ? Thanks for your help ;). V

vincent15000's avatar
vincent15000's avatar vincent150...4yrs agoLaravel
6
1
Last reply by vincent15000 4yrs ago
faraz73's avatar

findOrFail() works on test but not in action

Hi , im learning livewire so just write this test : /** * @test */ public function if_a_wrong_query_string_has_been_set_no_data_should_be_returned() { Livewire::withQueryParams(['post_id',rand()]) ->test('posts') ->assertSee('title','') ->assertSee('text','') ->assertSee('save'); } this t

faraz73's avatar
faraz73's avatar faraz734yrs agoLivewire
2
2
Last reply by faraz73 4yrs ago
Brainmaniac's avatar

Can't use sqlite in memory DB for pest test

I am about to start testing with Pest! It seems great BUT.. I am following instructions and have successfully been running the first test tests 😅 - But when I go to my phpunit.xml and uncomments the following rows to start use in memory sqlite db the test tests do not pass any more: <server name="DB_CONNECTION" value="sqlite"/> <server name="DB

Brainmaniac's avatar
Brainmaniac's avatar tykus4yrs agoTesting
8
7
Last reply by tykus 4yrs ago
gerardw85's avatar

Unit Test - Newbie Question

Hi, Very new here, and working through an online tutorial - but I'm stuck. Hopeful the community can point me in the right direction. I have this Unit Test: public function test_StoreValid() { $params = [ 'title' => 'Valid Title', 'content' => 'At least 10 characters' ]; $this->post('/posts', $params) -&g

gerardw85's avatar
gerardw85's avatar tykus4yrs agoGeneral
3
1
Last reply by tykus 4yrs ago
alexlegard's avatar

How do I test my large web app

I have a completed restaurant finder web application and would like to deploy it soon. I thought it would be a good idea to test it a while before I do that. But the application is already quite big and testing everything seems like an overwhelming task. I'm a beginner web developer, and I'd like to get the application to a place where it might impress recruiters. But I'd also

alexlegard's avatar
alexlegard's avatar alexlegard4yrs agoTesting
2
1
Last reply by alexlegard 4yrs ago
CLab's avatar

Unit test with models?

Can/Should unit tests be made with instances of models created to database or should these be feature tests? Basically I created a custom rule and wanted to test it. My rule checks the model instance if it has some value in a JSON column. I searched for articles for testing custom validation rule and came across articles like https://nickescobedo.com/1262/how-to-write-tests-for

CLab's avatar
CLab's avatar CLab4yrs agoTesting
8
1
Last reply by CLab 4yrs ago
faraz73's avatar

Livewire works but test says: not !

Hi, I'm testing a livewire component , the test is error session should be thrown when from inputs are empty : /** * @test */ public function while_creating_a_post_the_empty_inputs_should_return_errors() { Livewire::test('posts') ->set('title' , '') ->set('text' , '') ->call('store') ->assert

faraz73's avatar
faraz73's avatar faraz734yrs agoLivewire
2
1
Last reply by faraz73 4yrs ago
CLab's avatar

Writing test for function to store files

I have a function in a trait which stores an attachment to a Google Cloud Storage bucket like: public function storeFiles($type, $id, $attachments) { $folder = $type . '/' . $id; $disk = \Storage::disk('gcs'); if (!empty($attachments)) { $output = []; foreach ($attachments as $attachment) { $file = $attachment['file']; $filename = $f

CLab's avatar
CLab's avatar CLab4yrs agoTesting
4
1
Last reply by CLab 4yrs ago
PeterF's avatar

PHPUnit with test coverage in VSCode = Pain and suffering

Hi All, I have tried to go down the test coverage path with phpunit in vscode for laravel projects a few times over the last few years and always end up giving up in disgust. Normally its because if Xdebug but on this occasion its not. It's some weird nuance in VSCODE that is driving me bonkers. When I try and run tests, either individually, or all at once, through the PHPUnit

PeterF's avatar
PeterF's avatar PeterF4yrs agoTesting
1
1
Last reply by PeterF 4yrs ago
Annaro's avatar

How to test code inside a job?

In ANOTHER test, i am testing that the job is actually pushed to the queue, using Queue::fake() : /** @test */ public function job_is_dispatched() { // some code Queue::fake(); $response = $this->post(route('runOrScheduleAction')); sleep(1); Queue::assertPushed(RunJob::class, 1); } Now i'd like to test the code of the

Annaro's avatar
Annaro's avatar Annaro4yrs agoTesting
2
1
Last reply by Annaro 4yrs ago
salmazz45's avatar

my test cases not working after run php artisan optimize:clear

i am set up my environment i am working with laravel 8 i am run about 13 test case after i run php artisan optimize:clear does not run my testcase except the two example of test case what exists by default with framework ? what can i do ?

salmazz45's avatar
salmazz45's avatar tisuchi4yrs agoLaravel
1
1
Last reply by tisuchi 4yrs ago
beNjiox's avatar

How to test emails being sent later

I have a simple mail code Mail::to("[email protected]")->later(now()->addSeconds(5), $mailable); How do I test that the email will be sent in 5 seconds ? Note that regular tests work Mail::assertQueued($mailable::class) Reading the implementation of later in MailFake, i realize that the delay is being ignored, so I assume there's no proper way, but I still ask

beNjiox's avatar
beNjiox's avatar federico-b...2yrs agoTesting
9
1
Last reply by federico-boncaldo 2yrs ago
craig_lovelock's avatar

How to test a multistep checkout journey

Evening, I'm wanting to start adding tests to a new code base but have never gone beyond simple test for API endpoints and the like. This new project is a checkout journey with multiple pages / steps and finally a payment to Stripe. Is there any resources on building this sort of test flow? Each step of this checkout journey allows you to add items to a basket in the database,

craig_lovelock's avatar
craig_lovelock's avatar drewdan4yrs agoTesting
1
1
Last reply by drewdan 4yrs 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.