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

PoncetheLion's avatar

PHPUnit MySQL in memory test with point and polygon column

I have a migration for a table as following: use Illuminate\Support\Facades\Schema; use Grimzy\LaravelMysqlSpatial\Schema\Blueprint; //use this as blueprint use Illuminate\Database\Migrations\Migration; Schema::create('properties', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->point('position'); $t

PoncetheLion's avatar
PoncetheLion's avatar gourab6yrs agoCode Review
9
1
Last reply by gourab 6yrs ago
meijdenmedia's avatar

Unit Test "deep" relational data

Dear community, In Laravel it is very normal to get data from related objects like $customer->wallet->balance. What is the best approach in testing the value of the customers' current balance? Sometimes this even goes a layer deeper. Thanks!

meijdenmedia's avatar
meijdenmedia's avatar meijdenmed...7yrs agoTesting
3
6
Last reply by meijdenmedia 7yrs ago
Ben94's avatar

Test Database with multiple Databases

I have created an .env.testing with the following data: DB_CONNECTION=sqlite DB_DATABASE=database/test.sqlite So everytime I ran phpunit it put the data in the test.sqlite file. However, I now need to use two development databases, so I added these lines to my Models. class ExampleModelOne { protected $connection = 'mysql'; ... } class ExampleModelTwo { protected

Ben94's avatar
Ben94's avatar shez19837yrs agoTesting
1
1
Last reply by shez1983 7yrs ago
lishaliu's avatar

seeding works in command line but not in phpunit test file

I run database seeding using php artisan db:seed everything works fine; but if I put $this->seed('DatabaseSeeder'); in the TestCase.php set up class after refresh database, I ran into issues: foreign key constraint.... this is my TestCase.php file: <?php namespace Tests; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; use Illuminate\Foundation\Testing\Refres

lishaliu's avatar
lishaliu's avatar Kel_7yrs agoTesting
3
1
Last reply by Kel_ 7yrs ago
JorickL's avatar

Swap class when running test?

In my Laravel 5.7 I want to 'fake' an API endpoint of a service we use. I've created a 'Fake class' which acts as the API. In my models I whip up a new connection to the external API like this: $connection = (new TicketAPI)->bookings($attributes); This works, like a charm. Now, I want to replace, or 'swap' the TicketAPI::class when I'm running tests. So, I thought I could u

JorickL's avatar
JorickL's avatar Talinon7yrs agoTesting
7
1
Last reply by Talinon 7yrs ago
PatrickSJ's avatar

How to have JSON_NUMERIC_CHECK applied on test response?

If I take an object and assert a JSON response has it using $response->assertJsonFragment($new_labor->toArray()); then it fails with float/decimal numbers because 16.5 is not "16.50". I can get around this manually simply by decoding the response and looping through the keys, but is there a built-in way to handle this that I've missed? Maybe something I can set

PatrickSJ's avatar
PatrickSJ's avatar PatrickSJ7yrs agoTesting
1
1
Last reply by PatrickSJ 7yrs ago
Thyrosis's avatar

Custom service provider gives Purify errors in PHPUnit test

Hi guys, This is a weird one. I'm trying to add some extra allowable HTML elements to Steve Baumans' Purify. It takes a custom ServiceProvider, seeing as the element (anchor target) isn't 'officially' allowed. Now, don't get me wrong, it works. Perfectly. When showing database-content, the anchor target attribute is shown. But when I run my tests, half of them fail with the fol

Thyrosis's avatar
Thyrosis's avatar Thyrosis7yrs agoTesting
11
9
Last reply by Thyrosis 7yrs ago
NoTimeForCaution's avatar

Adding Factory to test POST

How can I refactor the below $attributes = [ 'sector' => 'CARGO', 'name' => strToUpper($this->faker->word) . ' AIRWAYS', 'icao' => 'ABC', 'iata' => 'AB', ]; $response = $this->actingAs($admin)->post('/admin/airline', $attributes) To the following $response = $this->actingAs($admin)->post('/a

NoTimeForCaution's avatar
NoTimeForCaution's avatar DawgOnKing7yrs agoTesting
7
1
Last reply by DawgOnKing 7yrs ago
MichalOravec's avatar

How test forked laravel package?

For example for this package laravel-paginateroute. When I clone to local machine a run phpunit from console. I got some errors. Problem is becouse this return NULL.

MichalOravec's avatar
MichalOravec's avatar MichalOrav...7yrs agoTesting
2
1
Last reply by MichalOravec 7yrs ago
hasandev's avatar

Laraval Passport Authentication Test

Hello I am using Laravel Passport for my API authentication. Now, there are some endpoints those are required to be authenticated to access. However, once I use- Passport::actingAs( factory(User::class)->create() ); It show's me Expected status code 200 but received 403. that means redirect to other page. It's clearly shows that, it doesn't authenticate

hasandev's avatar
hasandev's avatar hasandev7yrs agoTesting
0
1
Kirk.Franklin's avatar

ReflectionException: Class request does not exist running unit test

I'm getting a Class request does not exist ReflectionException running phpunit. I've run composer dump and php artisan clear:compiled. Laravel 5.7. <?php declare(strict_types=1); namespace Tests\Unit; use DemoSite\Data\Authors\Author; use DemoSite\Data\Authors\AuthorRepository; use Tests\TestCase; use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundat

Kirk.Franklin's avatar
Kirk.Franklin's avatar Kirk.Frank...7yrs agoTesting
3
1
Last reply by Kirk.Franklin 7yrs ago
behnampmdg3's avatar

Basic Split Test Without DB Access

Hi; I want to send half of the traffic to Yahoo and have to Google. 1 - Is this way of redirecting correct? 2 - Anyways to make the distribution 100% accurate? Thanks $rand=rand(1,2); $url = "https://yahoo.com"; if($rand==1) { $url = "https://google.com"; } header('Location: '.$url);

behnampmdg3's avatar
behnampmdg3's avatar douglasaku...7yrs agoGeneral
4
1
Last reply by douglasakula 7yrs ago
nickdavies07's avatar

Using cretueusebiu/valet-windows can't connect to .test domains

Not really Laravel specific, but thought I'd ask anyway. Anyone have any experience using cretueusebiu/valet-windows? I've installed as per the guide, configured my DNS to point to 127.0.0.1 and ::1. Pinging any of my projects i.e. app.test returns a reply from 127.0.0.1 successfully. However, visiting app.test in the browser returns 'The requested URL could not be retrieved -

nickdavies07's avatar
nickdavies07's avatar D97059967yrs agoLaravel
3
1
Last reply by D9705996 7yrs ago
nionta's avatar

query execution test

I want to know that does laravel have any builtin way that, "if i have multiple query between a single function/method ,then if any of those query return an exception , the all query result (data saving in the table) that is being executed successfully before the unsuccessful query, will be removed from database table." ????

nionta's avatar
nionta's avatar nionta7yrs agoMix
1
1
Last reply by nionta 7yrs ago
joshuajazleung's avatar

How do you test Laravel Filesystem with AWS?

Is there any resource on testing Laravel with AWS? Any guideline/rule of thumb on this?

joshuajazleung's avatar
joshuajazleung's avatar luciandex3yrs agoTesting
2
1
Last reply by luciandex 3yrs ago
GTHell's avatar

How do I test speed in laravel?

I mean debug the function execution time?

GTHell's avatar
GTHell's avatar wilk_randa...7yrs agoLaravel
1
1
Last reply by wilk_randall 7yrs ago
Chaeril's avatar

need help with factory test and phpunit

$roles = factory(App\Role::class, 5)->create(); $tags = factory(App\Tag::class, 20)->create(); when i run phpunit, i always got Error: Class 'Tests\Feature\App\Role' not found, I've tried to add use App\Role too but it does not work either. what am i missing?

Chaeril's avatar
Chaeril's avatar Chaeril7yrs agoTesting
3
1
Last reply by Chaeril 7yrs ago
garygreen's avatar

Do you unit test model factories? (and their states)

Let's say your using factory(Post::class)->make() to create a Post model in your unit tests, and a post can have various states e.g. published, unpublished. By default, a post will return unpublished. Do you write unit tests to ensure that the factory is returning the default state correctly for use in your tests? I would assume it's a good idea because if a developer on you

garygreen's avatar
garygreen's avatar garygreen7yrs agoTesting
3
1
Last reply by garygreen 7yrs ago
tiagomatosweb's avatar

Vuejs test utils + mocha webpack userAgent error

Hi all, Has anyone come across with this error when run tests? TypeError: Cannot read property 'userAgent' of undefined I'm using this stack https://vue-test-utils.vuejs.org/guides/#testing-single-file-components-with-mocha-webpack Thank you!

tiagomatosweb's avatar
tiagomatosweb's avatar tiagomatos...7yrs agoVue
0
1
uchihaabhi's avatar

Test transactions in Laravel

I have been trying to implement transaction in laravel. But I guess it isn't working. When I change the database field/column name (throwing a force error) the earlier tables gets inserted instead of rolling back. What is happening here?? try { DB::beginTransaction(); $drugInventory = DrugInventory::create([

uchihaabhi's avatar
uchihaabhi's avatar uchihaabhi7yrs agoLaravel
3
1
Last reply by uchihaabhi 7yrs ago
Tarasovych's avatar

Can anybody test my app (problems with Cookies)?

I have back-end Laravel app: GitHub. I have front-end Vue app: GitHub. I'm trying to receive Cookies in my Vue app, but I don't get them. I don't understand what's wrong. Both apps have same subdomain parts locally. Cookie Header exists but there is no Cookies in Developers Console->Application->Cookies. TL;DR //Laravel api routes Route::get('testget', function () { s

Tarasovych's avatar
Tarasovych's avatar Tarasovych8yrs agoCode Review
7
1
Last reply by Tarasovych 8yrs ago
Webiondev123's avatar

login test failed

public function testLoginPost(){ Session::start(); $response = $this->call('POST', 'login', [ 'email' => '[email protected]', 'password' => '123456', '_token' => csrf_token() ]); $this->assertEquals(200, $response->getStatusCode()); $this->assertEquals('auth.login', $response->original->name()); } output

Webiondev123's avatar
Webiondev123's avatar jcphpdev8yrs agoTesting
1
3
Last reply by jcphpdev 8yrs ago
GoTesla's avatar

How to test browser functionality of popups (such as for Payment Request API)

How can I write browser tests for modals like this? In case it matters, I'm using Laravel 5.6 Dusk for browser testing, and my payment request modal is generated via a Stripe Payment Request Button. Stripe's Payment Request Button uses the cross-browser Payment Request API from W3C. Chrome doesn't let me "inspect" the HTML of the elements of the modal, so I'm not sur

GoTesla's avatar
GoTesla's avatar jlrdw8yrs agoLaravel
3
1
Last reply by jlrdw 8yrs ago
beerbuddha's avatar

Better way to submit json data in post test

I currently have this testable piece of code to submit a json filled data via post. I let my controller do its thing and respond back. $responseKey = 'abcdabcd6b1649f681a408f1beebabcd'; $sendJson = $this->createSaleResponse($responseKey); $sendHeaders = [ 'CONTENT_TYPE' => 'application/json' ]; $response = $this->call( 'POST',

beerbuddha's avatar
beerbuddha's avatar wilburpowe...8yrs agoTesting
1
2
Last reply by wilburpowery 8yrs ago
lubart's avatar

csrf_token in PHPUnit test for Laravel 5.2 project

Hi, I'm trying to upgrade Laravel from 5.1 to 5.2 in my project. I have done all instructions from the official manual and project works normally, but some PHPUnit tests are failed. In all failed tests POST call like following is used: \Session::start(); $this->call("POST", "/myroute", [ '_token' => csrf_token(), 'param' => $param ]); Previously in

lubart's avatar
lubart's avatar bobbybouwm...8yrs agoLaravel
6
1
Last reply by bobbybouwmann 8yrs ago
hsntngr's avatar

How to change app domain into to the test?

I have used app domain on my laravel projects till today, but today mozilla starts open app domains with `https.. So I edited my laravel.app.conf file and changed Servername as laravel.test then restart my apache2 sudo service apache2 restart But this time local website doesn't open, it says server not found.. Did I something wrong ? Or am I need to do something else ? Edit: Al

hsntngr's avatar
hsntngr's avatar hsntngr8yrs agoLaravel
1
1
Last reply by hsntngr 8yrs ago
harriesbmariano's avatar

Laravel Free Test Server

Good day everyone, anyone knows a free hosting site or free sandbox where I can upload my Laravel Project together with its Database? Thank you.

harriesbmariano's avatar
harriesbmariano's avatar impbob8yrs agoLaravel
6
1
Last reply by impbob 8yrs ago
johnnw's avatar

OAuth is not working - ERR_TOO_MANY_REDIRECTS - Is not possible to test oauth login in localhost?

Im using Valet, when accessing "http://proj.test/auth/facebook" we are redirected to "http://proj.test/auth/facebook?code=B...". But it appears an error: Page is not working, proj.test redirect too many times. ERR_TOO_MANY_REDIRECTS. Do you know how to fix the error? Routes: Auth::routes(); Route::get('/home', 'HomeController@index')->name('home'); Rout

johnnw's avatar
johnnw's avatar bashy8yrs agoGeneral
1
1
Last reply by bashy 8yrs ago
Breki's avatar

Test against value in array/JSON

I've got a database table called scrapeobjects which I use as temporary storage for a number of scraper and parser jobs. The structure is basically an id, a category text field, a type text field and a data JSON field (plus the created/updated_at fields, of course). Reading and writing to this from Eloquent has never been a problem and I've been able to use the flexibility of t

Breki's avatar
Breki's avatar morteza8yrs agoEloquent
1
1
Last reply by morteza 8yrs ago
founders's avatar

"Use of undefined constant LARAVEL_START" when running a Test

I'm starting to learn Tests now, this simple method bellow is returning error 500 on my homepage, even though I can see it just fine in the browser: public function testExample() { $response = $this->get('/'); $response->assertStatus(200); } The error is that the constant LARAVEL_START which I use to show processing time of page isn't defined in the moment of tes

founders's avatar
founders's avatar a-dev-code...11mos agoLaravel
6
1
Last reply by a-dev-coder-f 11mos ago
phpMick's avatar

How to test soft deletes?

Hi, How are we doing this? Like this?: https://stackoverflow.com/questions/33117746/laravel-unit-testing-how-to-seeindatabase-soft-deleted-row

phpMick's avatar
phpMick's avatar phpMick8yrs agoTesting
4
2
Last reply by phpMick 8yrs ago
CarlWilson's avatar

Advice for Shared Test Setup

Current Server Setup MacOS Server 10.10.5 Apache 2.4.16 mySQL PHP 5.4 (yes I know...) git 2.4.9 Apache is set up with dynamic routing similar to Valet but uses an externally accessible domain so we can share with clients during development. We then mount a folder (effectively the equivalent of a www folder) from the server using AFP and can then create/edit/maintain sites built

CarlWilson's avatar
CarlWilson's avatar CarlWilson8yrs agoServers
1
1
Last reply by CarlWilson 8yrs ago
boptom's avatar

How to test Job Chaining in Laravel 5.5?

I have applied Job Chaining to an event in Laravel 5.5. I can check if the first job in the chain is being dispatched via: Queue::assertPushedOn(FirstJob::class) Is there a way to check that the rest of the jobs in the chain will be dispatched too?

boptom's avatar
boptom's avatar m1654377yrs agoTesting
8
1
Last reply by m165437 7yrs ago
chillcaw's avatar

How to add headers to test?

I'm using Lumen, but there is no information in the Lumen documentation on how to do this. So I followed the Laravel docs: public function testUpdateMethodSuccess() { $response = $this->withHeaders([ 'HTTP_Authorization', $this->token ])->json('POST', 'users/3', ['name' => 'Sally']); $response->assertResponseStatus(422); } Whet

chillcaw's avatar
chillcaw's avatar Borisu8yrs agoTesting
3
1
Last reply by Borisu 8yrs ago
nanadjei2's avatar

Phpunit error 'No test executed!'

Am using laravel 5.5 and anytime I run phpunit I get this error No tests executed. Can anyone help me. c:\xampp\htdocs\L5.5 (master) λ phpunit PHPUnit 3.7.21 by Sebastian Bergmann. Configuration read from C:\xampp\htdocs\L5.5\phpunit.xml Time: 42 ms, Memory: 4.00MB No tests executed!

nanadjei2's avatar
nanadjei2's avatar nanadjei28yrs agoLaravel
2
1
Last reply by nanadjei2 8yrs ago
ixudra's avatar

How to test my package?

I maintain several packages that are available for download via composer. To my shame, most of these do not have tests, despite me using them extensively in my day to day activities. Reason is simple: I don't know how to make them work properly. For example: my most used package is ixudra/curl, a package for easily sending cURL requests through a fluent query builder. Ideally,

ixudra's avatar
ixudra's avatar ixudra8yrs agoTesting
4
3
Last reply by ixudra 8yrs ago
thc1967's avatar

Kind of a gross functional test. How to improve it, maybe?

GIVEN that we have a Character with a Type that has a Might pool value and a Descriptor that has a Might bonus value WHEN we run that character through the calculation rules for rendering THEN the Character's Might will be calculated accurately public function it_calculates_might_accurately() { $this->signIn(); $stat = Stat::findOrFail(Stat::MIGHT);

thc1967's avatar
thc1967's avatar thc19678yrs agoCode Review
0
1
ionelfona's avatar

Make the DatabaseMigrations trait migrate the test database

So the problem I'm facing is that after the tests are run, my local development database is rolled back instead of the testing one that is referenced in the .env.dusk.local file. Is this indeed an issue or I'm missing something? Any way I can fix this? Maybe overwrite the trait migration so that it does migrate --env=dusk.local, any ideas?

ionelfona's avatar
ionelfona's avatar ionelfona8yrs agoTesting
0
1
phpMick's avatar

Test that db table has some rows?

Is there a good way to do this? At the moment I am doing: $this->seeInDatabase('things',['id' => 1]); Mick

phpMick's avatar
phpMick's avatar phpMick8yrs agoTesting
2
1
Last reply by phpMick 8yrs ago
Marins's avatar

Test Mail without server?

Hello, can I test/mock Mail locally? with no mail server Thank you

Marins's avatar
Marins's avatar ModestasV8yrs agoLaravel
2
1
Last reply by ModestasV 8yrs ago
gocanto's avatar

How do you test query to Json columns using sqlite?

Hey folks, I came across an issue testing my queries using SQLite. I need to perform query similar to Product::whereRaw('features->"$.color"', 'red')->first(); This trows sintax error, but works with MySQL Also, I tried the laravel docs way, like so: Product::where('features->color', 'red')->first() but I get null as the result but works with MySQL Th

gocanto's avatar
gocanto's avatar bobbybouwm...8yrs agoLaravel
2
3
Last reply by bobbybouwmann 8yrs ago
Magelfik's avatar

Should I test redirections ?

Hi there, I'm a long time lurker on this forum and I thought I would ask my first question since I usually read good and specific answers here. I'm still trying to get the hang of some Laravel's features, and I'm definetly not an expert :-) To situate : I have a controller (let's call it ServerController). This controller has the auth middleware applied to it, therefore any gue

Magelfik's avatar
Magelfik's avatar MikeHopley8yrs agoTesting
2
1
Last reply by MikeHopley 8yrs ago
dannys's avatar

Gulpfile Auto Test, TDD and phpspec

Hello, i am following Jeff step 6 course, Step 1 prime factors, i followed his steps, from php descirbe primefactors to run, but everytime i run i get 1 argument broken instead of passed even after i create the class. Also after i install gulp, with his gulpfile, i run gulp in cmd and nothing changes, i can't get the auto-test messages jeff gets. I also don't understand how he

dannys's avatar
dannys's avatar dannys8yrs agoGeneral
3
1
Last reply by dannys 8yrs ago
mg-freelancer's avatar

DatabaseMigrations is too slow for each test, how to fix ?

When I run phpunit testing it takes long time to complete process because of migrations and seed, so how to fix this problem ?

mg-freelancer's avatar
mg-freelancer's avatar robrogers38yrs agoTesting
4
1
Last reply by robrogers3 8yrs ago
mazinoukah's avatar

SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'stories' already exist for sqlite in memory test phpunit

I am using sqlite for my phpunit testing (in memory), it was all working well untill recently i started receiving this error "SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'stories' already exist"

mazinoukah's avatar
mazinoukah's avatar aurawindsu...9yrs agoTesting
1
1
Last reply by aurawindsurfing 9yrs ago
lukecurtis's avatar

Provision Server and test on subdomain on different IP

Hey All, I've searched Google but I can't really find a succinct answer to my question so I'm hoping you guys can help. Basically, I've haven't gone live with a Laravel project yet and that requirements from the client add even more complication that I need some advise on. We have a domain 'example.com' that has a Wordpress installation on it and I would like to host a Laravel

lukecurtis's avatar
lukecurtis's avatar neilherber...9yrs agoServers
1
1
Last reply by neilherbertuk 9yrs ago
zachleigh's avatar

Test datatables file download?

Anybody know how to do acceptance tests for datatables CSV file downloads? We're using phpunit/Codeception and can't find a way to get the file to download. Any help?

zachleigh's avatar
zachleigh's avatar zachleigh9yrs agoTesting
0
1
ill-logical's avatar

Should I test for unauthenticated behavior?

Hi, I am new to testing. So far, I have been testing each of my API endpoints for both authenticated and unauthenticated users: public function testAuthenticatedUser() { Passport::actingAs($this->user); $response = $this ->get('/api/posts') ->assertStatus(200); //... (other assertions) } public function testUnauthenticatedUser() {

ill-logical's avatar
ill-logical's avatar ill-logica...9yrs agoTesting
3
1
Last reply by ill-logical 9yrs ago
eddyerburgh's avatar

avoriaz - a Vue test util library

I've made a library to make testing Vue components easier. Check it out. Hopefully you find it as useful as I have

eddyerburgh's avatar
eddyerburgh's avatar eddyerburg...9yrs agoTesting
0
1
ajmerainfo's avatar

Test Markdown Test

Do we have delete functionality for thread here?

ajmerainfo's avatar
ajmerainfo's avatar ajmerainfo9yrs 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.