probedock/probedock-phpunit

PHPUnit 检测器,用于将测试结果发布到 Probe Dock。

v0.2.3 2016-07-08 08:31 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:53:12 UTC


README

PHPUnit 监听器,用于将测试结果发布到 Probe Dock

设置

在您的 composer.json 文件中将 probedock-phpunit 添加为依赖项

{
  "name": "my/package",
  "require": {
    "probedock/probedock-phpunit": "^0.2.0"
  }
}

然后运行 php composer.phar update

如果您尚未这样做,请设置您的 Probe Dock 配置文件。该过程在此处描述

然后,您必须将 Probe Dock PHPUnit 监听器添加到您的 PHPUnit 配置文件中(例如 phpunit.xml.dist)。您必须添加以下监听器

<listener class="ProbeDock\ProbeDockPHPUnit\ProbeDockPHPUnitListener">
  <arguments>
  </arguments>
</listener>

以下是一个来自 Symfony 项目的完整 phpunit.xml.dist 配置文件示例,显示了添加监听器的地方(在底部)

<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
         backupGlobals="false"
         colors="true"
         bootstrap="app/autoload.php">

  <php>
    <ini name="error_reporting" value="-1" />
    <server name="KERNEL_DIR" value="app/" />
  </php>

  <testsuites>
    <testsuite name="Project Test Suite">
      <directory>tests</directory>
    </testsuite>
  </testsuites>

  <filter>
    <whitelist>
      <directory>src</directory>
      <exclude>
        <directory>src/*Bundle/Resources</directory>
        <directory>src/*/*Bundle/Resources</directory>
        <directory>src/*/Bundle/*Bundle/Resources</directory>
      </exclude>
    </whitelist>
  </filter>

  <listeners>
    <listener class="ProbeDock\ProbeDockPHPUnit\ProbeDockPHPUnitListener">
      <arguments>
      </arguments>
    </listener>
  </listeners>
</phpunit>

所有测试结果现在将在您下次运行测试套件时发布到 Probe Dock!

使用方法

要丰富测试信息,您可以使用 @ProbeDock 注解

<?php

namespace Tests\AppBundle\Controller;

use ProbeDock\ProbeDockPHPUnit\ProbeDock;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class DefaultControllerTest extends WebTestCase {

  /**
   * @ProbeDock(name="Custom name different than the function name", category="Web Test", tags="api,http,get")
   */
  public function testIndex() {
    $client = static::createClient();

    $crawler = $client->request('GET', '/');

    $this->assertEquals(200, $client->getResponse()->getStatusCode());
    $this->assertContains('Welcome to Symfony', $crawler->filter('#container h1')->text());
  }
}

故障排除

AnnotationException: 注解从未导入

此库使用 Doctrine 注解,因此您可以使用标签等额外信息丰富测试

如果您使用其他注解,它们可能与 Doctrine 注解库发生冲突。例如,在测试中使用 @expectedException 注解的项目中可能会出现此错误

Uncaught Doctrine\Common\Annotations\AnnotationException: [Semantical Error] The annotation "@expectedException" in method My\Class::testMethod() was never imported. Did you maybe forget to add a "use" statement for this annotation?

要解决这个问题,您必须将 Doctrine 未知注解添加到其全局忽略列表中。以下是在测试的引导文件中的代码

namespace Doctrine\Common\Annotations {
  require __DIR__ . '/../vendor/autoload.php';
  use Doctrine\Common\Annotations\AnnotationReader;

  AnnotationReader::addGlobalIgnoredName('expectedException');
  // Repeat the line above to ignore other annotations...
}

如果您还没有为测试创建引导文件,您可以创建它并将其路径添加到 phpunit.xml.dist 配置文件中的 <phpunit> 标签中

<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./tests/bootstrap.php" colors="true">
  <!-- Your PHPUnit configuration... -->
</phpunit>

贡献

  • 分支
  • 创建一个主题分支 - git checkout -b feature
  • 将您的分支推送到远程 - git push origin feature
  • 从您的分支创建一个 pull request

请添加带有您姓名的新功能和错误修复的更改日志条目。

贡献者

许可证

probedock-phpunitMIT 许可证 下授权。请参阅 LICENSE.txt 以获取完整文本。