我目前正在Laravel 5.5新开发安装上尝试单元测试。并使用https://github.com/laracasts/Integrated
安装了扩展程序这是我的TestCase.php
<?php
namespace Tests;
use Laracasts\Integrated\Extensions\Laravel as IntegrationTest;
abstract class TestCase extends IntegrationTest
{
use CreatesApplication;
}
这是我运行phpunit时得到的错误
Fatal error: Access level to Laracasts\Integrated\Extensions\Traits\LaravelTestCase::get() must be public (as in class Illuminate\Foundation\Testing\TestCase)
在第9行的C:\ xampp2 \ htdocs \ laradev \ vendor \ laracasts \ integrated \ src \ Extensions \ Laravel.php
Call Stack:
0.0010 348128 1. {main}() C:\xampp2\htdocs\laradev\vendor\phpunit\phpunit\phpunit:0
PHP 13. Composer\Autoload\ClassLoader->loadClass() C:\xampp2\htdocs\laradev\tests\Feature\ExampleTest.php:8
0.0550 1862640 2. PHPUnit\TextUI\Command::main() C:\xampp2\htdocs\laradev\vendor\phpunit\phpunit\phpunit:53
PHP 14. Composer\Autoload\includeFile() C:\xampp2\htdocs\laradev\vendor\composer\ClassLoader.php:322
PHP 15. include() C:\xampp2\htdocs\laradev\vendor\composer\ClassLoader.php:444
0.0550 1867200 3. PHPUnit\TextUI\Command->run() C:\xampp2\htdocs\laradev\vendor\phpunit\phpunit\src\TextUI\Command.php:148
PHP 16. spl_autoload_call() C:\xampp2\htdocs\laradev\tests\TestCase.php:7
0.0550 1867200 4. PHPUnit\TextUI\Command->handleArguments() C:\xampp2\htdocs\laradev\vendor\phpunit\phpunit\src\TextUI\Command.php:159
PHP 17. Composer\Autoload\ClassLoader->loadClass() C:\xampp2\htdocs\laradev\tests\TestCase.php:7
0.0670 2190488 5. PHPUnit\Util\Configuration->getTestSuiteConfiguration() C:\xampp2\htdocs\laradev\vendor\phpunit\phpunit\src\TextUI\Command.php:771
PHP 18. Composer\Autoload\includeFile() C:\xampp2\htdocs\laradev\vendor\composer\ClassLoader.php:322
PHP 19. include() C:\xampp2\htdocs\laradev\vendor\composer\ClassLoader.php:444
请问如何解决此问题,因为我无法使用visit(),see()和type()方法
答案 0 :(得分:1)
如github上所述,大部分内容都集成在Laravel Core中。
请参阅Laravel 5.5 Http Tests,如果您需要更多内容,可以使用Browser kit testing,或者如果您希望浏览器测试使用Laravel Dusk。
答案 1 :(得分:0)
您可以使用浏览器测试(Laravel Dusk),正如Bostjan在https://laravel.com/docs/5.5/dusk所说。
它支持与元素的各种交互,包括点击链接,使用表单,附加文件,键盘/鼠标操作等等。
这是Dusk文档的一个例子
<?php
namespace Tests\Browser;
use App\User;
use Tests\DuskTestCase;
use Laravel\Dusk\Chrome;
use Illuminate\Foundation\Testing\DatabaseMigrations;
class ExampleTest extends DuskTestCase
{
use DatabaseMigrations;
/**
* A basic browser test example.
*
* @return void
*/
public function testBasicExample()
{
$user = factory(User::class)->create([
'email' => 'taylor@laravel.com',
]);
$this->browse(function ($browser) use ($user) {
$browser->visit('/login')
->type('email', $user->email)
->type('password', 'secret')
->press('Login')
->assertPathIs('/home');
});
}
}