我可以将phpunit.xml用于凭据,将phpunit.xml.dist用于测试套件吗? [英] Can I use phpunit.xml for credentials and phpunit.xml.dist for testsuites?

查看:119
本文介绍了我可以将phpunit.xml用于凭据,将phpunit.xml.dist用于测试套件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是在phpunit.xml中具有凭据,在phpunit.xml.dist中具有测试套件.这种设置的问题似乎是,每当添加测试时,每个开发人员都需要将其添加到自己的个人phpunit.xml中.为了解决这个问题,我的想法是让测试套件来自.dist版本.尽管尝试了许多不同的版本,但是我不确定自己缺少什么.这就是我想要做的

What I wanted to do was have credentials in the phpunit.xml and the test suites in phpunit.xml.dist. The problem with this setup seems to be that anytime a test is added every developer needs to add it to their own personal phpunit.xml. To get around this, my idea was to have the test suites come from the .dist version. Despite trying a lot of different versions, I'm not sure what I am missing. Here is what I am trying to do

<?xml version="1.0" encoding="UTF-8"?>
<phpunit
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
    xmlns:xi="http://www.w3.org/2001/XInclude"
    bootstrap="cfg/phpunit_autoload.php">
<php>
    <var name="DB_DSN" value="mysql:dbname=mysql;host=localhost;port=3306"/>
    <var name="DB_USER" value="root"/>
    <var name="DB_PASS" value="your_local_pass"/>
    <var name="DB_DEFAULTDB" value="mysql"/>        
</php>
<xi:include href="tests/phpunit.xml.dist" parse="xml" xpointer="test-suites">
    <xi:fallback>
        <testsuites id="test-suites">
            <testsuite name="MTD">
                <directory>tests/app/MTD</directory>
            </testsuite>
        </testsuites>
    </xi:fallback>
</xi:include>

这个想法是,当某人第一次上手时,他们会将.dist文件从/tests复制为.xml到根目录,并用其凭据替换.因此,不是将.dist和.xml放在同一个文件夹中的常规设置,我将在项目根目录下使用.xml文件,在/tests中使用.dist文件.由于它的设置方式,测试套件可能来自版本文件.这样一来,便增加了新的测试套件,每个人都会被它们吸引.将使用非版本化的.xml作为配置文件来运行测试,并且testsuites元素将从/tests文件夹中的版本化的.dist文件中包含.

The idea is that when someone was getting started for the first time they would copy the .dist file from /tests into root as .xml and replace with their credentials. So instead of the normal setup where .dist and .xml live in the same folder I would have the .xml file at project root and .dist in /tests. Because of the way it was set up, the test suites could come from the versioned file. That way was new testsuites were added, they would get pulled by everyone. Tests would be run using the non versioned .xml as the configuration files and the testsuites element would be included from the versioned .dist file in the /tests folder.

回退似乎并没有像我所想的那样起作用. xml解析似乎是从.xml文件获取到.dist文件的,但是它不会回退并返回id ="test-suites"元素,而是错误消息无法加载外部实体"文件:/{ my_path}/tests/tests/phpunit.xml.dist".

The fallback doesn't seem to work like I was thinking however. The xml parsing seems to get from the .xml file to the .dist file, but it doesn't fallback and return id="test-suites" element, instead the error message is "failed to load external entity "file:/{my_path}/tests/tests/phpunit.xml.dist".

文档中,我看不到为什么会回退不能工作.

I don't see from the documentation for fallback why it wouldn't be working.

推荐答案

我最终将phpunit.xml保留为版本文件,而不使用phpunit.xml.dist,并将凭据放入非版本化的phpunit中.我使用XInclude所指的creds.xml.然后,我使用版本化的phpunit.creds.xml.dist作为模板.

What I ended up doing keeping phpunit.xml as a versioned file, not using a phpunit.xml.dist, and putting credentials in a non-versioned phpunit.creds.xml which I refered to using XInclude. I then used a versioned phpunit.creds.xml.dist for a template.

这篇关于我可以将phpunit.xml用于凭据,将phpunit.xml.dist用于测试套件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆