【问题标题】:Configuring Laravel 5 Unit Test URL with phpunit.xml使用 phpunit.xml 配置 Laravel 5 单元测试 URL
【发布时间】:2016-05-10 16:35:07
【问题描述】:

我已经运行了很多测试,但是其中一个路由生成 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>

有什么帮助吗?打赌这是愚蠢的事情!

谢谢

【问题讨论】:

标签: php laravel-5 phpunit


【解决方案1】:

/tests/TestCase.php

更改 $baseUrl 值。

/**
 * The base URL to use while testing the application.
 *
 * @var string
 */
protected $baseUrl = 'http://my-local-domain.dev';

【讨论】:

    【解决方案2】:

    更改测试目录根目录下TestCase 类中的$baseUrl 值。 这里提供了样本。所有其他值都将被此屏蔽。

    abstract class TestCase extends Illuminate\Foundation\Testing\TestCase
    {
        /**
         * The base URL to use while testing the application.
         *
         * @var string
         */
        protected $baseUrl = 'http://local.dev:8888';
    
        /**
         * Creates the application.
         *
         * @return \Illuminate\Foundation\Application
         */
        public function createApplication()
        {
    
        }
    
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-16
      • 2016-10-18
      • 2015-06-19
      • 1970-01-01
      • 2015-06-12
      • 1970-01-01
      • 2015-02-10
      相关资源
      最近更新 更多