اذهب إلى المحتوى
  • 0

الميثود get () غير معرفة في Laravel phpunit

محمد لارافيل

السؤال

أحاول استخدام phpunit  وأحثل على هذا الخطأ:

$ phpunit

1) Tests\Feature\ExampleTest::testBasicTest
Error: Call to undefined method Tests\Feature\ExampleTest::get()

/Users/xxxx/dev/xxxx/tests/Feature/ExampleTest.php:12

الكود في tests/Feature/ExampleTest.php

<?php

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;

class ExampleTest extends TestCase
{
  public function testBasicTest()
  {
    $response = $this->get('/');
    $response->assertStatus(200);
  }
}

الكود في tests/TestCase.php

<?php

namespace Tests;

use PHPUnit\Framework\TestCase as BaseTestCase;
// use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
  public function setUp():void { parent::setUp(); }
  public function tearDown():void { parent::tearDown(); }
  use CreatesApplication;
}

هل أقوم بفعل شيئا خاطئا؟

رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 0

الخطأ بسبب:

<?php

namespace Tests;

use PHPUnit\Framework\TestCase as BaseTestCase;
// use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase

تقوم بعمل extends للصنف:

use PHPUnit\Framework\TestCase as BaseTestCase;

هذا الصنف لا يحتوي على توابع التفاعل مع طلبات http مثل get، post، put و غيرها.

الصنف المهيأ مُسبقاً لعمل ذلك هو:

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

لأنه يستعمل ال Trait:

Illuminate\Foundation\Testing\Concerns\MakesHttpRequests;

الذي يتيح استعمال تلك التوابع.

ويقوم بوراثة الصنف:

use PHPUnit\Framework\TestCase as BaseTestCase;

مُسبقاً، و يضيف عليه أشياء أخرى.

فالحل فقط بتغيير الصنف الذي ترث منه أصناف الإختبار:

<?php

namespace Tests;

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
//use PHPUnit\Framework\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...