gpt4 book ai didi

unit-testing - phpunit laravel 5.4 错误

转载 作者:行者123 更新时间:2023-12-04 05:04:15 25 4
gpt4 key购买 nike

我需要在 laravel 中使用单元测试,但他们需要下载库 laravel/browser-kit-testing当我下载它时告诉我他们需要 php 5.6我使用的是 php 5.4。

 public function testBasicTest()
{
$this->visit('/home')
->seePageIs('/login');
$response = $this->call('GET', '/dradmin');
$this->assertEquals(200, $response->status());
$this->visit('/login')
->type('mahmoud@mahmoud.com', 'email')
->type('123456', 'password')
->press('Login')
->seePageIs('/home');

}
}

当使用phpunit

Error: Call to undefined method Tests\Feature\UserTest::visit()

/Users/mahmoud310/ecare/tests/Feature/UserTest.php:21

我阅读了其他问题 Laravel 5.4 HTTP testing - method seeInElement

使用命令laravel/browser-kit-testing可以解决问题

在我的情况下不起作用

Using version ^1.0 for laravel/browser-kit-testing
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- The requested package phpunit/phpunit (locked at 5.7.19, required as 4.8.*) is satisfiable by phpunit/phpunit[5.7.19] but these conflict with your requirements or minimum-stability.
Problem 2
- Conclusion: don't install phpunit/phpunit 4.8.35
...
- Conclusion: don't install phpunit/phpunit 4.8.1
- phpunit/phpunit 4.8.0 conflicts with phpunit/phpunit-mock-objects[3.4.3].
...
- phpunit/phpunit 4.8.0 conflicts with phpunit/phpunit-mock-objects[3.4.3].
- Installation request for phpunit/phpunit 4.8.* -> satisfiable by phpunit/phpunit[4.8.0, 4.8.1, ..., 4.8.9].
- Installation request for phpunit/phpunit-mock-objects (locked at 3.4.3) -> satisfiable by phpunit/phpunit-mock-objects[3.4.3].


Installation failed, reverting ./composer.json to its original content.

最佳答案

在终端中输入

composer require laravel/browser-kit-testing --dev

然后在你的项目中使用下载的文件

use Tests\CreatesApplication;
use Laravel\BrowserKitTesting\TestCase as BaseTestCase;

并且不要忘记从 BaseTestCase 进行扩展。

示例代码

<?php

namespace Tests\Feature;

use Tests\CreatesApplication;
use Tests\TestCase;
use App\User;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Laravel\BrowserKitTesting\TestCase as BaseTestCase;

class UserTest extends BaseTestCase
{
use CreatesApplication;
public $baseUrl = 'http://localhost';
/**
* A basic test example.
*
* @return void
*/
public function testExample()
{


$this->visit('/home')
->seePageIs('/login');


}
}

关于unit-testing - phpunit laravel 5.4 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43778728/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com