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

jrdavidson's avatar

Rephrasing test.

Any suggestions on how to improve on the naming of the variables in this test or maybe I need to re-write the assertion. Problem is a championship consists of a wrestler and a title. The records in the database of a wrestler holding a title are referred to as a championship. But I'd like to figure out what I can do so that it makes more sense that the champion loses the title.

jrdavidson's avatar
jrdavidson's avatar jrdavidson7yrs agoTesting
0
1
radosun's avatar

Guard Test

I am trying to get a set of gates to work in AuthServiceProvider, none are, so I decided to test out creating a completely open gate Gate::define('open', function () { true; }); @can('open') gate is open and working @endcan It does not work either, instead nothing displays... I am thinking if this gate doesn't work then no other gate in my application will either. Is this a val

radosun's avatar
radosun's avatar radosun7yrs agoLaravel
2
1
Last reply by radosun 7yrs ago
Tray2's avatar

Test fails even if the required value is in the database.

I have a test that I can't get to pass due to a validation error. I have this in my store method public function store(Request $request) { $request->validate([ 'author_id' => 'required|exists:authors, id', 'title' => 'required' ]); $book = new Book(); $book->author_id = $request->author_id; $book-&g

Tray2's avatar
Tray2's avatar Tray27yrs agoTesting
8
1
Last reply by Tray2 7yrs ago
jurandou's avatar

Test field unicity with formRequest on function boot

Hi, I'm trying to generate a slug with my Post title, using boot model function with static::creating. It works fine while it's unique. But if this duplicates existing slug, i cant' achieve to pass the test of my NewsFormRequest in the store resource method, and i'm getting the Integrity constraint violation: 1062. I guess i'm missing something logic, don't know what... Thanks

jurandou's avatar
jurandou's avatar jurandou7yrs agoRequests
8
1
Last reply by jurandou 7yrs ago
pedroroccon's avatar

Single test passing, but fails when running all tests (404 error)

Hello! I'm facing a strange issue in my testing class. Well, I'm using Laravel 5.5 with PHPUnit 5.7 and testing a file upload. Here's my file EmpresaLogotipoImagemTest.php <?php namespace Tests\Feature; use Tests\TestCase; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; use Illuminate\Foundation\Testing\RefreshDatabase; class EmpresaLogotipoImage

pedroroccon's avatar
pedroroccon's avatar pedrorocco...7yrs agoTesting
3
1
Last reply by pedroroccon 7yrs ago
AlbertMulaki's avatar

How can i test that the authorize method has authorized the user to do the request.

How can i test that the authorize method has authorized the user to do the request, and check if this function has been called. I have about 7 roles: $roles = [ 'SuperAdmin', 'Admin', 'MediaAdmin', 'InstitutionAdmin', 'DataEntryUser', 'ViewOne', 'ViewAll' ]; Right now i do something like this: public function test_super_admin_can_create_a_patien

AlbertMulaki's avatar
AlbertMulaki's avatar martinbean7yrs agoTesting
3
1
Last reply by martinbean 7yrs ago
spacedog4's avatar

Do something when Unit Test fails

In my test I create a model so I can test my command, but if the test fails, I want to remove my model but it never reachs File::delete(app_path() . '/Test.php'); How can I make some method that reachs when the assert fails? public function test_if_it_generate_view_files() { $model_name = 'Test'; Artisan::call('make:model', [ 'name' => 'Test'

spacedog4's avatar
spacedog4's avatar spacedog47yrs agoLaravel
2
1
Last reply by spacedog4 7yrs ago
AlbertMulaki's avatar

How can i test that the authorize method has authorized the user to do the request.

How can i test that the authorize method has authorized the user to do the request, and check if this function has been called. /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { $comment = Comment::find($this->route('comment')); return $comment && $this->user()->can('update', $comment)

AlbertMulaki's avatar
AlbertMulaki's avatar AlbertMula...7yrs agoTesting
4
1
Last reply by AlbertMulaki 7yrs ago
webRookie's avatar

Why I can not test that exception is throw?

Hi, I can not test the exception is throw in my test case even if it is the test do not pas: Tests\Feature\QuizPageTest::test_if_questionID_is_invalid_redirect Failed asserting that exception of type "\Illuminate\Database\Eloquent\ModelNotFoundException" is thrown. I have in testClass: use Exception; use Illuminate\Database\Eloquent\ModelNotFoundException; /** * @ex

webRookie's avatar
webRookie's avatar webRookie7yrs agoTesting
6
1
Last reply by webRookie 7yrs ago
mcbates's avatar

How to get concise feedback on what went wrong in a http request based test?

Say I have the following test to test whether login works /** @test */ public function a_user_giving_correct_login_data_can_log_in() { $user = factory(User::class)->make(); $options = [ 'email' => $user->email, 'password' => $user->password, ]; $response = $this->post('/login', $options);

mcbates's avatar
mcbates's avatar m7vm7v7yrs agoTesting
3
1
Last reply by m7vm7v 7yrs ago
hasandev's avatar

How to test specific test in Laravel.

I want to test something specifically in Laravel. Let's say, testUserTest(). I want to test only this. How can I do that instead to running test on everything?

hasandev's avatar
hasandev's avatar Carolyngay...10mos agoTesting
9
26
Last reply by Carolyngaynor 10mos ago
Majeed's avatar

How to test personal access token using Guzzlehttp in laravel

I'm working on Laravel Passport. I have created a personal access token. Now, I want to test it using guzzlehttp Client. How can i do this. I'm try this way it's not working. my routes/web.php Route::get('/callback', function (Request $request) { $response = (new GuzzleHttp\Client)->post('http://passportauth.test/oauth/token', [ 'form_params' => [

Majeed's avatar
Majeed's avatar Majeed7yrs agoLaravel
2
1
Last reply by Majeed 7yrs ago
mikail10000000's avatar

How to locally test cross website app

Hi, I'm writing an app that will involve an iframe and pulling a js widget from my website to a third party website , and I want to test it locally , I use laragon as my local dev , what would be a good way to set it up, thank You

mikail10000000's avatar
mikail10000000's avatar m7vm7v7yrs agoGeneral
1
1
Last reply by m7vm7v 7yrs ago
hepabolu's avatar

Statement on SQLite test database returns null while record is available

I'm trying to test a function that tries to fuzzy match a name to a name in the database. Basically: givenName = 'Peter' familyName = 'Pan' match('Peter Joe Pan') should return the record. The query running on a MySQL db would be Person::whereRaw('"' . $name . '" like concat(givenName , "%", familyName)')->first(); When I run my test where I test 'Pet

hepabolu's avatar
hepabolu's avatar hepabolu7yrs agoTesting
2
1
Last reply by hepabolu 7yrs ago
seamuswc's avatar

PhpUnit, How to dictate which test file to test

vendor/bin/php currently tests: 'tests/Unit/ExampleTest.php How to I specify when I want to test: 'tests/Feature/ExampleTest.php Or other test file names within the tests folder. Thanks

seamuswc's avatar
seamuswc's avatar lostdreame...7yrs agoLaravel
1
1
Last reply by lostdreamer_nl 7yrs ago
kitman's avatar

Best practice of unit test for search function

Hi, We are trying to write the unit test for a search function. The search function will then create a database query based on user input, since there are some many cases I assume that no one will write the case one by one, so I wanted to ask what is the best practice of doing unit test for a search function?

kitman's avatar
kitman's avatar bobbybouwm...7yrs agoTesting
1
2
Last reply by bobbybouwmann 7yrs ago
webRookie's avatar

is this a good way to test if the controller sends the desired collection to the view?

here is my code is this a good way to test if the controller sends the desired collection to the view? this is correct? It passes but I don't know ->assertSee($quiz->first()->description) ->assertSee($quiz->first()->questions->first()->body); /* given there is a quiz that has many questions when user visit quiz page see quiz questions and possible answe

webRookie's avatar
webRookie's avatar alanholmes7yrs agoTesting
3
1
Last reply by alanholmes 7yrs ago
ntraykov's avatar

Mocking the document object when writing Vue test

I want to test whether the document.location.hostname is correctly set in my component, but in my tests, I don't know how to mock the document object. I tried with jsdom, but without any success. Any help would be great! Thank you!

ntraykov's avatar
ntraykov's avatar ntraykov7yrs agoVue
0
1
rajcoder's avatar

Dusk test not working as expected

I am using dusk for testing and have encountered a problem. I have 2 test functions in ExampleTest file. In the first test, I am creating a factory user and logging him through login form and asserting that user should see home. This works. But the second test, where I again visit login page and enter wrong credentials, fails as I guess it somehow maintains the session for the

rajcoder's avatar
rajcoder's avatar jamienatha...7yrs agoTesting
5
2
Last reply by jamienathaniel 7yrs ago
jrdavidson's avatar

Improving Names For Test File

Any suggestions on the naming of my test cases or how I can refactor my tests. I'm also trying to figure out how to modify the a_title_match_with_no_champion_can_crown_a_champion_depending_on_match_decision and a_title_match_with_a_set_champion_that_wins_a_title_match_keeps_the_title_and_increases_successful_defensesbecause of trying to figure out the set up of the MatchFactory

jrdavidson's avatar
jrdavidson's avatar xtremer3607yrs agoCode Review
1
1
Last reply by xtremer360 7yrs ago
pimski's avatar

How do you test database notifications?

Hi there, How do you test database notifications? The following piece of code works when running in the browser, but gives no results when running in a test case: auth()->user()->notify(new \App\Notifications\ExportFinished); dd(\DB::table('notifications')->select()->get()); // empty result set in test Is the test 'mocking' the notification? I'm not calling Notific

pimski's avatar
pimski's avatar Opinodo5yrs agoTesting
10
8
Last reply by Opinodo 5yrs ago
ddw147's avatar

Http test redirecting to \ instead of login

Hi I am trying out testing in laravel5.6, but when try to test invalid login like below public function testInvalidLogin() { $response = $this->post('/login',[ 'email'=>'[email protected]', 'password'=>'secret' ]); $response->assertStatus(302); $response->assertLocation('/login'); } but when i run this i got error Failed asserting that

ddw147's avatar
ddw147's avatar ddw1477yrs agoTesting
2
1
Last reply by ddw147 7yrs ago
jcharcosset's avatar

Test lumen package

I develop external package to be used in lumen. In my package, I use global method config() and abort() who comes Lumen package . I include Lumen like a dependency of my project but this classes are not initialize because I haven't bootstrap/app.php in my package. So, PHPunit returns : ReflectionException: Class config does not exist I create dummy class to define this method

jcharcosset's avatar
jcharcosset's avatar jcharcosse...7yrs agoTesting
4
1
Last reply by jcharcosset 7yrs ago
mottihoresh's avatar

Dusk test works on isolation, breaks when run as part of the other tests.

I have a test file that is responsible for verifying a workflow that a user may take. For some reason, it seems like that when i run the test, the database is destroyed before it finish to test it. The test that fails is: the_campaign_mapping_page_should_list_all_campaigns_and_bucket_mappings, it only fails when running the full test suite, it passes when running it on it's own

mottihoresh's avatar
mottihoresh's avatar impbob7yrs agoTesting
1
1
Last reply by impbob 7yrs ago
mackth's avatar

Is it possible to test an abort that was called inside a model?

Hi everyone, I want to unit test my User Model if the assignRole method would throw an error if an invalid role name was entered. The method inside looks like this: public function assignRole($role) { $role = Role::where('name', $role)->first(); if (! $role) { abort(422, "Invalid role assigned"); } $this->roles()

mackth's avatar
mackth's avatar markandrew...8yrs agoTesting
2
1
Last reply by markandrewkato 8yrs ago
jrdavidson's avatar

Refactoring Test Methods

I'm trying to clean up some old code from a project and trying to figure out some ideas on renaming the test functions in a better way so that I nor others have to scratch their head to try to understand what I'm attempting to do. Also any suggestions on if there are areas in the test that I could modify. /** @test */ public function a_non_title_match_can_set_a_winner()

jrdavidson's avatar
jrdavidson's avatar BrandonSur...8yrs agoCode Review
6
1
Last reply by BrandonSurowiec 8yrs ago
darkec's avatar

Does RefreshDatabase rollback changes after each test of at the end of all

Let's say I have simple test with 2 functions: public function testCreateUser() { User::create(['username' => 'test']); } And this is where I create a user and it has id=1. Now I want to get that user in next test function public function testGetUser() { User::find(1); } Will this user be in my database or will RefreshDatabase rollback my changes after it finish

darkec's avatar
darkec's avatar arukomp8yrs agoTesting
3
14
Last reply by arukomp 8yrs ago
r@fitiiixxx's avatar

Horizon mixing {prod} and {test} supervisors

I've set up two Redis services on the same VM. One with 6379 and the other with 6380 port. I've configured my config/database.app such as: 'redis' => [ 'client' => 'predis', 'production' => [ 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', 6379), 'database' => 0, ], 'test' =&

r@fitiiixxx's avatar
r@fitiiixxx's avatar r@fitiiixx...8yrs agoLaravel
1
1
Last reply by r@fitiiixxx 8yrs ago
flyingL123's avatar

Creating and dropping a table during test breaks RefreshDatabase trait

I've created a trait using in my Laravel 5.6 app. The trait is called Projectable. This trait is meant to be used by Eloquent models. In order to test the trait, I wanted to create a ProjectableStub model to use in the tests. However, since this is an Eloquent model, it requires a table. I wanted to simply create and drop a table just for testing. However, when I do this, it se

flyingL123's avatar
flyingL123's avatar flyingL1238yrs agoTesting
1
1
Last reply by flyingL123 8yrs ago
behnampmdg3's avatar

What can you tell from these test results? Api Pressure test.

What can you tell from these test results? Help me understand, please. Can this system handle 10000 posts per minute without losing the posted data? 3000 posts per minute https://loader.io/reports/238ac2f2f04eac23fb74ff5e1dcd8b5b/results/abec3548aa5b649e677d15e9467302c9#connectionsponse_details 10000 posts per minute: https://loader.io/reports/238ac2f2f04eac23fb74ff5e1dcd8b5b/r

behnampmdg3's avatar
behnampmdg3's avatar bulforce8yrs agoGeneral
19
1
Last reply by bulforce 8yrs ago
valeraefimov696's avatar

How to correctly write a unit test for controllers methords in laravel 5.5?

Please check the code I used to in my controller: class ObjectsPagesController extends Controller { public function store(Create $request) { $group = DeviceGroups::findOrFail($request->get('group_id')); $objectsPage = new ObjectsPages(); $objectsPage->fill($request->all()); $image = $request->file('image'); $filename

valeraefimov696's avatar
valeraefimov696's avatar Robstar8yrs agoLaravel
3
1
Last reply by Robstar 8yrs ago
shiroamada's avatar

How to enable Dusk Test, open Chrome to view the whole process

Is there any way to let Dusk Test to open Chrome to view the whole Test process. Current Dusk only have option --headless for show the Chrome windows when it is fail. I would like to view the whole Testing Progress to really see what happen. Is it possible?

shiroamada's avatar
shiroamada's avatar shiroamada8yrs agoTesting
3
1
Last reply by shiroamada 8yrs ago
naing's avatar

test case for HTML Select option spoofing

Hi experts, My HTML blade for Select: @foreach(App\Model\Master\Country::all() as $country) <option value='{{$country->id}}'> {{$country->name}} </option> @endforeach My validatoin rule: 'country' => ['required',new CountryRule], This will return false if user enters(spoofs) incorrect id in HTML request. I can test it manually by enter

naing's avatar
naing's avatar naing8yrs agoTesting
2
1
Last reply by naing 8yrs ago
chriz74's avatar

can't run a test app on skysilk vps -> Forbidden

I am trying to put up a test app on skysilk vps, I added it to my folder /home/user/www/test I added vhost, hosts and all the stuff. If I go to the page it tells me Forbidden.

chriz74's avatar
chriz74's avatar chriz748yrs agoServers
1
1
Last reply by chriz74 8yrs ago
Jonjie's avatar

Why do we need other package to test?

Hi. I'm just thinking why do we really need to use other packages like PHPUnit to test our application? Why not just using the application on how users use it? Like for example if we have a registration functionality, why not just test it by just using the application itself? Sorry but I'm really confused about it. I also read this https://softwareengineering.stackexchange.com/

Jonjie's avatar
Jonjie's avatar joshuafran...8yrs agoTesting
2
2
Last reply by joshuafranks 8yrs ago
Hameed's avatar

Unable to deploy a test application in Forge

Hi Guys, I am new to forge and I am trying to deploy a test application but I keep getting an error related to database user configuration. When I had a look at my .env file in forge it is empty so my questions are do I need to generate the whole .env file or I only need to update variables needed such as the database configurations. Does forge create a default .env file when

Hameed's avatar
Hameed's avatar Hameed8yrs agoForge
10
7
Last reply by Hameed 8yrs ago
krystian2160's avatar

Laravel - when hitting web route twice in one test (get request)

Earlier in the test I have $response = $this->get(route('home')); $response->assertSee($goal->name); Then some action, other lines of code And then $response = $this->get(route('home')); $response->assertDontSee($goal->name); And the assertion fails. But it shouldn't. It works great! And when I remove earlier two lines of code, I mean: $response = $this->

krystian2160's avatar
krystian2160's avatar krystian21...8yrs agoTesting
5
1
Last reply by krystian2160 8yrs ago
Webiondev123's avatar

phpunit testing cannot find file and cannot test globally

I am unable to run phpunit test from root folder but when I change to vender/bin I can run phpunit but cannot test. It says cannot open file c:\wamp64\www\fundtheneedy>phpunit 'phpunit' is not recognized as an internal or external command, operable program or batch file. c:\wamp64\www\fundtheneedy\vendor\bin>phpunit ExampleTest Cannot open file "ExampleTest.php&

Webiondev123's avatar
Webiondev123's avatar tykus8yrs agoTesting
3
1
Last reply by tykus 8yrs ago
andremac96's avatar

Acceptable Unit Test?

Is this an acceptable test? I have a user model with the following fields. Name, Email, Password and UserType. I'm testing the register page. This is the testing code public function testExample() { $this->visit('/register') ->type('Andre MacNamara', 'name') ->type('[email protected]', 'email') ->type('Landlord', 'userType') ->type

andremac96's avatar
andremac96's avatar lostdreame...8yrs agoTesting
1
1
Last reply by lostdreamer_nl 8yrs ago
AR's avatar

Event/Listener working fine in browser but not working in test

I have an event/listener that works fine in the browser but in my test the event runs (when I dd() in its construct method) but the listener does not fire. Here is my test: <?php namespace Tests\Feature; use Tests\TestCase; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Event; use App\Events\ArticleHasNewComment; use Illuminate\Support\Fac

AR's avatar
AR's avatar godbout7yrs agoTesting
2
1
Last reply by godbout 7yrs ago
stefr's avatar

Realtime facade with constructor in Test

Hi, I have a class like this, where I can override an email when I need to in the constructor: class MyClass { protected $email; public function __construct($email = null) { $this->email = (null == $email) ? \Auth::user()->email : $email; } public function foo() { return 'bar'; } } Now in my tests I want to leverage the rea

stefr's avatar
stefr's avatar stefr8yrs agoLaravel
0
1
stefanbauer's avatar

Test the order of fired events

Just a quick question: With the Event::fake(), it's easy to test if an event has been fired. So far, so good. Is it somehow possible, to test that events have been fired in a specific order?

stefanbauer's avatar
stefanbauer's avatar stefanbaue...8yrs agoTesting
0
1
farhadkb6868's avatar

The response is not a view message when unit test fails in laravel 5.5

I am new in laravel 5.5 unit testing. I wrote a method in NewsController names index. It returns a view like below: public function index(Request $request) { $news = DB::table('news')->orderBy('created_at', 'desc')->get(); $data['news'] = $news; return view('news.index')->with($data); } I wrote a test for that like below: public function testIndex(){

farhadkb6868's avatar
farhadkb6868's avatar miranalmeh...2yrs agoTesting
4
1
Last reply by miranalmehrab 2yrs ago
behnampmdg3's avatar

How to test simple api endpoint to see if it can handle 100k or more calls (I dunno how many)

Hello; I want to test an API endpoint under pressure. This endpoint may receive up to 100k requests via API at one time. I'm using transactions. I want to be able to test it before I go live. I tested with 4k API calls and it all worked smoothly. Senders may queue their calls but since this is open to different systems, I gotta be prepared for anything. Thank you for tips Here

behnampmdg3's avatar
behnampmdg3's avatar avaneeshsi...8yrs agoTips
2
1
Last reply by avaneeshsingh 8yrs ago
towhid's avatar

SQLSTATE[HY000]: General error: 1364 Field 'category_id' doesn't have a default value (SQL: insert into `posts` (`title`, `body`, `cover_image`, `user_id`, `updated_at`, `created_at`) values (country, this is test country, C:\xampp\tmp\php9C8E.tmp, 2, 201

When i am using this code my controller $post=new Post; $post->category_id = $request->input('category_id'); $post->title = $request->input('title'); $post->body = $request->input('body'); $post->cover_image = $fileNameToStore; $post->user_id = Auth()->id(); $post->save(); this is model cod

towhid's avatar
towhid's avatar towhid8yrs agoLaravel
2
1
Last reply by towhid 8yrs ago
jesus143's avatar

When is the best time to create test case in a project?

Can anyone tell me when the best time to create test case in a project, is it can make the development process faster or slower. Just simply pros and cons. Thanks in advance! Cheers! Jesus

jesus143's avatar
jesus143's avatar N38yrs agoLaravel
1
1
Last reply by N3 8yrs ago
Reppair's avatar

Change Config from test case and test routes..

HI, I have a service provider and there I register some routes.. if a given config value is true/false I register different set of routes. Can I somehow change from my tests which routes get registered? If I use the Config facade to set new config value and list the routes they are still the same as they were before changing the config. $this->default_locale_in_uri = Config

Reppair's avatar
Reppair's avatar reppair8yrs agoTesting
2
1
Last reply by reppair 8yrs ago
wesmahler's avatar

Test Queue Connection Works for Healthcheck

How can I test to make sure the queue connection works? I want to add this test to our production's healthcheck file. We want it to check to make sure the QUEUE connection is working. Without having to dispatch a job.

wesmahler's avatar
wesmahler's avatar bobbybouwm...8yrs agoLaravel
2
1
Last reply by bobbybouwmann 8yrs ago
aelashley's avatar

Where should I test for element focus?

We have an application that has a Vue.js front end and a Laravel API back end. We have tests in vue-test-utils, PHPUnit, and Dusk for various things. I've started to write a Dusk test to make sure that a particular element receives focus after a form is submitted. But I can't see a clear way to do that in Dusk and now I'm wondering if Dusk is even the place to do it. Here is t

aelashley's avatar
aelashley's avatar Cronix8yrs agoTesting
1
1
Last reply by Cronix 8yrs ago
newnyc's avatar

login test in laravel 5.0 returning a json

I would like to get a user login test sample that returns a json in laravel 5.0

newnyc's avatar
newnyc's avatar newnyc8yrs agoLaravel
0
1

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.