【问题标题】:PHPUnit_Framework_TestCase class is not available. Fix... - Makegood , EclipsePHPUnit_Framework_TestCase 类不可用。修复... - Makegood , Eclipse
【发布时间】:2016-03-11 23:12:09
【问题描述】:

我正在使用 OSX 10.11

我正在尝试使用 Eclipse 设置 PHPUnit、MAKEGood 和 Xdebug。

XDebug 完成。 我可以从控制台运行 PHPUnit 测试。

但现在配置 MakeGood 比我预期的要困难得多。

我的 PHP 可执行文件

我必须在Eclipse->Preferences->PHP->Libraries 中添加梨吗?我不确定,因为我使用 Brew 安装了 PHPUnit。

brew install homebrew/php/phpunit

但我再次尝试包含 PEAR。

我将路径设为usr/local/bin,因为当我在终端中尝试which pear 时,它将输出为

/usr/local/bin/pear

在我的 PHP-> 项目属性中包含路径,我添加了上面的 PEAR 库。

仍然来自Makegood,错误来自

PHPUnit_Framework_TestCase class is not available. Fix..

我尝试了很多东西,例如:-

reinstalling pear
rm .metadata/.plugins/org.eclipse.dltk.core.index.sql.h2/*
restart Eclipse
Restart Computer
change pear library path

实际上我不确定我做错了什么。即使我不确定我是否需要梨库。

感谢任何帮助。提前致谢。

【问题讨论】:

    标签: php eclipse phpunit xdebug makegood


    【解决方案1】:

    MakeGood 和 Composer 需要一些摆弄才能让它们工作,看看

    你可能想要

    1. 用 composer 安装 phpunit
    2. 在 MakeGood 配置中添加文件 MakeGoodPreload.php 作为您的预加载脚本。
    3. 添加phpunit.xml

    最近的 PHPUnit 版本可选用 composer 完成。

    首先安装作曲家:

    curl -sS https://getcomposer.org/installer | php
    

    https://phpunit.de/manual/current/en/installation.html

    然后安装phpunit

    php composer.phar require "phpunit/phpunit=4.8.*"
    

    现在从命令行测试

    vendor/phpunit/phpunit/phpunit.php test/MakeGoodTest.php
    

    使用下面的 MakeGoodTest.php 文件。 结果应该是:

    PHPUnit 4.8.21 by Sebastian Bergmann and contributors.
    Warning:    Deprecated configuration setting "strict" used
    
    .
    
    Time: 86 ms, Memory: 4.50Mb
    
    OK (1 test, 5 assertions)
    

    最近的 MakeGood 版本支持 composer 安装 phpunit 的用户。

    在您的 Eclipse 项目中创建一个项目“makegood”,其中包含您的 作曲家安装,test/MakeGoodTest.php,MakeGoodPreload.php 和 phpunit.xml。

    右键单击项目的属性并转到“MakeGood”选项卡。 在 PHPUnit 选项卡中添加 phpunit.xml 并在 General 选项卡中将 Preload Script 设置为 MakeGoodPreload.php。

    现在您应该可以在编辑器中打开 MakeGoodTest.php 并右键单击 得到“在课堂上运行测试......”。

    运行它应该给你:

    PHPUnit 4.8.21 by Sebastian Bergmann and contributors.
    Warning:    Deprecated configuration setting "strict" used
    
    .
    
    MakeGood
     [x] [32mPush and pop[39m
    
    Time: 192 ms, Memory: 8.75Mb
    
    OK (1 test, 5 assertions)
    

    phpunit.xml

    <phpunit backupGlobals="true"
             backupStaticAttributes="false"
             cacheTokens="false"
             colors="false"
             convertErrorsToExceptions="true"
             convertNoticesToExceptions="true"
             convertWarningsToExceptions="true"
             forceCoversAnnotation="false"
             mapTestClassNameToCoveredClassName="false"
             printerClass="PHPUnit_TextUI_ResultPrinter"
             processIsolation="false"
             stopOnError="false"
             stopOnFailure="false"
             stopOnIncomplete="false"
             stopOnSkipped="false"
             testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader"
             strict="false"
             verbose="false">
    </phpunit>
    

    MakeGoodPreload.php

    <?php
    // This is a preload script to be used with
    // the Eclipse makegood continuous integration plugin
    // see https://github.com/piece/makegood/releases
    error_reporting(E_ALL);
    $loader = require 'vendor/autoload.php';
    

    test/MakeGoodTest.php

    <?php
    class MakeGoodTest extends PHPUnit_Framework_TestCase
    {
        public function testPushAndPop()
        {
            $stack = array();
            $this->assertEquals(0, count($stack));
    
            array_push($stack, 'foo');
            $this->assertEquals('foo', $stack[count($stack)-1]);
            $this->assertEquals(1, count($stack));
    
            $this->assertEquals('foo', array_pop($stack));
            $this->assertEquals(0, count($stack));
        }
    }
    ?>
    

    【讨论】:

    • 非常感谢。我会试试这个:)
    猜你喜欢
    • 1970-01-01
    • 2014-04-17
    • 1970-01-01
    • 1970-01-01
    • 2017-08-06
    • 2012-03-14
    • 1970-01-01
    • 1970-01-01
    • 2018-06-05
    相关资源
    最近更新 更多