我已经运行了很多测试,但有一次,路由生成url的测试一直失败。
经过检查,它看起来像是在使用默认的APP_URL。
我已经在phpunit.xml中更改了它,但它没有任何区别(即使在清除缓存后)
phpunit.xml:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="bootstrap/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<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="APP_URL" value="http://local.dev:8888"/>
<ini name="display_errors" value="true"/>
</php>
</phpunit>
有什么帮助吗?我打赌这是愚蠢的事!
感谢
在/tests/TestCase.php
中
更改$baseUrl值。
/**
* The base URL to use while testing the application.
*
* @var string
*/
protected $baseUrl = 'http://my-local-domain.dev';
更改测试目录根目录中TestCase类中的$baseUrl值。此处提供样品。所有其他值都将被此屏蔽。
abstract class TestCase extends IlluminateFoundationTestingTestCase
{
/**
* The base URL to use while testing the application.
*
* @var string
*/
protected $baseUrl = 'http://local.dev:8888';
/**
* Creates the application.
*
* @return IlluminateFoundationApplication
*/
public function createApplication()
{
}
}