小编Bru*_*rel的帖子

PHPUnit的白名单和黑名单似乎被忽略了

我在一个项目上设置PHPUnit,其结构如下:

- build
- src
    - service # PHP source code files here
- tests
    - php
        - unit # PHP unit tests here
            - bootstrap.php # PHP unit tests here
            - services
                - MyTest.php
                - ...
- vendor
Run Code Online (Sandbox Code Playgroud)

我创建了以下PHPUnit配置文件,该文件位于项目的根目录:

<phpunit
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.4/phpunit.xsd"
    bootstrap="tests/php/unit/bootstrap.php"
    verbose="true">

    <testsuites>
        <testsuite name="services">
            <directory>tests/php/unit/services</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist>
            <directory>src/service</directory>
        </whitelist>
    </filter>

    <logging>
        <log type="coverage-html" target="build/php/coverage"/>
        <log type="coverage-clover" target="build/php/coverage.xml"/>
        <log type="junit" target="build/php/test-results.xml"/>
    </logging>
</phpunit>
Run Code Online (Sandbox Code Playgroud)

我想使用白名单,以便PHPUnit不测试项目外的PHP文件,例如vendor目录中的那些......但是看一下代码覆盖率报告,似乎没有考虑白名单:

代码覆盖率

正如在捕获中所看到的那样tests,vendor被写为0%被覆盖,尽管它们不应被分析,因为它们不属于白名单.目录的"2%文件" src对应于我编写的唯一测试,因此代码覆盖率似乎正确.

如何才能src/service …

php phpunit whitelist

7
推荐指数
1
解决办法
7994
查看次数

使用 Mongo Native Query 解析 MongoDB DBRef 数组并处理解析的文档

我的 MongoDB 集合由 2 个主要集合组成:

1) 地图

{
"_id" : ObjectId("542489232436657966204394"),
"fileName" : "importFile1.json",
"territories" : [ 
    {
        "$ref" : "territories",
        "$id" : ObjectId("5424892224366579662042e9")
    }, 
    {
        "$ref" : "territories",
        "$id" : ObjectId("5424892224366579662042ea")
    }
]
},

{
    "_id" : ObjectId("542489262436657966204398"),
    "fileName" : "importFile2.json",
    "territories" : [ 
        {
            "$ref" : "territories",
            "$id" : ObjectId("542489232436657966204395")
        }
    ],
    "uploadDate" : ISODate("2012-08-22T09:06:40.000Z")
}
Run Code Online (Sandbox Code Playgroud)

2)在“地图”对象中引用的领土:

{
    "_id" : ObjectId("5424892224366579662042e9"),
    "name" : "Afghanistan",
    "area" : 653958
},
{
    "_id" : ObjectId("5424892224366579662042ea"),
    "name" : "Angola",
    "area" : 1252651 …
Run Code Online (Sandbox Code Playgroud)

mongodb aggregation-framework

5
推荐指数
1
解决办法
4510
查看次数

在Perl中编码哈希数组

我正在尝试做一些看似非常简单的事情,但我无法弄清楚如何在Perl中做到这一点:我想输出一个JSON格式的哈希数组.

有问题的哈希数组实际上是一个DBIx::MyParse Items对象实例的数组.这是我的代码:

use strict;
use DBIx::MyParse;
use JSON::PP;
my $json = JSON::PP->new->ascii->pretty->allow_nonref;

our $parser = DBIx::MyParse->new( database => "test", datadir => "/tmp/myparse" );
our $query = $parser->parse("UPDATE table1 SET field1 = 1;");

$json->convert_blessed(1);
print $json->encode(@{$query} );
Run Code Online (Sandbox Code Playgroud)

这就是这个脚本输出的内容:

"SQLCOM_UPDATE"
Run Code Online (Sandbox Code Playgroud)

这实际上是我想要作为一个整体输出的数组的第一个元素.以下是我逐步调试脚本时看到的数组内容: 查询调试值

我想在我的JSON输出中拥有整个结构.我怎样才能做到这一点?

perl hash json

1
推荐指数
1
解决办法
218
查看次数

标签 统计

aggregation-framework ×1

hash ×1

json ×1

mongodb ×1

perl ×1

php ×1

phpunit ×1

whitelist ×1