Laravel 5.4でbehat/minkが設定されていて、モデル内の関数から値が返ってこない場合、私はどのようにすればいいのでしょうか?この問題を解決してください。非常に基本的なlaravelインストール上のlaravel 5 behatテストがモデル内の関数で失敗しています
次の例では、次のとおりです。
など。 I User.phpというモデルを持っており、その中に私は私のhome.controller内で次の機能
public static function someFunction(){
return 'A Random Text String';
}
を持っている私は(インデックスに次のことを定義しています)
例えば
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$user = Auth::user();
return view('home',compact('user'));
}
と対応するブレードファイル内には次のものがあります。
{{$user}}
{{$user->someFunction()}}
と私はt彼は次のよう
私はブラウザを介して上記表示した場合、私のFeatureContext.php/**
* @Given /^(?:|I)am logged in as Dave$/
*/
public function iAmLoggedInAsDave()
{
$this->visit('/login');
$this->fillField('E-Mail Address', '[email protected]');
$this->fillField('Password', 'password');
$this->pressButton('Login');
$this->printCurrentUrl();
}
内の機能に対応し
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 "[email protected]"
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 "A Random Text String"
、私が見ることができるに相当するであろう
{"id":1,"name":"Dave","email":"[email protected]","created_at":"2017-06-30 16:10:39","updated_at":"2017-06-30 16:10:39"}
A Random Text String
私のテストのためのパス。私は
../vendor/behat/behat/bin/behat私/home/vagrant/Code/client/client.appディレクトリ 内、behatを実行したときに
しかし、私は取得に失敗
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 "A Random Text String" # FeatureContext::assertPageContainsText()
The text "A Random Text String" was not found anywhere in the text of the current page. (Behat\Mink\Exception\ResponseTextException)
私のログに次のエラーが表示されます。
次のErrorException:未定義メソッドを呼び出す\ Database \ Query \ Builder :: someFunction()(表示:/home/vagrant/Code/client/client.app/resources/views/home.blade.php)in /home/vagrant/Code/client/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2450
現在の開発プラットフォームは、放流剤を使用してホームステッドを使用して設定されています。
私はbehat.yml
default:
extensions:
Laracasts\Behat:
env_path: .env.behat
Behat\MinkExtension:
default_session: laravel
laravel: ~
私はもう少し明確に私の質問を変更しました。 Userモデル内のsomeFunction()メソッドは、この例では文字列を返します。出力はブラウザでレンダリングされるので、私は 'ランダムな文字列'を見ることができますが、テスト内には存在しません。たとえば、レンダリング時に同じ問題が発生します。、 '{{$ Foo-> Bar-> fieldname()}}'と '{{$ user-> hasRole( 'admin')}}' –
私は同様の問題を抱えていましたが、これを実行して解決しました ' 'php artisan config:cache''を最初に実行し、再度behatを実行してください。 – n31l
ありがとう@ n31l。それは悲しいことです。テストは '{{$ Foo-> fieldname()}} 'を出力しても' {{$ Foo-> Bar-> fieldname()}}'を出力すると失敗します。これらのモデルは、モデル内で$ this-> belongsTo()メソッドを介して結合されています)。これは魔法を好きではないという問題で問題になるでしょうか? –