[英]Laravel Unit testing Routes
My test method has: 我的测试方法有:
$this->visitRoute('route.name')->see('something');
Response: 响应:
There was 1 failure:
1) Tests\Unit\MyTest::testRoute
A request to [http://localhost/route.name] failed. Received status code [500].
Caused by
PDOException: SQLSTATE[HY000]: General error: 1 no such table 'tableThatExists'
BUT when I test: 但是当我测试时:
$this->visit('/')
As provided in Laravel documentation, it works, what is wrong?? 正如Laravel文档中提供的那样,它可以正常工作,这是怎么回事?
And also if I just want to test responses without "see" condition how do I do it? 而且,如果我只想测试响应而没有“看到”条件,该怎么办?
If anybody knows simple basic laravel unit tests it could help as well 如果有人知道简单的基本laravel单元测试,它也会有所帮助
use Illuminate\Foundation\Testing\DatabaseMigrations;
in file and 在文件中
use DatabaseMigrations;
in class 在班上
This error is because the app test is not finding the database. 该错误是因为应用测试未找到数据库。
Try with: 尝试:
Into phpunit.xml
inside php
tag you need to set a testing database like this 在
php
标记内的phpunit.xml
您需要设置一个这样的测试数据库
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
</php>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.