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

hiraq's avatar

Lumen Unit Test - Strange Behaviors

Actually, i've report this issue at lumen-framework github , but there are no answers at all.. I'm always do unit test with laravel, and now when i try lumen micro framework, i cannot test all unit tests together, and i see there is like a cache between tests. Unit test only work for first test, and the others will fail. Anyone has same experience with me? Or i'm just alone he

hiraq's avatar
hiraq's avatar hiraq11yrs agoLumen
6
1
Last reply by hiraq 11yrs ago
DMA's avatar

PHPSpec shouldBeCalled within the method under test

First, I may be going about this the wrong way entirely but here goes.. Here's the test I'm trying to write: Given I have productA, called 'Jeans' with a slug 'jeans' And I have productB, which is also called 'Jeans' When I generate a slug for productB Then then an exception is thrown In my class, I'm using a repository to perform the check if the slug already exists, but I do

DMA's avatar
DMA's avatar DMA11yrs agoTesting
0
1
Halz's avatar

Laravel5 - How to test middleware redirect ?

Hello everybody, I have created a simple localization & routing system to allow my application to work with language subdomains. Here's a brief description: a class Localize is in charge of detecting the locale ( from the url, the cookies, the browser settings or the application settings) a class Router is in charge of translating routes a middleware Localization is in char

Halz's avatar
Halz's avatar lazyboywu11yrs agoLaravel
1
1
Last reply by lazyboywu 11yrs ago
SteveAzz's avatar

Test doesn't work but in browser it work. Laravel 5 & Laracasts\Integrated

I have the following test. public function it_updates_post() { $post = TestDummy::create('Blog\Post'); $newPost = ['title' => 'Some title', 'body' => 'The body']; $this->visit('posts/' . $post->id . '/edit') ->seePageIs('posts/' . $post->id . '/edit') ->see('Edit Post') ->submitForm('U

SteveAzz's avatar
SteveAzz's avatar SteveAzz9yrs agoTesting
11
1
Last reply by SteveAzz 9yrs ago
Rodrigo Balest's avatar

How to test custom validation rules in Laravel 5?

Hi! I also posted this question at StackOverflow. I created a custom validation rule in Laravel, extending it in the register() method of a service provider, and I'd like to test it, but don't know how. I took a look at Laravel framework's validation tests, but I couldn't understand the purpose of the getTranslator() and getRealTranslator() methods. Could someone give me a hint

Rodrigo Balest's avatar
Rodrigo Balest's avatar KhantilPat...9yrs agoTesting
3
1
Last reply by KhantilPatel 9yrs ago
SachinAgarwal's avatar

[CodeCeption] Functional Test Error.

Here is my Complete Functional test: <?php $I = new FunctionalTester($scenario); $I->am('valid CN Admin user'); $I->wantTo('Login at CN Admin login page'); $I->haveAnCNAdminAccount([ 'username' => 'sachin', 'email' => '[email protected]', 'password' => 'sachin' ]); $I->amOnPage('/cn/admin/login'); $I->see('LogIn!'); $I->fillField

SachinAgarwal's avatar
SachinAgarwal's avatar SachinAgar...11yrs agoTesting
0
1
bslinger's avatar

Tests wrapped in transactions make it hard to test actual transactional behaviour

I'm just getting my head around doing some integration testing using Codeception and Laravel 5, taking inspiration from the 'Integration Testing Repositories' Laracast. My issue is that I am attempting to test a function which creates and persists an object to the database (an Order), but as the Order has multiple related objects (Address, Items), the whole thing is done in a t

bslinger's avatar
bslinger's avatar bslinger11yrs agoTesting
0
1
jackpopp's avatar

Migrating a test database

HI! I have a test database that I want to use with codeception and I need to run the migrations for it. I've created a .env.testing file and set up the configuration and then tried running: php artisan migrate --env=testing But it still seems to use the normal .env configuration instead of my test config, any ideas where I might be going wrong? Thanks!

jackpopp's avatar
jackpopp's avatar jackpopp11yrs agoGeneral
2
1
Last reply by jackpopp 11yrs ago
almo's avatar

Struggling with Integrated to test imbricated arrays

Hello, I can't get seeJsonContains($array) working properly with imbricated jsons. I'm returning from my controller this array : $array = [ 'user' => [ 'email' => $email ] ] So it's converted by the response()->json($array) to : { "user": { "email": "[email protected]" } } But whenever I call : $this->seeJ

almo's avatar
almo's avatar almo11yrs agoTesting
0
1
jonnybarnes's avatar

I can’t test a POST request in lumen

I have a route that can receive POST requests. Currently, if the parameter foo is not set the app returns a 400 error, and if the parameter foo is set to an unknown value a 501 error is returned. This works when I manually hit the route with curl. I can’t get this to work in my unit test, setting an unknown value for “foo” still results in a 400 response. This is how I‘m doing

jonnybarnes's avatar
jonnybarnes's avatar jonnybarne...11yrs agoLumen
4
1
Last reply by jonnybarnes 11yrs ago
isaackearl's avatar

How to test a function with Mockery.. and stub certain parts?

I've been struggling with this for awhile now and hoping someone can enlighten me. Basically I have a PayloadService that help me manage JWT auth stuff I'm doing. It provides some simple functions that all me to do things like get the userId from the payload or other claims. I also have a toUser function that returns the user based off the ids in the claims... but I can't fig

isaackearl's avatar
isaackearl's avatar isaackearl11yrs agoTesting
1
1
Last reply by isaackearl 11yrs ago
James's avatar

How to test this method

I have a repository class which has the eloquent model injected into its constructor. In my getById() method, I use a protected mapEntity() method which maps the returned eloquent model to my post entity. The method looks like: public function getById($postId) { $eloquentPost = $this->posts->where('id', $postId) ->with(['tags

James's avatar
James's avatar blackbird11yrs agoTesting
1
1
Last reply by blackbird 11yrs ago
EliasSoares's avatar

L5 PHPUnit simple test taking 5.49 seconds. It's normal?

Hi, little question. I'm starting now with PHPUnit, and my simple (Create a model and test it values) is taking 5.5 seconds to run in Homestead + Win 7 Machine. Is this time normal?

EliasSoares's avatar
EliasSoares's avatar EliasSoare...11yrs agoGeneral
1
1
Last reply by EliasSoares 11yrs ago
craigwebster's avatar

Multiple Test Scenarios with Integrated/Selenium

Hi Guys, I'm having trouble running more than one Selenium test at a time using the Integrated/Selenium extension. I can run one test fine, and it's really useful, but when I add a second test scenario I get an config/app.php error in the console telling me Mycrypt constant is not defined. This only occurs when the second test is triggered (Mycyrpt is working fine, by the way).

craigwebster's avatar
craigwebster's avatar craigwebst...11yrs agoTesting
0
1
ATOM-Group's avatar

How do you use PHPUnit to test Request objects?

I want to be able to test that given some input array, I get the expected MessageBag results out of a Request object, but there doesn't appear to be an easy way to do this. Is the only way do something like this a full integration test and actually inspecting the $errors object of the view that gets returned?

ATOM-Group's avatar
ATOM-Group's avatar pmall11yrs agoTesting
1
1
Last reply by pmall 11yrs ago
Fed03's avatar

Using PHPSpec to test repositories in L5

Hi all, I've a bunch of eloquent repositories I want to test. With Laravel4 and PHPUnit I used to have a database config file for the testing environment with an sqlite in memory database. Then with the aid of testdummy I was able to test my repositories. Now I switched to PHPSpec and L5 and I don't have any idea on how to reproduce that workflow, so I'm here to ask for your he

Fed03's avatar
Fed03's avatar JeffreyWay11yrs agoTesting
3
1
Last reply by JeffreyWay 11yrs ago
allantatter's avatar

phpspec: How to test if native function was called?

How to test if file_get_content() was called with right arguments if we had this example class: <?php namespace Some\Dir; class Example { public function method1($path) { return $this->method2($path); } private function method2($path) { return file_get_contents($path); } } My actual code is a lot more complicated but this is th

allantatter's avatar
allantatter's avatar allantatte...11yrs agoTesting
4
1
Last reply by allantatter 11yrs ago
craigwebster's avatar

Using Integrated to test a stripe gateway

Has anybody tried testing a stripe implementation by filling in a form with test creit card information? Is it possible? Do I need to use selenium?

craigwebster's avatar
craigwebster's avatar MikeHopley10yrs agoTesting
6
1
Last reply by MikeHopley 10yrs ago
narwen's avatar

Where to keep stripe test api key in L5?

I have been following the laracast tutorial on using Cashier. They store their stripe test key in start.php but Laravel 5 doesnot have start.php. SO, where should I put my stripe test key in laravel 5

narwen's avatar
narwen's avatar narwen11yrs agoGeneral
2
1
Last reply by narwen 11yrs ago
SteveAzz's avatar

How should I write this test

So I have two database tables with a many to many relationship. One of them is Item and the other one it Tier. I have a form which takes the name of the new Item and the Tier id or if he enters a string it will create the new tier and save it to the database. For example the user enters "Photo" as the item name, and enters "Gold" as a new tier which doesn't

SteveAzz's avatar
SteveAzz's avatar bastiaan8911yrs agoTesting
5
1
Last reply by bastiaan89 11yrs ago
gribas's avatar

Unit Test Models with Sqlite

Hi folks, I am newbie php and Laravel developer. I am trying to do unit testing of my models but I'm not sure about what configuration I need for Laravel 5. I followed this guide but is not working for me: (https://laracasts.com/lessons/test-databases-in-memory) This is my test (at the moment is not doing anything): class UserModelTest extends TestCase { /** * A basic

gribas's avatar
gribas's avatar gribas11yrs agoTesting
0
1
nolros's avatar

Easier method to test for Eloquent Collection or instance?

In the case where you are using Eloquent's with relationships ->with() is there an easier way to test if what is returned is an instance of the relationship or a collection. If there is only one record Eloquent will return that as an instance of the model, but if there are more then one you end up with a Collection which makes sense, however, if you a re using dynamic prop

nolros's avatar
nolros's avatar SachinAgar...11yrs agoEloquent
1
1
Last reply by SachinAgarwal 11yrs ago
Bondacom's avatar

[PHPUnit] No exceptions shown when test fails

PHPUnit is working fine, tests fail when they have to, but I can't see the exception that was thrown when that happens. My tests/RoutingTest class has class RoutingTest extends TestCase { public function test_it_shows_dashboard() { $this->call('GET', '/'); $this->assertResponseOk(); } } But, since my routes file is empty, it should f

Bondacom's avatar
Bondacom's avatar hamzapurra10yrs agoTesting
1
1
Last reply by hamzapurra 10yrs ago
simonsmadsen's avatar

Test Notification

In the Bowling Game code kate video. https://laracasts.com/series/code-katas-in-php/episodes/3 Is Jeffrey Way using a tool to running hi's test, and then give a notification . What is the name of this tool?

simonsmadsen's avatar
simonsmadsen's avatar simonsmads...11yrs agoGeneral
2
6
Last reply by simonsmadsen 11yrs ago
mpallante's avatar

Unexpected passing Behat functional test

Hello, I'm just doing functional tests for the first time using L5, Homestead, Behat3 and the Behat Laravel 5 Extension. My test is very simple and it is stored in features/example.feature: Feature: Sample In order to learn Behat As a programmer I need a simple url testing Scenario: Registration Given I am not logged in When I go to the regist

mpallante's avatar
mpallante's avatar mpallante11yrs agoTesting
0
1
Moe's avatar

Mandrill will not work in test mode

When i send an email with a normal API key there is no problem, but when i add the test key en go to the test mode of Mandrill i do not find any email in my outbound box. What can be the problem? Are there some specific action that i have to do for working whit TEST mode?

Moe's avatar
Moe's avatar bashy11yrs agoGeneral
6
1
Last reply by bashy 11yrs ago
bobbybouwmann's avatar

How to test custom FormBuilder

Hi guys, So I created a custom FormBuilder based on the FormBuilder from the Collective package: http://laravelcollective.com/docs/5.0/html The FormBuilder will only return html so I was thinking about a unit test. Then I can compare the output on correctness. So I have a function like this: <?php namespace App\Services\Html; class FormBuilder extends \Collective\Html\FormB

bobbybouwmann's avatar
bobbybouwmann's avatar blackbird11yrs agoTesting
5
1
Last reply by blackbird 11yrs ago
christophrumpel's avatar

New dump for every Codeception test?

Hey, I've been working with Codeception in my latest project and what I find strange is the DB module. So after every test CC restores my DB from the dump I provide. But that means I need to create a new dump every time I run my tests? (when I want to clear the data created) Wouldn't it be of more use if CC creates automatically a dump before running the test and then resets to

christophrumpel's avatar
christophrumpel's avatar Mike Hople...11yrs agoTesting
5
1
Last reply by Mike Hopley 11yrs ago
ThibaudDauce's avatar

Test a Blade template

Hi, I'm currently trying to test a Blade template but I don't know how to do that. I want to be sure that all the method calls on my object are corrects (no errors in Blade) and also that some information can be see in the HTML. What can I do? Thanks,

ThibaudDauce's avatar
ThibaudDauce's avatar RayRutjes11yrs agoTesting
1
3
Last reply by RayRutjes 11yrs ago
kfirba's avatar

How to test commands as the domain layer

Hello. I really like using Behat with ubiquitous language as I can then run the features against a DomainContext and a UserInterfaceContext. However, I find it quite hard to test my commands. If I'm not using a command and just for example a repository I would do something like this in my test step: protected $repo; // maybe there is a way to do it more elegantly? public funct

kfirba's avatar
kfirba's avatar kfirba11yrs agoGeneral
5
1
Last reply by kfirba 11yrs ago
daneel's avatar

Getting Request::path() in routes.php when using call() from a test

Hi, I'm trying to get the requested path through Request::path() in routes.php file. It does work when making a real request, but it doesn't when using call() from a test with phpUnit. Am I using it wrong? Is there a better way to make dynamic routing to controllers without using request path? Thanks!

daneel's avatar
daneel's avatar daneel11yrs agoTesting
0
1
6ber6ou's avatar

Laravel 5 and Test Envornment

Hi all. I don't understand very much how I can configure 3 different environment (local, test, and production). I just saw this tuto : https://laracasts.com/series/laravel-5-fundamentals/episodes/6 Here's what I understood : - The default .env file is set for my local environment. - To setup production variables I create a .env file on my production server with inside : APP_ENV

6ber6ou's avatar
6ber6ou's avatar 6ber6ou11yrs agoGeneral
2
1
Last reply by 6ber6ou 11yrs ago
PatrickBauer's avatar

How to test if a user which tries to log in is confirmed yet

Hi guys, I know laravel doesn't provide an email confirmation machanism for new users but I'm trying to implement my own. As soon as the user tries to log in, I'm dispatching an event handler for the auth.attemt event and do my confirmation check. How do I link back to the login page and show the user an error message? Is the event system not the right choice for this kind of t

PatrickBauer's avatar
PatrickBauer's avatar jekinney11yrs agoGeneral
11
1
Last reply by jekinney 11yrs ago
DMA's avatar

Unit test a repository

I want to test a method called 'loadById', so I've written the following test: <?php use App\Models\User; class TestDbUserRepository extends TestCase{ public function testCanLoadById() { $mock = Mockery::mock('App\Models\User'); $repository = new App\Repositories\User\DbUserRepository(); $mock->shouldReceive('findOrFail')->once()->

DMA's avatar
DMA's avatar JeffreyWay11yrs agoTesting
4
1
Last reply by JeffreyWay 11yrs ago
pstephan1187's avatar

Setting Domain in Route Test with PHPUnit

My app works on multiple domains. Depending on the domain you access the app on, different controllers are called. Here is how the routes file is setup: Route::group(['domain' => getenv('APP_DOMAIN')], function(){ //... lots of routes }); //Catch all Route::any('{all}', 'SitesPublicController@index')->where('all', '.*'); So if the domain matches the APP_DOMAIN env

pstephan1187's avatar
pstephan1187's avatar pstephan11...11yrs agoGeneral
3
7
Last reply by pstephan1187 11yrs ago
kfirba's avatar

How to test middleware

Hello! I'm trying to limit the access to my application for registered users only. I'm also restricting the registration form to registered users only. I need to somehow test that it is actually working. I'm trying to figure out how I can possible write such a test while focusing on the Domain layer, which means I can't do something like $this->visit('/'); I need to some

kfirba's avatar
kfirba's avatar JarekTkacz...11yrs agoGeneral
5
1
Last reply by JarekTkaczyk 11yrs ago
yayuj's avatar

Mysterious 100% test coverage

I'm studying unit testing and I started seeing some projects made by the creator of the PHPUnit and I saw this project: https://github.com/sebastianbergmann/money/ - The thing is that he has several classes and I saw every single test of him and he doesn't test them, but they are all 100% coverage, how is that possible? What is that magic?

yayuj's avatar
yayuj's avatar JarekTkacz...11yrs agoGeneral
9
1
Last reply by JarekTkaczyk 11yrs ago
zandzpider's avatar

Codeception run setup once and not once per test?

Hello! Writing a integration test using \Codeception\TestCase\Test I have a class that i have under test and i've written a few tests for it. The problem is that is runs _before() before every tests. This takes along time Is it possible to run it only once or am i forced to gather all my test functions to one function? Was hoping to split up the tests to keep it clean. All

zandzpider's avatar
zandzpider's avatar zandzpider11yrs agoTesting
0
6
joshuahornby's avatar

Which test is actually testing the most?

Quick question, both these tests return green and I was just wondering which method everything prefers. For the record I am using the TestDummy package. /** @test **/ public function intergrationTestOne() { $content = Factory::times(3)->create('App\Models\Content'); $data = $this->repository->getAllContent(); $this->assertCount

joshuahornby's avatar
joshuahornby's avatar JarekTkacz...11yrs agoGeneral
1
1
Last reply by JarekTkaczyk 11yrs ago
johnny's avatar

How would you unit test this helper function

I have a little helper function, and I'd like to write a test for it. if ( ! function_exists('lang') ) { /** * Get the translation for the given key or return the default value. * * @param string $key * @param array $default * @return string */ function lang($key, $default = null) { if (Lang::has('system.'.$key)) return L

johnny's avatar
johnny's avatar johnny11yrs agoTesting
5
1
Last reply by johnny 11yrs ago
freekmurze's avatar

How to test method chains with PhpSpec

Imagine your have this class: <?php class Elasticsearch { protected $indexName; public function __construct(Client $elasticsearch) { $this->elasticsearch = $elasticsearch; } /** * Set the name of the index that should be used by default * * @param $indexName * @return $this */ public function setIndexName($i

freekmurze's avatar
freekmurze's avatar silence10yrs agoRequests
3
1
Last reply by silence 10yrs ago
NoorDeen's avatar

how to test icon links

I want to test some links without text and with some icon by codeception Webdriver module and phantomjs . the normal links with text found with: $I->seeLink('users','/users.php'); how to test links with icons not text like this : <a class="btn btn-info" href="/users.php"> <i class="fa fa-users"></i> </a>

NoorDeen's avatar
NoorDeen's avatar sitesense11yrs agoTesting
5
1
Last reply by sitesense 11yrs ago
ajtrichards's avatar

PHPUnit - Test and Middleware has 2 different session tokens

In my App i've written some middleware that checks if a Session variable called contract_id is present - if not, it redirects to a page where the user can set a contract ID. This works fine when running in the browser. However, when it comes to writing a unit test I keep getting a failure. My unit test is: <?php use App\User; use Illuminate\Http\Request; class SecurityTe

ajtrichards's avatar
ajtrichards's avatar ajtrichard...11yrs agoTesting
0
1
anchour's avatar

Login cest not working in Codecept test, but works in the browser.

I'm not quite sure what I'm missing here. My test seems simple enough - I'm just not sure why it's failing on the it_logs_the_user_in test. Here's my test: <?php // ... public function it_logs_the_user_in(FunctionalTester $I) { $I->am('guest'); $I->amGoingTo('log into the dashboard'); $I->haveEnabledFilters(); $I->dontSeeAut

anchour's avatar
anchour's avatar Mike Hople...11yrs agoTesting
7
1
Last reply by Mike Hopley 11yrs ago
johan's avatar

Simple test, get: ErrorException: Array to string conversion

Hello! I'm running the simple test from the guide, and instead of a: Base table or view not found~ error I get: ErrorException: Array to string conversion. I can't figure out why. The formatting on this forum confused me a bit so I instead pasted my files here: http://justpaste.it/i5fy Sorry for the inconvience, but thanks for the help!

johan's avatar
johan's avatar johan11yrs agoTesting
2
1
Last reply by johan 11yrs ago
Ortix's avatar

ENV variables empty on test site using Forge

I have 2 sites on my digitalocean droplet using forge. The production and the test site. I've created several ENV variables (including the variable ENVIRONMENT = production) on my production site which work fine. However, nothing works on my test site. Any environment variable I create simply is not available in $_ENV... currently I have these 3 files: .env.php .env.staging.

Ortix's avatar
Ortix's avatar mikebronne...11yrs agoGeneral
6
1
Last reply by mikebronner 11yrs ago
aedart's avatar

[L5] How to unit test Eloquent models in your workbenches

While being in the process of developing multiple packages (inside workbench), I found myself in the situation, where I needed to create unit tests for my Eloquent models - however, this has caused a variety of issues for me. First, I cannot simple create new instances of my models, because they are unable to connect to a given database (which I have specified inside my "testi

aedart's avatar
aedart's avatar aedart11yrs agoTesting
6
1
Last reply by aedart 11yrs ago
ovidiu_dtp's avatar

How do you unit test file uploads?

I was thinking, how can you mock and test if file upload works as intended? I mean, a proper unit test. See it pass, see it fail... Can I just use a file I have on my HDD and feed the path?

ovidiu_dtp's avatar
ovidiu_dtp's avatar deweller9yrs agoTips
4
1
Last reply by deweller 9yrs ago
tzookb's avatar

adding test to my package with DB

I have a package for laravel for user-messaging. It creates several tables with migrations, and I want to add tests to my package. In my laravel projects I use sqlite, so it's not a problem. But this package is not in a laravel project, it is only a package, so how can I test it? any ideas?

tzookb's avatar
tzookb's avatar tzookb11yrs agoGeneral
1
1
Last reply by tzookb 11yrs ago
otherjohn's avatar

How would you write a phpspec test for this?

Hi, I have the following code in a Repository I would like to learn how to unit test for the create() method. I want to test the firing of the event and the saving of the account. I beleive this is more of a functional test but I want to learn how to write this properly as a unit test. Can some give me some direction? class AccountRepository implements AccountInterface { ... .

otherjohn's avatar
otherjohn's avatar otherjohn11yrs agoGeneral
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.