vendredi 30 juin 2017

laravel 5 behat tests are failing with functions in models

I’m running against an issue with behat / mink set up on Laravel 5.4 where its failing to return values from functions within models and I am looking for some advise on how i would resolve this issue.

An example on a very basic laravel install follows below:

eg. I have a model called User.php and inside it i have the following function

public static function someFunction(){
    return 'Some Function';
}

within my home.controller i have the following defined for index()

eg

/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Http\Response
 */
public function index()
{
        $user = Auth::user();
        return view('home',compact('user'));
}

and within the corresponding blade file i have the following

and i have a feature set up as the following:

Scenario: Home Page           # features/hometest.feature:6
    Given I am on the homepage  # FeatureContext::iAmOnHomepage()
    Then I should see "Laravel" # FeatureContext::assertPageContainsText()

Scenario: Check we can login
    When I go to "/register"
    And I fill in "Name" with "Dave"
    And I fill in "E-Mail Address" with "Dave@dave.com"
    And I fill in "Password" with "password"
    And I fill in "Confirm Password" with "password"
    And I press "Register"
    And I should see "You are logged in!"

Scenario: Check we can access the homepage as Dave
    Given I am logged in as Dave
    When I go to "/home"
    And I should see "Some Function"

which corresponds to a function within my FeatureContext.php

/**
 * @Given /^(?:|I )am logged in as Dave$/
 */
public function iAmLoggedInAsDave()
{
    $this->visit('/login');
    $this->fillField('E-Mail Address', 'dave@dave.com');
    $this->fillField('Password', 'password');
    $this->pressButton('Login');
    $this->printCurrentUrl();
}

if i view the above via the browser, i can see

You are logged in! {"id":1,"name":"Dave","email":"Dave@dave.com","created_at":"2017-06-30 16:10:39","updated_at":"2017-06-30 16:10:39"} Some Function

Which would correspond to a pass for my test.

But when i run behat, within my /home/vagrant/Code/client/client.app directory ../vendor/behat/behat/bin/behat

I get a fail

    Scenario: Check we can login       # features/hometest.feature:19
        Given I am logged in as Dave     # FeatureContext::iAmLoggedInAsDave()
            │ http://localhost/home
        When I go to "/home"             # FeatureContext::visit()
        And I should see "Some Function" # FeatureContext::assertPageContainsText()
            The text "Some Function" was not found anywhere in the text of the current page. (Behat\Mink\Exception\ResponseTextException)

and i get the following error in my logs.

Next ErrorException: Call to undefined method Illuminate\Database\Query\Builder::someFunction() (View: /home/vagrant/Code/client/http://ift.tt/2s9LZmb) in /home/vagrant/Code/client/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2450

My current development platform is set up using homestead using vagrant.

I have the following within behat.yml

default:
    extensions:
        Laracasts\Behat:
            env_path: .env.behat
        Behat\MinkExtension:
            default_session: laravel
            laravel: ~



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire