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

daverydan's avatar

Test Failing on Project-Flyer

Not sure what's happening, but I am running Laravel 5.2. So, that could be a problem, but I am very uncertain as I have never written a test before so I wouldn't understand how to read the error. I mean, it obviously has something to do with the move method or something. Anyhoo... AddPhotoToFlyerTest.php <?php // namespace App; use App\AddPhotoToFlyer; use Symfony\Componen

daverydan's avatar
daverydan's avatar daverydan9yrs agoLaravel
0
1
wottavm's avatar

My phpunit relation test fails

Hello everyone, I am starting with testing and I am getting stuck at the relation part for my test. Here is my code : <?php use Illuminate\Foundation\Testing\WithoutMiddleware; use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseTransactions; class CreateVersionTest extends TestCase { use DatabaseTransactions; /**

wottavm's avatar
wottavm's avatar concept_co...9yrs agoTesting
6
1
Last reply by concept_core 9yrs ago
cactus's avatar

How to write a test case for Traits

I have a trait RandomTrait. I want to write a test case for this trait. How can I do that? I am creating a new class and then using the said trait in that class & writing the test cases for the new class. However, when I run the test case, I see the error PHP Fatal error: Class 'DB' not found in /var/www/crm/app/Traits/RandomTrait.php Code: RandomTrait.php <?php namesp

cactus's avatar
cactus's avatar cactus9yrs agoTesting
1
1
Last reply by cactus 9yrs ago
ovidiu_dtp's avatar

How to test random

I have to implement a feature that half the time has one behavior, and half the time, another behavior, and for that I need to use random. But how could I test to see if it is actually random? That in the long run, results are not biased? It is something like: if(somethingRandom50percentChance()) { doOneThing(); } else { doAnotherThing; } I am a bit confused on how to deal with

ovidiu_dtp's avatar
ovidiu_dtp's avatar ohffs9yrs agoTesting
4
1
Last reply by ohffs 9yrs ago
amite's avatar

PHPUnit separate connection to mysql test database Laravel 5.2 not working

I am trying to connect my Testcase integration tests to a separate database connection but its not happening. The test suite keeps connecting to the default database connection instead. In phpunit.xml I have set this variable: <env name="DB_CONNECTION" value="mysql_testing"/> And in my database.php I have this: 'mysql_testing' => [ 'dr

amite's avatar
amite's avatar supertrall9yrs agoTesting
2
1
Last reply by supertrall 9yrs ago
esdairi's avatar

Free webhosting plan to deploy and test my Laravel app

Hi, I am new to Laravel and I need a free web host to test and play with my app on a production environment.

esdairi's avatar
esdairi's avatar rduran9yrs agoServers
4
1
Last reply by rduran 9yrs ago
illia's avatar

How to fire event in integration test?

I'm trying fire even in my integration test but it does not triggering. I set up QUEUE_DRIVER=sync in my phpunit xml. Why event and listener is not working ? The workflow of my app is next: Create some entity. Send it to remote server (i use even and listener); Give back some id and write it to db. public function testCanGetCbdOfPlan() { $plan = factory(Plan::class)-&g

illia's avatar
illia's avatar bobbybouwm...9yrs agoTesting
3
1
Last reply by bobbybouwmann 9yrs ago
casenjo's avatar

Unit test fails saying JSON doesn't match, even though the contents do

I'm very confused about this unit test I'm trying to fix. The contents of the JSON are the same, but it seems that the returned keys are sorted in the actual result while in the expected result they are not. I've verified with Postman that the data is returned properly, and it coincides with how I set the expected results should be (not sorted). Only in the unit test itself doe

casenjo's avatar
casenjo's avatar casenjo9yrs agoTesting
0
1
leandromatos's avatar

How to test if relationship has successfully created?

In a test case, how to test if relationship has successfully created? Example: <?php use App\School; use App\Teacher; use Illuminate\Foundation\Testing\DatabaseTransactions; class TeacherTest extends TestCase { use DatabaseTransactions; /** @test */ public function a_teacher_can_be_created() { // Given // create a teacher $teacher =

leandromatos's avatar
leandromatos's avatar selmonal9yrs agoTesting
7
8
Last reply by selmonal 9yrs ago
Placid's avatar

Test Unauthorized Access using PHPUnit

I am trying to test unauthorized access in Laravel 5.2 using PHPUnit. AuthServiceProvider.php: $gate->define('foo', function ($user) { return $user->email == '[email protected]'; }); routes.php: Route::get('foo', 'PagesController@foo'); PagesController.php: public function foo() { $this->authorize('foo'); return &

Placid's avatar
Placid's avatar tomo_pongr...9yrs agoTesting
1
1
Last reply by tomo_pongrac 9yrs ago
Laura_E's avatar

Behat "I should see 'Laravel 5'" test fail homepage

In my new Laravel application (created by $ composer create-project laravel/laravel my_app), I type: $ php -S localhost:8888 -t public And in the browser (Safari or Chrome) on localhost:8888 I successfully see black text "Laravel 5" on the webpage. I have a hometest.feature file in features/ that looks like: Feature: In order to prove that Behat works as intended

Laura_E's avatar
Laura_E's avatar Xanthakita9yrs agoTesting
1
1
Last reply by Xanthakita 9yrs ago
ramonhollands's avatar

use App\Model in test dir trait

Hi, I created a Trait in the test directory which is used by multiple tests. In the Trait I try to import the User model: use App\User; <?php trait TestPrepareQuestionnaire { use App\User; ... public function create_user_team_and_members() { .... } } This gives the error: Tests\TestPrepareQuestionnaire cannot use App\User - it is not a trait

ramonhollands's avatar
ramonhollands's avatar tomo_pongr...9yrs agoLaravel
1
1
Last reply by tomo_pongrac 9yrs ago
Dusted's avatar

Test not working together

Hi, the second test below is only successful when it run separately. Why is this? <?php use Laracasts\TestDummy\Factory; use Laracasts\TestDummy\DbTestCase; class OrganisationObserverTest extends DbTestCase { /** @test */ public function it_deactivates_custom_questions_on_organisation_deactivation() { $organisation = Factory::create('App\Models\Organi

Dusted's avatar
Dusted's avatar Dusted9yrs agoTesting
10
1
Last reply by Dusted 9yrs ago
deathmetalgore's avatar

How to simulate Content-Type header in a test within a Laravel 5 package?

I'm currently building a Laravel package that injects a new method in Illuminate\Http\Request. The method I'm injecting has been completed and is expected to work nicely, but I also want to test it before releasing it. My test requires me to change the request's Content-Type header, in order for me to see if the test is passing or no. So I have done the following to simulate th

deathmetalgore's avatar
deathmetalgore's avatar deathmetal...9yrs agoLaravel
0
1
derekmd's avatar

withoutEvents() for only integration test setup

I have a scenario where Event::fire() is called in both created and deleted events of a model. During the API's PUT update endpoint integration test I want to know: that event isn't fired when the update action is successful. (i.e., "InvalidArgumentException: No connector for []" wouldn't being thrown during the integration test scenario.) However factory()->crea

derekmd's avatar
derekmd's avatar derekmd9yrs agoTesting
3
1
Last reply by derekmd 9yrs ago
ashleywnj's avatar

Test Rate Limit (throttling) - catch 22

Thanks in advance for any insights or hints on how to develop a test for throttling an api using the 5.2 middleware option. I am using Laravel Spark - my controller is setup to use the auth middleware - I had a few tests setup for authentication, all passed. Using httpie in exec() to test the rate limit. To the middleware I added "throttle" public function __constr

ashleywnj's avatar
ashleywnj's avatar ashleywnj2yrs agoTesting
5
1
Last reply by ashleywnj 2yrs ago
haegemon's avatar

Why laravel5 use Crawler test by default ?

Why laravel5 use Crawler test by default ? Why not use codeception which has enough good working model? I haven't any problem with Crawler but I try understand this decision.

haegemon's avatar
haegemon's avatar haegemon9yrs agoTesting
2
1
Last reply by haegemon 9yrs ago
welcomattic's avatar

Test a select2 field with PHPUnit

I'm trying to test a form with a select2 field with this code : $this->actingAs($this->loggedUser) ->visit('admin/conference/create') ->submitForm('Add', [ 'name' => 'Forum PHP 2016', 'location' => 'Paris', 'start_at' => '2016-10-27 09:00:00', 'end_at' => '2016-10-28

welcomattic's avatar
welcomattic's avatar welcomatti...10yrs agoTesting
6
1
Last reply by welcomattic 10yrs ago
alariva's avatar

How do you test your commands? (phpunit)

Hi guys, I'm trying to write test cases for Commands in PHPUnit, without much success. At this point I've tried many things, being probably this post the closest approach I found for my purpose. Still, I'm struggling a lot to get this working. Follows an example output for you: alariva@trinsic ~/timegrid.io/app $ phpunit --filter=SendBusinessReportTest PHP Warning: The use sta

alariva's avatar
alariva's avatar ifpingram9yrs agoTesting
8
9
Last reply by ifpingram 9yrs ago
Robert-Jan's avatar

Test with PSR ServerRequestInterface has empty body

I have a TestCase with the following test: public function test_password_grant_token_request() { $this->json('POST', '/authentication/token', [ 'grant_type' => 'password', 'client_id' => 'test', 'client_secret' => 'test', 'username' => '[email protected]', 'password' => 'T

Robert-Jan's avatar
Robert-Jan's avatar Robert-Jan10yrs agoTesting
1
1
Last reply by Robert-Jan 10yrs ago
dschu's avatar

Mocking a repository and running and selenium test

The title says it all.. I need to mock a repository and then run a selenium test, because I'm interacting with a third party API. Is this possible? Any advice for me how to achieve my goal? The test itself does nothing special at the moment. Just opens the page and waits so I can check manually, if the mocked data was submitted. ReportsTest.php <?php class ReportsTest exten

dschu's avatar
dschu's avatar shez19839yrs agoTesting
1
1
Last reply by shez1983 9yrs ago
kubaszymanowski's avatar

Test Laravel package integration

Hi What I want to do is test my Laravel 5 package. Specifically how it integrates with a actual Laravel app(I already have unit tests). My idea is: create a tests/Integration directory in my package exclude tests/Integration in phpunit.xml in tests/Integration install a Laravel project, create a simple app and write tests there do not require my package as a Laravel app

kubaszymanowski's avatar
kubaszymanowski's avatar ifpingram10yrs agoTesting
3
1
Last reply by ifpingram 10yrs ago
EventFellows's avatar

Limit access to Test and DEV environments without .htaccess

I waneted to limit access to my test and development servers / environments so only the production system would be freely accessible to users. As I had to learn: .env variables are not accessible on the server itself to be picked up by the .htaccess file (for apache server) so the basic authentication can only be handled there with weird work-arounds. I looked for a way to solv

EventFellows's avatar
EventFellows's avatar EventFello...10yrs agoServers
1
1
Last reply by EventFellows 10yrs ago
vishal.varshney's avatar

How to test form containing php captcha validation in laravel

hi guys, while writing php unit test case in laravel, how we send php captcha value. i am using php captcha public function testSignupStoreFunction() { $data['first_name'] = "vsdghvfas"; $data['last_name'] = "asdas"; $data['email_id'] = "[email protected]"; $data['password'] = "asd1#"; $data['password

vishal.varshney's avatar
vishal.varshney's avatar selmonal9yrs agoTesting
1
1
Last reply by selmonal 9yrs ago
anhnd's avatar

Should we write unit test for laravel project ?

I already have Xdebug to fix bugs. So should i write unit test for my project ?

anhnd's avatar
anhnd's avatar anhnd10yrs agoTesting
6
1
Last reply by anhnd 10yrs ago
ohffs's avatar

Code fails in test - looks like model binding?

I have a basic bit of code that lets you pick from a drop-down which then gets used as a foreign key on the model. I've got a test which should pass, but I keep getting an error : 1) CourseTest::test_can_edit_a_valid_course Illuminate\Database\QueryException: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails

ohffs's avatar
ohffs's avatar SaeedPrez10yrs agoTesting
4
1
Last reply by SaeedPrez 10yrs ago
ChristopherSFSD's avatar

Need help with first mocking / stubbing test

Hello I'm trying to get my first mocking or stubbing test working with Prophecy. I've never used mocks and stubs or Mockery. I've done a fair number of unit tests where dependencies didn't really come into play, etc. If I can get this one test working, I think it'll help me go a long with with further testing my code. Any help would be greatly appreciated! First the error ... M

ChristopherSFSD's avatar
ChristopherSFSD's avatar Christophe...10yrs agoTesting
3
1
Last reply by ChristopherRaymond 10yrs ago
stephan-v's avatar

How to unit test modals?

I just started unit testing with php and so far everything is going alright. But now I am running into problems because I have bootstrap modals set up to display when you click a register link in the navigation. Since phpunit runs it can't possible interact with these modals since they are launched with javascript upon click of a register link. Preferable I would like to test i

stephan-v's avatar
stephan-v's avatar pmall10yrs agoTesting
1
1
Last reply by pmall 10yrs ago
philbenoit's avatar

How to test ajax file uploads

I am trying to test my file upload code. The Uploaded file object is not getting sent through to my controller, hoping another pair of eyes might spot the error. Here is my code . public function testBulkFileCanBeUploaded() { $user = User::find(1); $root = realpath($_SERVER["DOCUMENT_ROOT"]); $path = "$root/tests/files/loca

philbenoit's avatar
philbenoit's avatar philbenoit10yrs agoTesting
1
1
Last reply by philbenoit 10yrs ago
jaycito's avatar

Setting cookies before test

I know neither setcookie nor sessions in general are very test-friendly, I need to test a specific behaviour based on the presence of a cookie, how do I set a cookie before running the test ? For the moment it fails, it behaves likes nothing was set. Is there a way using ->visit() that I'm not aware of or a way with ->call() where I can set session variables ? $this->a

jaycito's avatar
jaycito's avatar jaycito10yrs agoTesting
4
1
Last reply by jaycito 10yrs ago
Nclow's avatar

Post bodies ignored when making multiple post calls in test

I've been running into problems writing my phpunit tests in lumen5.2 with laravel components. If I make multiple http calls to my API within a single test, the body I supply for subsequent calls is ignored in favor of the first body supplied to any http call in the test. The problem occurs using any of the available methods in MakesHttpRequests, such as post() or put() or call(

Nclow's avatar
Nclow's avatar Nclow9yrs agoTesting
1
1
Last reply by Nclow 9yrs ago
jeigh's avatar

Codeception test error

I am trying to text using Codeception but getting the following error: There was 1 failure: --------- 1) Failed to check that login works in EnterLoginCept (tests\acceptance\\EnterLoginCept.php) Step I see "Welcome" Fail Failed asserting that /login --> Depression App a:link { text-decoration: none; color: #000000; pad

jeigh's avatar
jeigh's avatar jeigh10yrs agoTesting
0
1
jerlandsson's avatar

file exists Condition fails in test, works in manual test

Hello fellow coders. I'm having a nasty problem where my tests fail when I try to load a "module". But when I try the API manually it works just fine. I've spend at least a couple of hours on this now so I thought that I should ask if someone else could be so nice and "throw an eye" (as we say in Sweden) on this to help me get pass this. I'm trying to load a

jerlandsson's avatar
jerlandsson's avatar jerlandsso...10yrs agoTesting
0
1
coder81's avatar

I should test even the failure cases?

Suppose I have a rule that not permit to a moderator to delete a user (but an admin can). I should test even this case? I should test even the case of a user who type a bad password or a bad email when sign in? In general, actually I test only success use cases, do you test even the failure (or not permitted) use cases?

coder81's avatar
coder81's avatar ohffs10yrs agoTesting
4
1
Last reply by ohffs 10yrs ago
kodemania's avatar

Risky Test PhpUnit

Hello guys Could you help me with risky test. How to write code which passes completely and avoid risky tests. Regards

kodemania's avatar
kodemania's avatar kodemania10yrs agoGeneral
4
2
Last reply by kodemania 10yrs ago
Desu's avatar

What do you actually test?

It can be obvious but for me it is not. I watched series about testing and even read a book, but I don't get it. Lets pretend I am building project on my own. How can I specify acceptance tests etc.? I don't know how to start and I feel a little bit overwhelmed. What to test? Should I test CRUD actions? Its pretty obvious that I should test complicated calculations etc. but I d

Desu's avatar
Desu's avatar MikeHopley10yrs agoTesting
2
1
Last reply by MikeHopley 10yrs ago
EliasSoares's avatar

TDD - How to test Controller Validation?

Hi, We're developing a new system trying to use TDD everywhere, and I'm stuck at Validation tests. I use the Request classes to validate my API Requests. The problem is how to test it? I've seen two options: Manually test all possible combinations for all fields and make many assertions for it. Just check if my Request rules() method have my expected validations (relying on La

EliasSoares's avatar
EliasSoares's avatar ifpingram9yrs agoTesting
4
1
Last reply by ifpingram 9yrs ago
kodemania's avatar

How to completely pass PhpUnit Risky test

Hello fellows I hope you guys are doing well, I was facing a bit difficultly in passing phpunit tests. Let me explain my code SignupController class SignupController extends Controller { /** * @var UserRepositoryInterface */ private $repository; /** * @var RedirectServiceInterface */ private $redirectService; /** * @param UserRepo

kodemania's avatar
kodemania's avatar kodemania10yrs agoGeneral
0
1
ayekoto's avatar

seeInPage() error with phpunit test

at last, am able to make a post.... happy :), now here is my challenge: here is my controller code /** * process the authentication * * @param Request $request * @return */ public function postLogin(LoginRequest $request) { $this->dispatchFrom(AuthenticateCommand::class, $request); return redirect()->route('

ayekoto's avatar
ayekoto's avatar ayekoto10yrs agoTesting
2
1
Last reply by ayekoto 10yrs ago
vitr's avatar

Spark Test Suites

Just played a bit with Spark today, amazing app, hands down, love it! Just one thing bothers me, if I start modifying it, how I can be sure that I don't break anything? I understand, it's only beta, but will be there some test suits for both back-end and front-end code? Laravel kernel project has lots of tests, we must have some tests for Spark as well.

vitr's avatar
vitr's avatar vitr10yrs agoSpark
3
1
Last reply by vitr 10yrs ago
bencarter78@hotmail.com's avatar

How to test submitting a form with multiple checkboxes

Hi there When I run my test I get the following error... InvalidArgumentException: Input "grade_id[]" cannot take "11" as a value (possible values: 1). I have the following test... function it_displays_submitted_summaries_with_given_criteria() { $grades = $this->grades(3); $processes = $this->processes(3); $sectors = $this-

bencarter78@hotmail.com's avatar
bencarter78@hotmail.com's avatar jekinney10yrs agoTesting
1
1
Last reply by jekinney 10yrs ago
gojulabs's avatar

Automated get/route test generator

Anyone know of a composer package that can auto-create a series of simple get/route tests for PHPUnit to quickly flesh out tests? Obviously this is woefully incomplete, but would make a nice way to populate a test harness for a new project.

gojulabs's avatar
gojulabs's avatar ifpingram10yrs agoTesting
5
1
Last reply by ifpingram 10yrs ago
bencarter78@hotmail.com's avatar

Running Selenium against a test database

Hi there I'm running Laravel 5.2 and testing with PHPUnit and Selenium. I tried to install the laracasts/integrated package but it seems that 5.2 isn't compatible so I ended up running phpunit-selenium. I've set up my first test and when I've come to log in to my application it says it can't find the user which I have created in the test (and saved to the test database). It see

bencarter78@hotmail.com's avatar
bencarter78@hotmail.com's avatar MikeHopley10yrs agoTesting
5
1
Last reply by MikeHopley 10yrs ago
monsterdream's avatar

How to test this stripe webHook ? And why it't not working

Hi, In my test i have simply method: $req = $this->call('POST', '/stripe/webhook', ['name' => 'Something']); function is reaching but somehow array is not attached: In: WebhookController.php public function handleWebhook(Request $request) { // dd($payload = json_decode($request->getContent(), true)); => here it throws null dd($request->getC

monsterdream's avatar
monsterdream's avatar monsterdre...10yrs agoGeneral
0
1
rohan0793's avatar

How to unit test abstract classes the right way?

So I am trying to write unit tests for my repository package. It is a small package which takes out the functionality of the repositories and I have a BaseRepository.php abstract class which basically performs all the eloquent related stuff. All the eloquent repositories extend this class. This is what it looks like: <?php namespace Uppdragshuset\AO\Repository\Eloquent; us

rohan0793's avatar
rohan0793's avatar Darival10yrs agoTesting
1
1
Last reply by Darival 10yrs ago
EmilMoe's avatar

Test REST calls

Which tools can you recommend to test REST calls? They are behind a login and require a token.

EmilMoe's avatar
EmilMoe's avatar EmilMoe10yrs agoGeneral
2
1
Last reply by EmilMoe 10yrs ago
tomriddle1403's avatar

Test Upload Image

Hello everyone, I am trying to test the function uploadImage of my controller. I run into this error when trying to Mockery an Uploadedfile. Exception: Serialization of 'Mockery_0_Symfony_Component_HttpFoundation_File_UploadedFile' is not allowed Below is my test case.

tomriddle1403's avatar
tomriddle1403's avatar tomriddle1...10yrs agoTesting
0
1
Darival's avatar

Test Api 404 on multiple requests

Hi, I'm trying to test all the routes on my api but only the first request gets 200, all following requests get 404, but when I run any test individually (phpunit --filter test_something) they work. <?php class ProgramTest extends TestCase { /** @test */ public function it_returns_index() { $this->get('api/v1/test') ->assertReturnOk(['lim

Darival's avatar
Darival's avatar rasmuscnie...4yrs agoTesting
3
1
Last reply by rasmuscnielsen 4yrs ago
vunh's avatar

How to test function store with PhpSpec

I have just studied phpSpec, I have a function store with validate and saving on database. But I don't know how to test it. Can you help to write test it with PhpSpec? Thanks alot Here is my function: public function store(Request $request) { $validator = Validator::make($request->all(), [ 'name' => 'required', 'alias' => '

vunh's avatar
vunh's avatar vunh10yrs agoTesting
0
1
meto1080's avatar

Laravel testing cannot recognise route when call the same test function at the second time

Hi Guys, I am newbee of Laravel testing. I just got an route not define error when I call the same test function at the second time. Story: I put the login test into the TestCase.php file for reusability in all test files. When it is called by the first test case, everything is fine. I.E. loginSuccess, loginFailed functions below. But when the second test case pickup the same

meto1080's avatar
meto1080's avatar meto108010yrs agoTesting
8
1
Last reply by meto1080 10yrs 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.