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

rikw's avatar

Do you test all validations for create and update actions?

Hi! I'm writing tests for my new application and start to wonder... Do you test all form field validations for create and update actions seperately? To me it looks like a lot of test code. Does that make sense? Cheers! Rik

rikw's avatar
rikw's avatar DawgOnKing7yrs agoTesting
3
1
Last reply by DawgOnKing 7yrs ago
MatejKucera's avatar

Dusk is not creating new session after each test

Hello, I have a trouble resetting session after each test. I use cookies as my session driver (not working with file driver either). This is my test teardown: public function tearDown() { parent::tearDown(); foreach(static::$browsers as $browser) { $browser->driver()->manage()->->deleteAllCookies(); } } It clears the cookies successfully, but m

MatejKucera's avatar
MatejKucera's avatar myasirhash...8yrs agoTesting
1
1
Last reply by myasirhashmi 8yrs ago
bambamboole's avatar

How to test a View Composer in Laravel?

I want to test a view composer and I don't get how to... I have a simple View Composer like this: class SidebarComposer { /** * @var Post */ protected $post; public function __construct(Post $post) { $this->post = $post; } public function compose(View $view) { $view->with('latestPosts', $this->post->orderBy('cr

bambamboole's avatar
bambamboole's avatar impbob368yrs agoTesting
4
1
Last reply by impbob36 8yrs ago
aboutsam's avatar

Store fix test data ?

Hello guys, is it possible to create fixed test data for my laravel installation which i can also migrate via php artisan? I know the factory files but these files create dummy data. I want to save 2 users as default .. because when i refresh the database, i have to manuell insert them again. Is there any standard process in laravel? Thanks a lot!

aboutsam's avatar
aboutsam's avatar xmarks8yrs agoLaravel
1
1
Last reply by xmarks 8yrs ago
bencarter78@hotmail.com's avatar

PHPStorm - Running PHPUnit test from 'Run context configuration' gives Class 'Tests\TestCase' not found error

Hello I have one of those issues where it was working last week, but for some reason today it's not working. I had a workflow with PHPStorm whereby I could place my cursor in a test method and 'Run context configuration' and it would test that method. Today (after a reboot) it shows me the error Class 'Tests\TestCase' not found. I've managed to set up a specific configuration f

bencarter78@hotmail.com's avatar
bencarter78@hotmail.com's avatar bencarter7...8yrs agoTesting
1
1
Last reply by bencarter78 8yrs ago
deepu07's avatar

PhpUnit test

Hi, I'm newbie for phpunit test. Which one is better to start with phpunit test.

deepu07's avatar
deepu07's avatar ChristophH...8yrs agoTesting
1
1
Last reply by ChristophHarms 8yrs ago
TEAMPT's avatar

How Do I test if an email was queued and sent?

How can I test if my mailable was successfully queued and sent in PHPUNIT?

TEAMPT's avatar
TEAMPT's avatar martinbean8yrs agoTesting
1
1
Last reply by martinbean 8yrs ago
Mikoop's avatar

404 response for "webhook/stripe" url for test domain?

My test webhook for stripe is giving me a 404 (MethodNotAllowedHttpException ) response for "webhook/stripe" on forge. Works fine in local environment using ngrok, and on other LIVE domains. have tried most things and can see the route exists in the php artisan route:list, Any ideas would be greatly appreciated?

Mikoop's avatar
Mikoop's avatar Jaytee8yrs agoSpark
1
1
Last reply by Jaytee 8yrs ago
luklaw's avatar

How to functional test application using Laravel Passport?

I'm building an api using for authorization Laravel Passport package and I would like to functional test my routes, problem is that I have used client_credentials grant type and recommended code to test api is not working. Passport::actingAs( factory(User::class)->create(), ['create-servers'] ); How to create in test environment access token and use it to access my

luklaw's avatar
luklaw's avatar AliBayat3yrs agoTesting
2
1
Last reply by AliBayat 3yrs ago
matt_panton's avatar

Best way to test creating charges with Stripe?

I'm working on a project that requires me to take payments using Stripe. I'm writing some feature tests to check that card declines are handled correctly and I'm currently using the JacobBennet/StripeTestToken to generate fake tokens. The problem is that it's slow to generate these tokens, especially when there's around 10 being generated in my test suite. What's the best way t

matt_panton's avatar
matt_panton's avatar matt_panto...8yrs agoTesting
0
1
TimM1968's avatar

Error when running unit test - ReflectionException: Method suite does not exist (BaseTestRunner.php)

I have assignd CTRL+T run my unit test within VS Code on Windows 10 within BetterPhpUnit. Have debugging turned on. I just want to be able to debug a test. I start the debugger to "Listen for XDebug (test-project)", put the cursor on the "testBasicTest" and start the debug using the BetterPhpUnit assigned shortcut key. After I few seconds I get an exception

TimM1968's avatar
TimM1968's avatar tylerwiega...6yrs agoLaravel
4
1
Last reply by tylerwiegand 6yrs ago
navihtot's avatar

Controller test - request empty in service provider

I have a service provider which binds a service based on route parameter. Everything works nice but now I'm trying to test my controller, and for some reason request parameters are empty in my service provider :( Service provider: public function register() { $this->app->call([$this, 'registerServices']); } public function registerServices(Request

navihtot's avatar
navihtot's avatar Abdul Rahm...4yrs agoLaravel
3
1
Last reply by Abdul Rahman 4yrs ago
makapaka's avatar

How do you test API limits

I want to load test my Laravel API - i have set the throttle to 500, how can I simply test hitting it more than that at once to see how it handles it ? Do i have to use a full on load testing tool externally or is there a way within Laravel to do this ?

makapaka's avatar
makapaka's avatar robrogers38yrs agoLaravel
2
1
Last reply by robrogers3 8yrs ago
adifaidz's avatar

How should I test this method

Hi I'm quite new to testing and I want to know what kind of testing should I do with this piece of code public function setCountry($data) { //Some checks.. //Get country $cc = array_get($data, 'data.country_code'); $country = Country::where('cc', $cc)->first()->name; $this->country = $country; } Should I unit test or integration test this? O

adifaidz's avatar
adifaidz's avatar adifaidz8yrs agoTesting
2
1
Last reply by adifaidz 8yrs ago
abkrim2's avatar

Dusk L55 headaches with database test

I'm new on Dusk Well, configure using doc and tutorials On my local development create a .env.dusk.local (I verified that app is on local environment with dd($this->app->environment()) .env.dusk.local DB_CONNECTION=mysql_tests DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=lowino_tests DB_USERNAME=myname DB_PASSWORD=mypassword DB_DATABASE_TESTS=lowino_tests in phpunit.xml &

abkrim2's avatar
abkrim2's avatar TesterP8yrs agoTesting
1
1
Last reply by TesterP 8yrs ago
thebigk's avatar

Do not want to disable Middleware and yet get the test to green

My test is as follows: /** @test */ public function guests_cannot_create_quiz() { //$this->withoutMiddleware(); $this->post('/quiz/store', []) ->assertRedirect('/register'); } I'm trying to post an empty array to my route and I expect the system to redirect the user to login page. While I'm not exactly sure if that's the right asser

thebigk's avatar
thebigk's avatar thebigk8yrs agoTesting
2
1
Last reply by thebigk 8yrs ago
PrinceMinky's avatar

Thread Test error.

I am running a test, as featured on one of the series. But I'm not getting the same errors. For some reason my the test 'a_user_can_browse_threads' isn't found even though it is clearly there. Have I missed something? [all errors and code] "Mikey@Home MINGW64 /c/wamp/projects/forum $ phpunit PHPUnit 6.4.4 by Sebastian Bergmann and contributors. W.

PrinceMinky's avatar
PrinceMinky's avatar pijushsaha7yrs agoTesting
3
2
Last reply by pijushsaha 7yrs ago
ignatius56's avatar

test subscription fails

try to subscripe a test user in spark ... ccnumber 4242424242424242, sec-code 123 after clicking on SUBSCRIBE, the program turns in circles ... any idea how to get over this? thanks for your help Ignatius

ignatius56's avatar
ignatius56's avatar ignatius568yrs agoSpark
2
1
Last reply by ignatius56 8yrs ago
jbarotin's avatar

How to see the stack trace while executing unit test on REST API that don't work

Hello, I'm trying to implement a REST API with lumen. In order to validate my work. I wrote unit test thought phpunit. Sometime, an error occur (database constrains for example) in the REST API, that generate a "rich" web page in order to view the error in a browser. But, I'm running my test in command line, I would prefer to get the stack without all this html format

jbarotin's avatar
jbarotin's avatar jbarotin8yrs agoLumen
5
1
Last reply by jbarotin 8yrs ago
PaulClarke's avatar

Null object in test using Eloquent

So I am attempting to test that when a user has forgotten their password, they can enter their email address and receive a password reset email. The code works, but the test fails. (I have made a create helper method like JW had on the 'How to Build a Forum' series). /** @test */ public function a_user_can_request_an_email_to_reset_their_password() { Notificati

PaulClarke's avatar
PaulClarke's avatar PaulClarke8yrs agoTesting
3
1
Last reply by PaulClarke 8yrs ago
PaulClarke's avatar

PHPWord works locally but not when pushed to test server

Dear All, I am having a problem using PHPWord and I am hoping someone else has experience of this and can let me know where I am going wrong. Locally, PHPWord is working absolutely perfectly and producing my files as expected. My settings are: In composer.json (shortened) "require": { "php": ">=7.0.2", "laravel/framework&qu

PaulClarke's avatar
PaulClarke's avatar haydi808yrs agoGeneral
4
1
Last reply by haydi80 8yrs ago
kulka1's avatar

BrowserKitTesting test if file was downloaded after form submit

I have a simple form in laravel to convert excel to csv. After i submit my button, a function called convertToCsv will be executed with the given requests. Finally the file will be downloaded and deleted after sending: return response() ->download($destinationFilePath) ->deleteFileAfterSend(true); This works good. Now i want to test my form if the file was

kulka1's avatar
kulka1's avatar kulka18yrs agoTesting
0
1
chrismay's avatar

Api Test Structure (Model vs Controller vs Route Cest)

I want to test all my api endpoints with codeception. I started off with a more model based approach: class UserCest { public function it_can_request_its_own_status (ApiTester $I) { $user = $I->amLoggedIn(); $I->sendGET('/users/'.$user->id.'/status'); $I->seeResponseCodeIs(200); $I->seeResponseContainsJson(['status' => 'acti

chrismay's avatar
chrismay's avatar chrismay8yrs agoTesting
2
1
Last reply by chrismay 8yrs ago
haakym's avatar

Log in a user test, failed login redirects to `/` instead of back to `/login`?

I've written the following test to check incorrect credentials do not log a user in. /** @test */ public function logging_in_with_invalid_credentials() { $user = factory(User::class)->states('verified')->create([ 'email' => '[email protected]', 'password' => bcrypt('123456'), ]); $response = $this->post('/login', [ 'email' =>

haakym's avatar
haakym's avatar Saneesh6yrs agoTesting
4
1
Last reply by Saneesh 6yrs ago
haakym's avatar

Refactoring a test for user registration

I've written a test to check a user can register. The main outcomes of the registration are that a new user is in the database and is sent an email requesting they verify their registration. The test seemed a bit long to me and I thought I'd get some second opinions here on the forum with how I might refactor it. Here's the code: /** @test */ public function a_user_can_register

haakym's avatar
haakym's avatar mdecooman8yrs agoCode Review
3
1
Last reply by mdecooman 8yrs ago
haakym's avatar

Writing test with form that uses no-captcha

I am writing a test for when a user registers. The registration form has a no-captcha field to prevent bots. I am using the following package to enable the no-captcha functionality: https://github.com/anhskohbo/no-captcha There are some instructions on the readme with how to use the package when writing tests in Laravel, see here: https://github.com/anhskohbo/no-captcha#testing

haakym's avatar
haakym's avatar mcload6yrs agoTesting
2
1
Last reply by mcload 6yrs ago
thebigk's avatar

Why is assertDatabaseHas failing in this test case?

Here's my test case public function an_authenticated_user_may_participate_in_forum() { $this->withoutExceptionHandling(); // Disable exception handling. Throw the exception at right place $user = factory('App\User')->create(); $this->be($user); $thread = factory('App\Thread')->create(); // Thread ID 1 $reply = factory('App\Re

thebigk's avatar
thebigk's avatar thebigk7yrs agoTesting
13
1
Last reply by thebigk 7yrs ago
Bom_Basti's avatar

[SOLVED but not SOLVED] Test the subject and from-address

Hi, I want to test the "to", "from" and "subject" of an Mailable in Laravel 5.5. If I write my test like this, everything is working fine, if the "to" address matches. Mail::assertSent(NewOffer::class, function ($mail) { return $mail->hasTo('[email protected]'); }); But if I want to test the "from" and "subject&q

Bom_Basti's avatar
Bom_Basti's avatar atorscho5yrs agoTesting
4
1
Last reply by atorscho 5yrs ago
thebigk's avatar

How does reply get added to correct thread in this test?

I'm currently revising the Lesson 4 of building a forum with TDD approach and wondering why the following test works [ Ref: https://github.com/laracasts/Lets-Build-a-Forum-in-Laravel/blob/76a05a038ae9a846df9b11ab1fcff48376ce74cf/tests/Feature/ParticipateInThreadsTest.php ] In the following test, we create a thread and then create a reply and assume that the reply gets added to

thebigk's avatar
thebigk's avatar JeffreyWay8yrs agoTesting
1
1
Last reply by JeffreyWay 8yrs ago
donniebrandt's avatar

Root domain redirects to test subdomain

Problem: www.domain.com is automatically redirecting to test.domain.com. Context: I have used Forge to set up a web server at DigitalOcean. This server has two sites on it: domain.com which is fully configured, but always defers to test. test.domain.com which is fully configured and working. I have the domain routed through Cloudflare and have two A records configured: A |

donniebrandt's avatar
donniebrandt's avatar donniebran...8yrs agoForge
3
1
Last reply by donniebrandt 8yrs ago
saqueib's avatar

unable to test filesystem temporaryUrl

Laravel Version: 5.5.11 PHP Version: 7.1 Database Driver & Version: MySQL Description: I have written some test to verify that a file exists on s3 and download when tried to test Storage::disk('s3')->temporaryUrl($url, $urlExpires); It gives 500 error with this msg but the code works when test by the browser. This driver does not support creating temporary URLs Steps

saqueib's avatar
saqueib's avatar ABRAR@ARCH...4yrs agoTesting
6
1
Last reply by [email protected] 4yrs ago
janduano's avatar

Problem running Laravel Dusk test in Travis

Hello everyone, I'm trying to get Travis to run the Dusk test, but I always get an error. The tests work well on my local environment, but when Travis run the Test I get an error like this: NoSuchElementException: no such element: Unable to locate element: Travis configuration: sudo: required language: php dist: trusty php: - 7.1 install: - cp .env.travis .env - travis_

janduano's avatar
janduano's avatar monahajt8yrs agoTesting
1
1
Last reply by monahajt 8yrs ago
Bom_Basti's avatar

Empty database after test

Hey guys I want to start with TDD and have a strange problem: I've added these lines to my phpunit.xml: <php> <env name="APP_ENV" value="testing"/> <env name="CACHE_DRIVER" value="array"/> <env name="SESSION_DRIVER" value="array"/> <env name="QUEUE_DRIVER&

Bom_Basti's avatar
Bom_Basti's avatar tykus8yrs agoTesting
5
1
Last reply by tykus 8yrs ago
princelionelnzi's avatar

Test Laravel Notification using PHPUnit

Hello, I am new to PHPUnit and I just made a test to send a notification after a new user is registered. /** @test */ function a_confirmation_email_is_sent_upon_registration() { Notification::fake(); $user = $this->post(route('register'), [ 'name' => 'John', 'email' => '[email protected]', 'password' =>

princelionelnzi's avatar
princelionelnzi's avatar Medoucine8yrs agoTesting
2
3
Last reply by Medoucine 8yrs ago
dacastro4's avatar

Getting status 419 running a phpunit test

Hey Guys. I have a weird issue that i don’t understand entirely. I’m running a test but a I’m getting a ng $member = factory(User::class)->create([ 'type' => 'member' ]); $title = "Random Title for Test."; $case = factory(DentalCase::class)->raw(['title' => $title]); $response = $this->actingAs($member) ->post('/cases/create', $case); $response->

dacastro4's avatar
dacastro4's avatar scott_mcmu...1yr agoTesting
9
1
Last reply by scott_mcmullan 1yr ago
tsaicharlie93's avatar

Select function not working for Browser test

Hi Guys, I am getting an weird error from select function in browser test using laravel The error is : no such element: Unable to locate element: {"method":"css selector","selector":"body #editRank1 textarea[name='rank']"} My test code is : $browser->loginAs($user) ->visit('/view/1') ->click('[name

tsaicharlie93's avatar
tsaicharlie93's avatar bheath8yrs agoTesting
1
1
Last reply by bheath 8yrs ago
deconf's avatar

Laravel Dusk: test page using POST method

Hi, I want to test page using POST method using my parameters, is this possible?

deconf's avatar
deconf's avatar deconf8yrs agoTesting
0
1
DivDax's avatar

phpunit: How to test write to log file

i'm really new to phpunit testing and want to test if something was written to the logfile. How you would test this?

DivDax's avatar
DivDax's avatar eugenevdm3yrs agoTesting
4
1
Last reply by eugenevdm 3yrs ago
Lars-Janssen's avatar

Why do I always get a 404 in my test?

Hi, In my package I'm testing an api endpoint, but I always get a 404 response!?!? Here is the file (see unsuccessfulLogin method): https://github.com/larsjanssen6/underconstruction/blob/master/tests/Integration/UnderConstructionModeTest.php $this->post('/under/check', ['code' => 1235]) In my service provider: https://github.com/larsjanssen6/underconstruction/blob/master

Lars-Janssen's avatar
Lars-Janssen's avatar Jaytee8yrs agoLaravel
1
1
Last reply by Jaytee 8yrs ago
iamfaiz's avatar

How to test if a helper function was called inside a class method?

Say I am testing the following class in PHPUnit: class ExampleClass { public function exampleMethod() { example_helper_function('firstArg', 'secondArg'); } } How can I test if example_helper_function was called with the arguments 'firstArg' and 'secondArg' when exampleMethod was run? In other words, how can I mock functions that are not class methods?

iamfaiz's avatar
iamfaiz's avatar Cronix8yrs agoTesting
2
1
Last reply by Cronix 8yrs ago
Christofer's avatar

Test Successful, but fails in full phpunit test all

Issue: Test does not work when running phpunit on whole test folder. My test passes "green" when I use --filter TestFunctionName Update: It may have something to do with boot::saving() calculating and updating the record when saving. I've spent a long time today trying to debug code and fix code that was not broken, waaahhh. ;-( Is this one of those "Testing with

Christofer's avatar
Christofer's avatar Christofer8yrs agoTesting
5
1
Last reply by Christofer 8yrs ago
X-Strike's avatar

How do you test the Job Class?

How do I test all the functionality in the Job Class to make sure it is working correctly? Is it possible to do this while faking the Queue? I can't use Queue::fake(); because that is just to assert that it is queued or dispatched. It does not execute any methods in the Queue. For Example: /** * @test */ public function it_has_successfully_uploaded() {

X-Strike's avatar
X-Strike's avatar X-Strike8yrs agoLaravel
0
1
andersfloor's avatar

Dusk test does not see database update

I'm trying to replicate the Email verification lesson in Laravel 5.5 using Dusk for testing. I'm running into an issue where my test procedure does not see the database update after a user has confirmed his registration through the link. This is my test procedure: public function test_a_user_may_register_but_must_confirm_email_address() { $this->browse(functi

andersfloor's avatar
andersfloor's avatar timur_z807yrs agoTesting
4
1
Last reply by timur_z80 7yrs ago
thebigk's avatar

Why is this test failing, when 'found' shows the expected record?

I'm pasting the output of phpStorm exception obtained from phpUnit: Failed asserting that a row in the table [questions] matches the attributes [ "title", "Rerum quis dolores quas sint repudiandae qui." ]. Found: [ { "id": "1", "user_id": "2", "title": "Rerum quis dol

thebigk's avatar
thebigk's avatar thebigk8yrs agoTesting
1
1
Last reply by thebigk 8yrs ago
thebigk's avatar

Simple test: It passes when it should actually fail

This is my first attempt at writing tests and I'm super confused about what's going on. Here's my first test - /** @test */ public function an_authenticated_user_can_view_add_a_question_form() { $this->withExceptionHandling(); $this->signIn(); $this->get('questions/add') ->assertSee('Add New Question'); } I haven't yet de

thebigk's avatar
thebigk's avatar thebigk8yrs agoTesting
1
1
Last reply by thebigk 8yrs ago
tsaicharlie93's avatar

Trying to do a Login test from browser test

I am trying to use login test from browser testing. Here is my code: $this->browse(function (Browser $browser) { $browser->visit('/login') ->clear('email') ->clear('password') ->type('email', '[email protected]') ->type('password', 'password') ->press('Login')

tsaicharlie93's avatar
tsaicharlie93's avatar tsaicharli...8yrs agoLaravel
2
1
Last reply by tsaicharlie93 8yrs ago
Anonymous194's avatar

PhP Unit, risky test? What's the cause of it and how to avoid

Hi, I followed documentation for laravel php unit tests on laravel website. However, the tests I have give me this output: PHPUnit 6.3.0 by Sebastian Bergmann and contributors. RRRRRR 6 / 6 (100%) Time: 8.53 seconds, Memory: 16.00MB There were 6 risky tests: 1) Tests\Unit\ResponseTest::testHomePage Test code or te

Anonymous194's avatar
Anonymous194's avatar lemaur7yrs agoTesting
9
14
Last reply by lemaur 7yrs ago
Mikeritteronline's avatar

Laravel 5.3 style test fails to see user email constructed from factory

Here's my test public function test_i_can_see_my_name_and_email() { $user = factory(User::class)->create(); $this->actingAs($user)->get('/admin/user')->see($user->email); } The route is protected, and authentication passes. When I run this in my browser all is well. But my test fails every time. I've even run dd($user->email) and it looks good. Here'

Mikeritteronline's avatar
Mikeritteronline's avatar Mikeritter...8yrs agoLaravel
1
1
Last reply by Mikeritteronline 8yrs ago
4jZW7jVSdS4U6PC's avatar

Help figuring out how to test on demand notification

Hello Everyone. I have a slack notification class that sends a message inside our company slack, in a specific channel, every time an user performs the activation process. The system works, but it's manually tested and that's not cool. The notification is sent by a listener attached to an UserHasBeenActivated event, the listener is the following: public function handle(User

4jZW7jVSdS4U6PC's avatar
4jZW7jVSdS4U6PC's avatar rkallenkoo...4yrs agoTesting
5
12
Last reply by rkallenkoot 4yrs ago
GroundZero's avatar

Test fails, always 500 where 200 expected

Ha guys, i am trying to make some unit tests, unfortunately I always receive a 500 error where a 200 is expected. I can visit my website anywhere, its fully functional and working, just Unit tests wont work, always errors no matter what kind of test I do. I tried checking the log, but the errors there are replaces with dots (to shorten them) so I have no clue if those are messi

GroundZero's avatar
GroundZero's avatar mpak8yrs agoTesting
3
1
Last reply by mpak 8yrs 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.