ifpingram

ifpingram

Member Since 4 Years Ago

Experience Points 13,815
Experience Level 3

1,185 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 23
Lessons
Completed
Best Reply Awards 30
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

12 Mar
2 years ago

ifpingram left a reply on Production.ERROR: Call To A Member Function BeginTransaction() On Null

@ttwb good find! Yes, this is on a Digital Ocean VM, although we're not reporting any errors since adding the supervisor restarting job, but if / once it rears it's ugly head again we'll follow your findings above. I just don't have the time at present to re-provision a new server... Many thanks for all your digging here; much appreciated!

05 Mar
2 years ago

ifpingram left a reply on Production.ERROR: Call To A Member Function BeginTransaction() On Null

@ttwb good stuff - fingers crossed it works! I have a feeling that this temporary fix will become permanent, as it looks like it might take quite a lot of work to get to the bottom of, and I don't have the time to investigate any further. :( I'll keep an eye on the thread in case you have the chance to investigate further yourself, but I would say that this hack should suffice...

04 Mar
2 years ago

ifpingram left a reply on Production.ERROR: Call To A Member Function BeginTransaction() On Null

@ttwb I just put the command in Forge as:

157276 Hourly 0 * * * * root /usr/bin/supervisorctl restart laravel-worker-scriptname:*

I haven't had a chance yet to analyse the logs, but should do so next week to see if it is causing errors still for a while like yours is.

No idea if it is the server, or something in the code base / supervisor. This is on a box provisioned by Laravel Forge (Ubuntu) using php7.1; is that a similar server environment to yours?

02 Mar
2 years ago

ifpingram left a reply on Production.ERROR: Call To A Member Function BeginTransaction() On Null

@ttwb we can't find a solution to this, so what we have done is we restart the relevant supervisor jobs via a cron every hour. It's not ideal, but it seems to work, as we've not had these PDO exceptions thrown this morning...

01 Mar
2 years ago

ifpingram left a reply on Production.ERROR: Call To A Member Function BeginTransaction() On Null

@ttwb FYI ours started to error at 06:25:15 this morning!

ifpingram left a reply on Production.ERROR: Call To A Member Function BeginTransaction() On Null

@ttwb no idea what is causing this, but we are having exactly the same problem currently. We will post more as/when/if we find anything...

22 Feb
2 years ago

ifpingram left a reply on Testing If A Tag Have A Majuscule

Je te conseil de enlever le duplication de tags avant que ton array map.

...
        array_walk($tags_to_create, function (&$item) {
            $item = ucfirst(strtolower($item));
        });

        $tags_to_create = array_unique($tags_to_create);

        $tags_to_create = array_map(function ($tag) {
            return [
                'name' => $tag,
                'slug' => Str::slug($tag),
                'produit_count' => 1
            ];
        }, $tags_to_create);
...
06 Feb
2 years ago

ifpingram left a reply on Disable Exception Handling - Class Is Not Bound To Service Container

You need to be using PHP7 in order to make use of anonymous classes. Can you confirm that you are using PHP 7, not 5?

ifpingram left a reply on Database Testing - Right Approach?

You should be seeding the test data at the beginning of the test, therefore you should never have a situation where "more data" is added over time. Ergo, you and your coworker are really having the wrong argument :)

17 Jan
2 years ago

ifpingram left a reply on Testing Mail And Asserting Each Email Was Sent

Take a look at this video, it may provide some ideas to work out how to write the test so it passes:

https://adamwathan.me/2016/01/25/writing-your-own-test-doubles/

20 Dec
2 years ago

ifpingram left a reply on Access Certain Production Data From Testing Environment

"Copy the database using a seeder?" - this one; never access production databases from tests!

28 Nov
2 years ago

ifpingram left a reply on Testing Without 'real Data'

@cawex In answer to your questions:

  1. Keep DatabaseTransactions and put it in the setUp() function, so that it runs it at the beginning of each test.

  2. Do not use DatabaseTransactions or DatabaseMigrations, put it in the setUp() and then also put in a setUpBeforeClass() method:

$this->artisan('migrate');

and then put this in tearDownAfterClass() method:

$this->artisan('migrate:rollback');
  • I never use the 2nd option, so cannot verify that it works correctly with Laravel's TestCase, but the option is there to do it in PHPUnit...
25 Nov
2 years ago

ifpingram left a reply on Event Doesn't Store Model While Unit Testing

No idea I am afraid. I have never used Eloquent events; sometimes there can be a little too much voodoo behind the scenes, so I often avoid these sort of features.

ifpingram left a reply on Event Doesn't Store Model While Unit Testing

Looks like you need to call createMonthsBudget() manually in the setup, as it is not registering the Model Event:

 public function setUp()
    {
        parent::setUp();

        // Create an user
        $user = factory(Budgeck\Models\User::class)->create();

        // Create an account for the user
        factory(Budgeck\Models\Account::class)->create([
            'id'         => 1,
            'user_id'    => $user->id,
        ]);

        // Add account budget
        $this->account_budget = factory(Budgeck\Models\AccountBudget::class)->create([
            'id'         => 4,
            'amount'     => 300,
            'account_id' => 1,
        ]);

        $this->account_budget->createMonthsBudget();
    }
24 Nov
2 years ago
23 Nov
2 years ago

ifpingram left a reply on Segmentation Fault When Requesting Endpoints With Bearer Authentication Token

Doesn't look like you are doing anything wrong! Which version of PHP is it? Perhaps try to upgrade to latest stable one if not already?

22 Nov
2 years ago

ifpingram left a reply on TDD - How To Test Controller Validation?

@Kandown You have massively overcomplicated things. Testing is essentially about taking an input, passing it through some code, then verifying the outcomes. Instead you are introspecting into the code itself, and this will only lead to pain later on.

To begin with the test code is very difficult to read at a glance. I have looked over it twice and have no idea what is going on. In six months time, when you go back to look at it, nor will you!

Secondly, you are essentially trying to test Laravel's internal features. These are tested within the framework itself. There is no need for you to do it again.

Thirdly, and going back to my original point, unless you are leaving out bits of test code in your "Usage" section, you are not verifying outcomes but looking at system configuration directly. System configuration will have an effect on outcomes, but it is the outcomes you should be asserting against.

What you should be doing is setting up the test to drive out the outcomes you are looking to get when the wrong input is received. Then the assertions should be against the response you receive. If the validation rules are broken, then your response should indicate which rules are broken and you should then assert accordingly...

ifpingram left a reply on Guideline To Manage The Number Of Tests In A File

For "integration" level tests, I tend to group them by behaviour / feature. For example, I have the following tests for a search engine I have written:

tests/api/SaleAdvertSearch/EndToEndTest.php (2279 lines) tests/api/SaleAdvertSearch/InvalidSearchTest.php (343 lines) tests/api/SaleAdvertSearch/RetrieveAdvertByIdTest.php (68 lines) tests/api/SaleAdvertSearch/SinglePageOfResultsTest.php (150 lines) tests/api/SaleAdvertSearch/StartPageOutOfBoundsTest.php (45 lines) tests/api/SaleAdvertSearch/ZeroResultsTest.php (71 lines)

as you can see, I don't really worry too much about the size of the files. The EndToEnd test can be a little unwieldy, but I think that if I was to split it down further into all the various search permutations, I would end up with dozens of files and this itself would become a problem in the folder...

For strict "unit" tests, it is one file per class, which is standard.

11 Nov
2 years ago

ifpingram left a reply on Calling PHPUnit From Artisan Command Will Ignore The XML File

@ludo237 unless I've missed something, why not just do this in a shell script? What advantage does doing it in Artisan bring?

08 Nov
2 years ago

ifpingram left a reply on Moving Image Files In Seed: Permissions Issues

@zachleigh your images folder does not have group write permissions. I would think that may have something to do with it?

27 Oct
2 years ago

ifpingram left a reply on How To Unit Test The Requeue/failure Of A Job?

@abodnar I presume you are on 5.2 and not 5.3? Are you trying to achieve assertPushed() and assertNotPushed()? If so, why not take a look at those methods in 5.3 and see if they give you any ideas?

20 Oct
2 years ago

ifpingram left a reply on Lumen: Error While Mocking Request Facade

@madhur2791 can you post the whole test, not just the mock please?

19 Oct
2 years ago

ifpingram left a reply on Lumen: Error While Mocking Request Facade

@madhur2791 See the very bottom warning on this page:

https://laravel.com/docs/5.3/mocking#mocking-facades

"You should not mock the Request facade. Instead, pass the input you desire into the HTTP helper methods such as call and post when running your test. Likewise, instead of mocking the Config facade, simply call the Config::set method in your tests."

27 Sep
2 years ago

ifpingram left a reply on Testing Controller & Mocking Request

@squibby Testing controllers is easiest using the Laravel integrated package, as opposed to PHPUnit itself. You have nothing really to mock out here, so you're investigating a solution to a different problem.

This said, I would not really bother testing the above as there is not a lot of bespoke non-framework logic in your code. I would certainly TDD to arrive at the above code, but now it is written, there isn't much you can actually test beyond a simple catch-all regression test to ensure that the request rules are doing what they should.

26 Sep
2 years ago

ifpingram left a reply on Functional Test API Using Behat.

@andfelzapata I don't think Behat is very well supported in Laravel. I only use the Laravel-integrated testing, but then I make sure that I do not use Javascript for the code under test. Is it essential that you test the Javascript part of the code (i.e. if it is Ajax, can you just test the Ajax calls etc.), and is it essential that you use Behat?

ifpingram left a reply on How To "DRY Up" My Tests Set Up

@haakym you have already answered your own question :) I'd opt for options 2 or 3. However, be aware that you have subtle differences in the set up of these tests, so you may be best to just leave the set up in each test, as you may end up having to pass in a number of parameters to the functions you extract the set up into. This would probably just make it more difficult to read what the test is doing.

I tend to find that I often have between 3-5x more test code than my Model / Controller logic, so verbosity and repetition in tests is not itself a problem which needs to be DRYed out as zealously as in the logic.

13 Sep
2 years ago

ifpingram left a reply on Database Transactions Doesn't Prevent Id Incrementation

@brslv try using DatabaseMigrations instead.

14 Aug
2 years ago

ifpingram left a reply on PHPUnit: Show $errors Messages That Laravel Throws

@matthijs110 I don't think it is possible unless you output the $errors from your code. Unit testing is not privy to the internals of what is going on within the Laravel instance; instead it is taking an input, passing it to the Subject Under Test and then making sure that the output is as desired; it can't really see in any further without using test doubles of some sort.

It looks like your test is wrong. You instead should be writing a test that explicitly fails to log in, and then test to make sure that the desired redirect is made. Then the test will pass.

ifpingram left a reply on Testing And The "new" Keyword

@imJohnBon to allow mocking of the objects in question, I would make the object before putting it into the argument. The docs are not focussed on testability, so this is understandable it is written like they are. To allow mocking of the objects, pull the object from the container prior to using it as an argument, e.g.

$shipping_status_updated = app(ShippingStatusUpdated::class, ['update' => $update]);
broadcast($shipping_status_updated);

Then in your tests, you can swap out ShippingStatusUpdated::class in the usual way:

$shipping_status_updated_mock = Mockery::mock(ShippingStatusUpdated::class);
$this->app->instance(ShippingStatusUpdated::class, $shipping_status_updated_mock);
03 Jul
3 years ago

ifpingram left a reply on How Do You Test Your Commands? (phpunit)

@bjones2015 this is correct, but IIRC this does not allow the output of the command to be retrieved, hence the need to dig a little deeper and return the following for the assertions:

$this->commandTester->getDisplay();
28 Jun
3 years ago

ifpingram left a reply on How Do You Test Your Commands? (phpunit)

@alariva looks good, although I think the naming of arrangeFixture() is wrong; it should be seedAppointment() or similar, as what you are doing is seeding the system prior to testing the report...

27 Jun
3 years ago

ifpingram left a reply on How Do You Test Your Commands? (phpunit)

@alariva here is a post I wrote a few months ago which may be of help. It may be that you are missing:

->setLaravel(app());
22 Jun
3 years ago

ifpingram left a reply on Logs For Laravel Testing?

@shawnyv I would probably write a helper function which echos the following to a log file:

$this->response->getContent();

I am not sure how to get this to execute only on failure, but looking at the phpunit docs, it seems that maybe a TestDecorator may work:

https://phpunit.de/manual/current/en/extending-phpunit.html#extending-phpunit.PHPUnit_Framework_TestListener

Good luck!

20 Jun
3 years ago

ifpingram left a reply on How To Swap Out A IoC Created Object From Controller

@beerbuddha Yes I guess both will work, but I only ever use instance() as in tests it is used to register existing objects (i.e. the mock I have made) into the container.

The bind method only binds the closure to make the object into the container, which makes the code a little less readable as I would need to write the mock within the closure, thus I use bind within service providers only...

ifpingram left a reply on Test Laravel Package Integration

@kubaszymanowski yes I see what you mean, I've only given you half of the answer - apologies :)

If you are on Larachat Slack Testing channel, give me a shout on there, as it is easier to show you in real time as opposed to via the forum...

ifpingram left a reply on How To Swap Out A IoC Created Object From Controller

@beerbuddha To swap the IoC instance with the mock, use the following in the test

    public function testExample()
    {
         $stream = \GuzzleHttp\Psr7\stream_for('string data');
        // ... init MockHandler...
        // ....

        $this->app->instance(MockedClassName::class, $mock);

        $this->get('/');

        $this->assertEquals(
            $this->response->getContent(), 'string data'
        );
    }
19 Jun
3 years ago

ifpingram left a reply on Test Laravel Package Integration

@kubaszymanowski the easiest thing to do, is to leave the tests in your composer package, then import the package into a test Laravel app and then use them from this apps tests using a PHP trait.

Here's an example I put online to test somebody else's package (The Garbage Man package)

https://github.com/ifpingram/laravel-garbage-man-host

https://github.com/ifpingram/laravel-garbage-man-host/blob/master/composer.json

https://github.com/ifpingram/laravel-garbage-man-host/blob/master/tests/PurgeCommandTest.php

HTH!

12 Jun
3 years ago

ifpingram left a reply on Codeship CI Environment Variables

@Guardian good stuff - I see the issue now. I do not use MySQL with Codeship, so had not encountered this before, but makes good sense now you have explained it - thanks!

11 Jun
3 years ago
09 Jun
3 years ago

ifpingram left a reply on Mailcatcher Not Catching Anything...

@zachleigh good catch; that kind of missing parameter is the sort of thing that breaks people's spirit indeed :(

ifpingram left a reply on Mailcatcher Not Catching Anything...

@zachleigh have you considered mocking this, and then there is no need to send the emails at all? This video specifically covers writing test doubles to test email sending. No reliance on external dependancies, and is lightning quick...

07 Jun
3 years ago

ifpingram left a reply on Testing Service Providers

@Centagon I guess this is because you are calling the app() command in your test, which refers to the app() of the testing environment and not the environment under test itself.

26 Apr
3 years ago

ifpingram left a reply on Failing When Tests In Subfolders

@wise have you added the namespace int he autoload section of composer.json?

"autoload": {
        "psr-4": {
            "Tests\\Acceptance\\": "tests/acceptance"
        }
    },

Try adding the above, then "composer du"...

ifpingram left a reply on Failing When Tests In Subfolders

@wise a couple of things:

  1. it's not often necessary to namespace tests, so I would just remove it altogether.

  2. I think namespaces are case-sensitive for components as well as classes, so you should use directory structure of "/tests/Acceptance/". I may be wrong, but in any case, if you follow #1, this is a redundant point ;)

25 Apr
3 years ago

ifpingram left a reply on Method Mockery_0_Illuminate_Http_Request::setUserResolver() Does Not Exist On This Mock Object

@sebastiansulinski it may well be something to do with the fact that you are unable to mock the Request facade:

https://laravel.com/docs/5.1/testing#mocking-facades

Note: You should not mock the Request facade. Instead, pass the input you desire into the HTTP helper methods such as call and post when running your test.

24 Apr
3 years ago

ifpingram left a reply on SeeInPage() Error With Phpunit Test

@ayekoto do you have the user you are logging in with created in the test database before the start of the test? You will probably need to seed it.

21 Apr
3 years ago

ifpingram left a reply on DB Rollback After All Tests In Class Are Finished?

@zaboo Ideally you should not be trying to persist test seed data across tests. Instead, you should seed each test with the data you need. If you need the same data between tests, then do the seeding in the setUp() method, which will then re-seed the same data at the beginning of each test (and thus achieve the same result that you are looking for)...

ifpingram left a reply on Mocking Config

@xirkus you need to also swap out the ConfigRepository in the IoC with the mock:

 public function it_returns_all_users_with_pagnation()
    {
        $configMock = m::mock(ConfigRepository::class)
            ->shouldReceive('get')
            ->with('legacy.db-connection')
            ->andReturn('sqlite-legacy-testing');

        $this->app->instance(ConfigRepository::class, $configMock);

        $response = $this->get('/api/v1/users');

        dd($response);
    }
19 Apr
3 years ago

ifpingram left a reply on PHPUNIT Testing Orderby? Can It Be Done?

@inventsimple as @spekkionu says, the thing to do is to seed the database then test against it, but as he also says, you are only testing Eloquent and thus this test is redundant.

Testing should be for the code / objects which you are writing. What is it that you actually wish to do with these rows when you retrieve them? That's the code which you want to be testing...

ifpingram left a reply on PHPUNIT Testing Orderby? Can It Be Done?

@inventsimple I'm sorry but I don't understand the question. Are you referring to the results of database queries, Eloquent collections or some other data object? Perhaps you can elaborate with an example of the data you are playing with, and we can try to see what can be done...