PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse

試著忘記壹切 提交于 2020-01-24 12:47:47

问题


I am working in OSX 10.11

I am trying to setup PHPUnit , MAKEGood and Xdebug with Eclipse .

XDebug is Done . I can Run PHPUnit tests form the console .

But now configuring MakeGood is lot more harder than i expected .

MY PHP Executables

Do i have to add pear in Eclipse->Preferences->PHP->Libraries ?? i am not sure because i installed PHPUnit using Brew.

brew install homebrew/php/phpunit

But again i tried to include PEAR .

I gave the path as usr/local/bin because when i try which pear in terminal it will output as

/usr/local/bin/pear

And in my project properties under PHP-> include path i added the above PEAR library .

still from Makegood the error comes as

PHPUnit_Framework_TestCase class is not available. Fix..

I tried a lot of things , Ex:-

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

Actually i am not sure what i am doing wrong . Even i am not sure i need the pear library .

Any help is appreciated . Thanks in advance .


回答1:


MakeGood and Composer need some fiddling to get them to work see

  • https://github.com/piece/makegood/issues/17
  • https://github.com/piece/makegood/issues/85

You might want to

  1. install phpunit with composer
  2. add a file MakeGoodPreload.php as your Preload Script in the MakeGood configuration.
  3. add phpunit.xml

More recent PHPUnit releases are optionally done with composer.

First install composer:

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

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

then install phpunit

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

now test from the command line

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

using the MakeGoodTest.php file below. The result should be:

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)

Recent MakeGood releases support the user of the composer installed phpunit.

In your Eclipse project create a project "makegood" that contains your composer installation, test/MakeGoodTest.php, MakeGoodPreload.php and phpunit.xml.

Right click properties of the project and go to the "MakeGood" tab. in the PHPUnit tab add phpunit.xml and in the General Tab set the Preload Script to MakeGoodPreload.php.

Now you should be able to open MakeGoodTest.php in the editor and right click to get "Run Tests in class ...".

running it should give you:

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));
    }
}
?>


来源:https://stackoverflow.com/questions/34132063/phpunit-framework-testcase-class-is-not-available-fix-makegood-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!