Search code examples
phpphpunitphpactiverecord

run phpunit of php-activerecord failed


I am trying to test php-activerecord, it has some tests. When run:

phpunit sometestname

nothing happened. I checked the code,

include 'helpers/config.php';

require_once dirname(__FILE__) . '/../lib/Inflector.php';

class InflectorTest extends SnakeCase_PHPUnit_Framework_TestCase

{
    public function set_up()
    {
        $this->inflector = ActiveRecord\Inflector::instance();
    }

    public function testOne()
    {
        $this->assertTrue(2+2==4);
    }

Any idea?

enter image description here


Solution

  • Your PHPUnit version is a bit outdated. Let's make sure you are current. Please do

    pear channel-discover pear.phpunit.de
    pear channel-discover components.ez.no
    pear channel-discover pear.symfony-project.com
    

    and then

    pear install --force --alldeps phpunit/PHPUnit again
    

    this should result in

    downloading PHPUnit-3.5.13.tgz ...
    Starting to download PHPUnit-3.5.13.tgz (118,553 bytes)
    ..........................done: 118,553 bytes
    install ok: channel://pear.phpunit.de/PHPUnit-3.5.13
    

    If there is any errors try upgrade your PEAR version to the current version with

    pear upgrade-all
    

    The DocBlock for the test helper of PHPActiveRecord says

    /**
    * In order to run these unit tests, you need to install:
    * - PHPUnit
    * - PEAR Log (otherwise logging SQL queries will be disabled)
    * - Memcache (otherwise Caching tests will not be executed)
    *
    * To run all tests : phpunit AllTests.php --slow-tests
    * To run a specific test : phpunit ????Test.php
    */
    

    but there is two suppressed includes in it for the Log dependency

    @include_once 'Log.php';
    @include_once 'Log/file.php';
    

    which could be the reason why you are not getting any result on CLI at all, so make sure you also do

    pear install --force --alldeps Log
    

    That should work then.

    EDIT: the 1.0 Version that is available from the PHPActiveRecord Website does not have the above DocBlock and uses require_once for the Log dependency. This is changed in the current master version, so you might want to try the nightly or check out the master branch from GitHub: