【问题标题】:Jenkins: phpunit with namespaces in Yii-FrameworkJenkins:在 Yii-Framework 中带有命名空间的 phpunit
【发布时间】:2013-11-24 15:46:24
【问题描述】:

我是詹金斯的新手。我尝试在website 上使用 ci。如果我构建我的项目,我会收到以下控制台输出错误

phpunit:
 [exec] PHPUnit 3.7.28 by Sebastian Bergmann.
 [exec] 
 [exec] Cannot open file "/var/www/repo/project/protected/tests/bootstrap.php".
 [exec] 

BUILD FAILED
 /var/www/repo/build.xml:117: exec returned: 1

我的 build.xml

<target name="phpunit" description="Run unit tests with PHPUnit">
  <exec executable="phpunit" failonerror="true">
     <arg line="--log-junit ${basedir}/build/logs/phpunit.xml /var/www/repo/project/protected/" />
 </exec>
 </target>

我的项目结构是这样的:

-repo
  -project
    -protected
      -components
      -config
      - ....
      - tests
         - unit
         - bootstrap.php
         - ReflectionTest.php
  -build
    -....
  -build.xml
  -phpunit.xml.dist

我正在使用带有命名空间的 Yii 框架。如果我从测试目录执行 phpunit 命令,它工作得很好。但是如果我在其他地方执行它,我会收到这样的错误:

PHP Fatal error:  Class 'application\tests\ReflectionTest' not found in /var/www/repo/project/protected/tests/unit/account/manager/ManagerTest.php on line 13

这是我的测试:

<?php

namespace application\tests\unit\account\manager;

use application\modules\account\manager\Manager;
use application\models;
use Yii;
use application\tests\ReflectionTest;

/**
 * This class test the protected and public methods of SignupManager
 */
class ManagerTest extends ReflectionTest {

这里是我的 phpunit.xml.dist

<phpunit bootstrap="project/protected/tests/bootstrap.php"
        colors="false"
        convertErrorsToExceptions="true"
        convertNoticesToExceptions="true"
        convertWarningsToExceptions="true"
        stopOnFailure="false">

    <selenium>
        <browser name="Internet Explorer" browser="*iexplore" />
        <browser name="Firefox" browser="*firefox" />
    </selenium>

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

</phpunit>

我的错误在哪里?

【问题讨论】:

    标签: yii jenkins namespaces continuous-integration phpunit


    【解决方案1】:

    我使用 phpunit.xml 文件所在位置的相对路径来引用我的引导文件。像这样:

    <phpunit bootstrap="bootstrap.php"
        colors="false"
        convertErrorsToExceptions="true"
        convertNoticesToExceptions="true"
        convertWarningsToExceptions="true"
        stopOnFailure="false">
    

    【讨论】:

    • 这是相对路径。绝对路径是这样的 /var/www/repo/project/protected/tests/bootstrap.php
    【解决方案2】:

    我在 github 上为 Yii 创建了一个示例项目。在那里你可以看到 phpunit 的设置应该如何正常工作。查看https://github.com/perlmonkey/yii-sample-project

    此外,您必须注意所有相关的 PHPUnit 模块都可用于测试。这就是为什么我创建了一个自动化脚本来为我配置 Jenkins:https://github.com/perlmonkey/php-ci

    【讨论】:

      猜你喜欢
      • 2010-11-18
      • 2011-11-14
      • 2018-07-29
      • 2011-12-30
      • 2015-12-12
      • 2018-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多