jeudi 23 juin 2016

Laravel: 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 and want to test my javascript. 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 extends SeleniumTestCase
{
    private $mock;

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

        $this->mock = $this->mock('App\Repositories\ReportRepository');
    }


    /** @test */
    public function select_a_specific_rule_report()
    {
        $user = $this->initUser();

        $this->mock->shouldReceive('getRulesListByRegions')
            //->with( $user->client->id, null )
            ->andReturn( json_decode( file_get_contents( base_path('tests/acceptance/raw/ReportRepository/getRulesListByRegions.json') ), true ) );

        $this->app->instance('App\Repositories\ReportRepository', $this->mock);


        $this->logIn()
            ->seePageIs( route( 'dashboard' ) )
            ->waitForElement( '#lnk-nav-reports', 2000 )
            ->clickCss( '#lnk-nav-reports' )
            ->waitForElement( '#lnk-reports-rules', 2000 )
            ->clickCss( '#lnk-reports-rules' )
            ->wait( 20000 );
    }

}

Aucun commentaire:

Enregistrer un commentaire