概述 快速入门 教程 手册 最佳实践 组件 参考 贡献

发布于 2015-08-27 16:45:37 | 103 次阅读 | 评论: 0 | 来源: 网络整理

Sometimes when running tests, you need to do additional bootstrap work before running those tests. For example, if you’re running a functional test and have introduced a new translation resource, then you will need to clear your cache before running those tests. This cookbook covers how to do that.

First, add the following file:

// app/tests.bootstrap.php
if (isset($_ENV['BOOTSTRAP_CLEAR_CACHE_ENV'])) {
    passthru(sprintf(
        'php "%s/console" cache:clear --env=%s --no-warmup',
        __DIR__,
        $_ENV['BOOTSTRAP_CLEAR_CACHE_ENV']
    ));
}

require __DIR__.'/bootstrap.php.cache';

Replace the test bootstrap file bootstrap.php.cache in app/phpunit.xml.dist with tests.bootstrap.php:

<!-- app/phpunit.xml.dist -->

<!-- ... -->
<phpunit
    ...
    bootstrap = "tests.bootstrap.php"
>

Now, you can define in your phpunit.xml.dist file which environment you want the cache to be cleared:

<!-- app/phpunit.xml.dist -->
<php>
    <env name="BOOTSTRAP_CLEAR_CACHE_ENV" value="test"/>
</php>

This now becomes an environment variable (i.e. $_ENV) that’s available in the custom bootstrap file (tests.bootstrap.php).

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务