alariva

Member Since 3 Years Ago

Buenos Aires

Developer at http://timegrid.io/

Experience Points 32,690
Experience Level 7

2,310 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 318
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

14 Jul
10 months ago

alariva left a reply on [L5] Disable CSRF Middleware On Certain Routes

@kilrizzy Very handful approach, got it working neatly. Thanks!

28 Jun
2 years ago

alariva left a reply on Laravel 5.3 Wish List

@TaylorOtwell What about a consume-once-token middleware , so double-submitting can easily be prevented serverside?

https://laracasts.com/discuss/channels/laravel/preventing-multiple-submits?page=1

27 Jun
2 years ago

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

Finally, a refactored version with 2 test cases

<?php

use App\Console\Commands\SendBusinessReport;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\Console\Tester\CommandTester;
use Timegridio\Concierge\Models\Appointment;

class SendBusinessReportTest extends TestCase
{
    use DatabaseTransactions;
    use CreateBusiness, CreateUser, CreateContact, CreateAppointment;

    protected $command;

    protected $commandTester;

    /**
     * @var \Timegridio\Concierge\Models\Business
     */
    protected $business;

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

        $application = new ConsoleApplication();

        $testedCommand = $this->app->make(SendBusinessReport::class);
        $testedCommand->setLaravel(app());
        $application->add($testedCommand);

        $this->command = $application->find('business:report');

        $this->commandTester = new CommandTester($this->command);

        $this->arrangeFixture();
    }

    /** @test */
    public function it_reports_to_all_businesses()
    {
        $this->commandTester->execute([
            'command' => $this->command->getName(),
        ]);

        $this->assertRegExp('/Scanning all businesses../', $this->commandTester->getDisplay());
    }

    /** @test */
    public function it_reports_to_a_single_business()
    {
        $this->commandTester->execute([
            'command'  => $this->command->getName(),
            'business' => $this->business->id,
        ]);

        $this->assertRegExp("/Sending to businessId:{$this->business->id}/", $this->commandTester->getDisplay());
    }

    protected function arrangeFixture()
    {
        $issuer = $this->createUser();

        $this->business = $this->createBusiness();

        $contact = $this->createContact();

        $this->makeAppointment($this->business, $issuer, $contact, [
            'status' => Appointment::STATUS_CONFIRMED,
            ]);
    }
}

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

@ifpingram , thanks for the hint. As I'm new to some of these concepts, it took me a while to get it working... however, it seems I finally got to the solution. I believe I followed your steps, correctly. Would you help me validate that? (Yep, I know it can be refactored, I'll get over that once everything looks fine :) )

<?php

use App\Console\Commands\SendBusinessReport;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\Console\Tester\CommandTester;
use Timegridio\Concierge\Models\Appointment;

class SendBusinessReportTest extends TestCase
{
    use DatabaseTransactions;
    use CreateBusiness, CreateUser, CreateContact, CreateAppointment, CreateService, CreateVacancy;

    /** @test */
    public function it_reports_to_all_businesses()
    {
        $this->arrangeFixture();

        $application = new ConsoleApplication();

        $testedCommand = $this->app->make(SendBusinessReport::class);
        $testedCommand->setLaravel(app());
        $application->add($testedCommand);

        $command = $application->find('business:report');

        $commandTester = new CommandTester($command);

        $commandTester->execute([
            'command' => $command->getName(),
        ]);

        $this->assertRegExp('/Scanning all businesses../', $commandTester->getDisplay());
    }

    /**
     * Arrange Fixture.
     *
     * @return void
     */
    protected function arrangeFixture()
    {
        $this->owner = $this->createUser();
        $this->issuer = $this->createUser();

        $this->business = $this->createBusiness();
        $this->business->owners()->save($this->owner);

        $this->contact = $this->createContact();
        $this->contact->user()->associate($this->issuer);

        $this->service = $this->makeService();
        $this->business->services()->save($this->service);

        $this->vacancy = $this->makeVacancy();
        $this->vacancy->service()->associate($this->service);

        $this->business->vacancies()->save($this->vacancy);

        $appointment = $this->makeAppointment($this->business, $this->issuer, $this->contact, [
            'status' => Appointment::STATUS_CONFIRMED,
            ]);
    }
}
25 Jun
2 years ago

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

Thanks for the hint, I should have started from there!! Will post updates :)

alariva started a new conversation 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:

[email protected] ~/timegrid.io/app $ phpunit --filter=SendBusinessReportTest
PHP Warning:  The use statement with non-compound name 'Artisan' has no effect in /home/alariva/timegrid.io/app/tests/unit/Console/Commands/SendBusinessReportTest.php on line 4
PHP Stack trace:
PHP   1. {main}() /usr/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46
PHP   3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:129
PHP   4. PHPUnit_TextUI_Command->handleArguments() /usr/share/php/PHPUnit/TextUI/Command.php:138
PHP   5. PHPUnit_Util_Configuration->getTestSuiteConfiguration() /usr/share/php/PHPUnit/TextUI/Command.php:657
PHP   6. PHPUnit_Util_Configuration->getTestSuite() /usr/share/php/PHPUnit/Util/Configuration.php:789
PHP   7. PHPUnit_Framework_TestSuite->addTestFiles() /usr/share/php/PHPUnit/Util/Configuration.php:873
PHP   8. PHPUnit_Framework_TestSuite->addTestFile() /home/alariva/timegrid.io/app/vendor/phpunit/phpunit/src/Framework/TestSuite.php:409
PHP   9. PHPUnit_Util_Fileloader::checkAndLoad() /home/alariva/timegrid.io/app/vendor/phpunit/phpunit/src/Framework/TestSuite.php:335
PHP  10. PHPUnit_Util_Fileloader::load() /usr/share/php/PHPUnit/Util/Fileloader.php:76
PHPUnit 4.8.26 by Sebastian Bergmann and contributors.

PHP Fatal error:  Call to undefined method App\Console\Kernel::resolve() in /home/alariva/timegrid.io/app/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 217
PHP Stack trace:
PHP   1. {main}() /usr/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46
PHP   3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:129
PHP   4. PHPUnit_TextUI_TestRunner->doRun() /usr/share/php/PHPUnit/TextUI/Command.php:176
PHP   5. PHPUnit_Framework_TestSuite->run() /home/alariva/timegrid.io/app/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:440
PHP   6. PHPUnit_Framework_TestSuite->run() /home/alariva/timegrid.io/app/vendor/phpunit/phpunit/src/Framework/TestSuite.php:747
PHP   7. PHPUnit_Framework_TestCase->run() /home/alariva/timegrid.io/app/vendor/phpunit/phpunit/src/Framework/TestSuite.php:747
PHP   8. PHPUnit_Framework_TestResult->run() /home/alariva/timegrid.io/app/vendor/phpunit/phpunit/src/Framework/TestCase.php:724
PHP   9. PHPUnit_Framework_TestCase->runBare() /home/alariva/timegrid.io/app/vendor/phpunit/phpunit/src/Framework/TestResult.php:612
PHP  10. PHPUnit_Framework_TestCase->runTest() /home/alariva/timegrid.io/app/vendor/phpunit/phpunit/src/Framework/TestCase.php:768
PHP  11. ReflectionMethod->invokeArgs() /home/alariva/timegrid.io/app/vendor/phpunit/phpunit/src/Framework/TestCase.php:909
PHP  12. SendBusinessReportTest->it_tests_command() /home/alariva/timegrid.io/app/vendor/phpunit/phpunit/src/Framework/TestCase.php:909
PHP  13. Illuminate\Support\Facades\Artisan::resolve() /home/alariva/timegrid.io/app/tests/unit/Console/Commands/SendBusinessReportTest.php:14
PHP  14. Illuminate\Support\Facades\Facade::__callStatic() /home/alariva/timegrid.io/app/tests/unit/Console/Commands/SendBusinessReportTest.php:14

  [Symfony\Component\Debug\Exception\FatalErrorException]  
  Call to undefined method App\Console\Kernel::resolve() 

You can find my current attempt here, (broken tests), but maybe you can hint me something I'm missing :)

Side Note: You may ask why PHPUnit and not another testing framework. So far I'm generating my test coverage with PHPUnit and I'd like to stick to it until I feel the actual need to switch. However, all suggestions are welcome.

Thanks in advance!

01 Feb
3 years ago
31 Jan
3 years ago

alariva started a new conversation [L5.2] Where To Put Package's Integration Tests?

I've moved my application Backend into a package.

The Backend has it's own integration tests (typical visit and see kind), but I'm not sure about where should be stored and how should them be run.

  • If I keep them into the package's tests dir, I see I should have a phpunit.xml file that duplicates some already-existing declarations in the app's phpunit.xml, like the database connection credentials.

  • If I keep them into the app tests dir, I'm assuming that this package is always installed (which is actually optional) and that all possible backends behave the same, which makes me think that is not the place for it.

  • The other option I evaluate is publishing the tests, so I develop them into my package but they run with the whole application tests. I see this viable but not sure if it's a valid approach, and either could make it work when trying to publish.

alariva left a reply on Is It Possible To Prioritize A Package's Routes?

Another apparent solution I found is loading the package service provider before my application route service provider, like so:

        // ...

        Timegridio\Backend\TimegridioBackendServiceProvider::class,

        /*
         * Application Service Providers...
         */
        App\Providers\AppServiceProvider::class,
        App\Providers\AuthServiceProvider::class,
        App\Providers\ComposerServiceProvider::class,
        App\Providers\EventServiceProvider::class,
        App\Providers\RouteServiceProvider::class,

        // ...

instead of

        // ...

        /*
         * Application Service Providers...
         */
        App\Providers\AppServiceProvider::class,
        App\Providers\AuthServiceProvider::class,
        App\Providers\ComposerServiceProvider::class,
        App\Providers\EventServiceProvider::class,
        App\Providers\RouteServiceProvider::class,

        // ...

        Timegridio\Backend\TimegridioBackendServiceProvider::class,

        // ...

It is working and my tests passing, any caveats on this??

alariva left a reply on Is It Possible To Prioritize A Package's Routes?

@TerrePorter , thank you for the approach, seems to make sense.

So far I came up with 4 different approaches:

  • Forcing priority through a third party package would help but I found it overkill for my case and adding the need to forcedly (vs naturally) maintain priorities.

  • Using regex to skip a catch all group. This was not possible since ->when() cannot be used after ->group()

  • Prefixing a catchall and using regex to skip the backend (or a set) prefix when catching all. This is, I catch all but skip those prefixes starting with _ so as I can use them for system functions. This is the approach I took so far and it's working on this branch, but still there is something making noise to me; the App must allow a routing path to get resolved to the backend. Sounds more natural that backend route is processed first with no chance to the app to try to catch such important path.

  • Extracting Frontend into a package so it runs after the Backend package. Similar to the solution you told, and makes sense since it would hold all the entire frontend logic with the last catch all declaration.

30 Jan
3 years ago

alariva started a new conversation Is It Possible To Prioritize A Package's Routes?

This is the scenario: I have the application routes, and I'm extracting the backend as a package, so it now has it's own routes.

But the application currently handles -say, to simplify- 3 types of routes:

  • Application routes, run first
  • Backend routes, run after
  • Application catch everything, run last

So currently, since I got the Backend split, It's routes are registered last like follows:

  • Application routes, run first
  • Application catch everything, run last
  • Backend routes, run after

If you ask for actual code this is my route files pointing to the ROOT CONTEXT I want to extract

Thanks!

04 Jan
3 years ago

alariva left a reply on InvalidArgumentException: Unable To Locate Factory With Name [default] [App\Models\Domain]

Found the solution

Found the problem

I was all the time thinking I was working with the file tests/factories/factories.php since I was using laracasts/testdummy.

It turns out (probably since the migration to L5.1, but not sure), I was now using database/factories/ModelFactory.php which I one day updated with my old factories, but neved removed the tests/factories/factories.php and thus, editing it for new changes was worthless.

Now I've removed this file and kept a single factory file sticking to Laravel 5.1 solution out of the box.

References that helped:

01 Jan
3 years ago

alariva left a reply on InvalidArgumentException: Unable To Locate Factory With Name [default] [App\Models\Domain]

Thank you, it is indeed. If I'm not missing anything, it's being imported the same as -say- Business class, which works perfectly among the rest of the factories.

alariva started a new conversation InvalidArgumentException: Unable To Locate Factory With Name [default] [App\Models\Domain]

Hello everybody,

I'm trying to add a Factory to help increment my test coverage on some controllers. I've been using Factories with no issues till now, where I find no reason for this message and I can't figure out what is different from the rest of the factories, which are working perfectly.

The error is:

1) GuestBusinessControllerTest::it_presents_a_domain_home
InvalidArgumentException: Unable to locate factory with name [default] [App\Models\Domain].

In order not to make a never-ending post of code crap, I reference the useful files as follows:

Sidenotes: Yes, I did composer dump-autoload (Else, the error message would be different) Sidenotes: I tried to define the factory in another helper file, and dump-autoload. (Just in case) Sidenotes: I also tried renaming my model, thinking that Domain might be a conflicting keyword, but that seems not to be the issue.

Any hints on this are welcome!! Thanks!! :)

26 Dec
3 years ago

alariva left a reply on Blade, Javascript And Variables

For further scalability, another option is using PHP-Vars-To-Js-Transformer.

14 Dec
3 years ago

alariva left a reply on Submitting A Form Without A Submit Button?

Seems to be a border case between the bare controller tests and the tests requiring JS and such, for which Selenium is a proper tool to tackle that cases.

In my personal opinion, I wouldn't start using Selenium just for that, but if you believe you'll need some more browsing power (aka real beahvior) for your tests, you can start considering it.

03 Dec
3 years ago

alariva left a reply on How To $this->type() In A Hidden Input

@bobbybouwmann good point.

I'm willing to alter the _token field to simulate an expired or tampered token for my tests. Any solutions/suggestions so far?

26 Nov
3 years ago

alariva left a reply on Requesting Critical Advice On Coding Practices For Future Scalability

@bobbybouwmann

You just gave me some useful hints to start with, I will check those references and see how can I improve. Yes, Im missing some php oop background to use the correct terminology, I will be over that as well. Thank you!

alariva started a new conversation Critical Advice For Future Scalability

Hello artisans,

I've started a full web application and it's my first time on Laravel. I try to follow best practices as much as I can but I'm learning something new every day and that makes me change entire whole aspects of my project when I realize I'm doing something wrong.

Well, I know there is still a long way out, but I'd like to have your feedback regarding the critical warnings you would advice in order not to spread a bad practice all the way down the life cycle of the project. It's on an early stage where I can still correct code and follow better coding guidelines for future additions.

Some of the current concerns I have most of the problems to work on:

  • Unit Testing: How to write them in a systematic, clean and organized way. How to create different fixtures.
  • Static class calls. Specially for common functions like Log, Mail, Request
  • Laravel 5.1 upgrade: I noticed I still have Handlers and Commands folders, should I do something about it ?
  • Resource Controllers: I believe some of the functions I've implemented need not to be a resource controller, so maybe I could improve here.
  • Routing: I'm pretty sure there are optimizations I could do here but I'm not sure how.

Okay, that's a lot for now, any suggestions are welcome specially regarding coding practices that may help me for the future.

timegrid project on Github

Thank you for the feedback!!

10 Jul
3 years ago

alariva started a new conversation My First Custom Laravel 5.1 Package

Hi everyone,

I'm new to Laravel and I'm trying to learn and get attached to best coding practices, thus I'd gently ask for your review and kindly accept enhancement suggestions and collaboration.

I've developed an almost trivial Laravel 5.1 package which allows to easily include a Live Chat to your laravel application. This was to support my application in a modular way, and to learn the package coding basis.

Despite this is a very simple package, I'm pretty sure there are many things I can improve, so upgrades also go into a sane coding criteria.

https://github.com/alariva/tidiochat-laravel-5-package

Thank you in advance!