में होता है, इसलिए मेरे पास "बनाएं" मान के साथ एक बटन वाला एक पृष्ठ है। जब मैं किसी भी फ़ील्ड को भरने के बिना उस बटन को क्लिक करता हूं, तो यह फ़ॉर्म को मान्य करता है और उसी पृष्ठ पर त्रुटि संदेशों को प्रदर्शित करता है। जब मैं ब्राउज़र में ऐसा करता हूं, तो यह ठीक काम करता है, लेकिन जब मैं इसे phpunit
के साथ करता हूं, तो इसका अप्रत्याशित परिणाम होता है और मुझे नहीं पता कि क्यों।लार्वाल phpunit परीक्षण विफल रहा है। एक अप्रत्याशित पृष्ठ पर जा रहे हैं। केवल परीक्षण
यहाँ मेरी एकीकरण परीक्षण है:
public function testCreateValidation()
{
$this->visit(route('patients.indexes.create', $this->patient->id));
$this->press('Create');
$this->seePageIs(route('patients.indexes.create', $this->patient->id));
}
और यह परिणाम है:
There was 1 failure:
1) Tests\Integration\IndexControllerTest::testCreateValidation
Did not land on expected page [http://localhost/patients/69/indexes/create].
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'http://localhost/patients/69/indexes/create'
+'http://localhost/patients'
/vagrant/vendor/laravel/framework/src/Illuminate/Foundation/Testing/InteractsWithPages.php:141
/vagrant/tests/Integration/IndexControllerTest.php:51
मुझे समझ नहीं आता क्यों यह patients
पृष्ठ पर पुनः निर्देशित किया जा रहा है।
public function create($id)
{
$index = $this->indexes->newInstance();
$patient = $this->patients->findOrFail($id);
return view('patient.index.create', ['index' => $index, 'patient' => $patient]);
}
यहाँ और create
देखने के प्रासंगिक अनुभाग है:
यहाँ Laravel create
विधि है कि परीक्षण किया जा रहा है
<?= Form::open(['route' => array('patients.indexes.store', $patient->id), 'class' => 'form-horizontal']) ?>
@include('patient.index._form')
<?= Form::submit('Create', ['class' => 'btn btn-primary']) ?>
<?= Form::close() ?>
और अंत में store
विधि है कि यह भेजा जा रहा है प्रति:
public function store(IndexRequest $request, $id)
{
$index = $this->indexes->newInstance();
$index->fill($request->all());
$index->patient_id = $id;
$index->save();
$patient = $index->patient;
return redirect()->route('patients.edit', $patient);
}
मैं भी एक FormRequest उपयोग कर रहा हूँ इनपुट को मान्य करने के:
public function rules()
{
return [
'index_title' => 'required',
'index_description' => 'required',
];
}
तो अनिवार्य रूप से, क्योंकि यह IndexRequest
में मान्यता विफल हो रहा है, IndexRequest
इसे वापस patients.indexes.create
दृश्य और प्रदर्शन त्रुटियों के लिए लात चाहिए। लेकिन कुछ कारणों से इसे मरीज़ पेज पर लाया जा रहा है (यह केवल परीक्षण में होता है, यदि मैं ब्राउज़र में मैन्युअल रूप से बनाएँ बटन पर क्लिक करके इसे आज़माता हूं, तो यह अपेक्षित काम करता है)
मुझे पहले यह समस्या है लेकिन इसे हल करने में कभी सक्षम नहीं हुआ है। कोई विचार?
Laravel का कौन-सा संस्करण चल रहे हैं? – BrokenBinary