tags:

views:

352

answers:

5

Searched stackoverflow for this and found no answer

Coming from Ruby On Rails and Rspec, I need a tool like rspec (easier transition). Installed it through PEAR and tried to run it but it's not working (yet)

Just wanna ask around if anyone's using it have the same problem, since it's not running at all

tried running it with an example from the manual - http://dev.phpspec.org/manual/en/before.writing.code.specify.its.required.behaviour.html

phpspec NewFileSystemLoggerSpec

returns nothing

even running

phpspec some_dummy_value

returns nothing

A: 

I also couldn't get it to run, but you can also use BDD with PHPUnit. Check the documentation:

wieczo
A: 

Was really looking forward to using PHPSpec, oh I guess will check into PHPUnit

Ed
+1  A: 

I tried using phpspec but found it too buggy/immature. I can highly recommend SimpleTest for writing unittests.

Bob Fanger
Yeah, I like SimpleTest too - but I think it is a good "starter" testing suite, where PHPUnit is the evolution (supported by IDEs and more).
Matt Refghi
SimpleTest's latest release was 2008/04/08
andho
A: 

You can write RSpec-ish types of tests in PHPUnit, but it's hindered by a couple of things.

  • PHPUnit mocks don't let you re-declare them so it's hard to set up a bunch of stubs in a before method and then override them as needed. You can work around this by arranging for the stubs to be setup after the expectations, but it's odd.

  • PHP isn't as dynamic as Ruby so you can't easily mock or stub out class methods unless you specifically design the class for this and even then it's pretty ugly. (This may change with PHP 5.3's late static binding features).

_Kevin
A: 

I have used PHPSpec succesfully but it's not actively developed now is it? It's great but don't think I would go with a stalled project. Anyway to the point I used the following setup to run the tests from the webbrowser, maybe you'll find something to help you to set it up for CLI.

PHPSpecConfiguration.php

$projectDir = realpath( dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' ) . DIRECTORY_SEPARATOR;

$simdal_root = $projectDir . 'library';
$phpspec_root = $projectDir . '..' . DIRECTORY_SEPARATOR . 'PHPSpec';
$mockery_root = $projectDir . '..' . DIRECTORY_SEPARATOR . 'Mockery';

$paths = array(
    'SimDAL'=>$simdal_root,
    'PHPSpec'=>$phpspec_root,
    'Mockery'=>$mockery_root
);

set_include_path( implode( PATH_SEPARATOR, $paths ) . PATH_SEPARATOR . get_include_path() );

require_once 'PHPSpec.php';
require_once 'Mockery/Framework.php';

class Custom_Autoload
{
    public static function autoload($class)
    {
        //$path = dirname(dirname(__FILE__));
        //include $path . '/' . str_replace('_', '/', $class) . '.php';
        if (preg_match('/^([^ _]*)?(_[^ _]*)*$/', $class, $matches)) {
            include str_replace('_', '/', $class) . '.php';
            return true;
        }

        return false;
    }

}

spl_autoload_register(array('Custom_Autoload', 'autoload'));

and then the file that runs it all: AllSpecs.php;

require_once 'PHPSpecTestConfiguration.php';

$options = new stdClass();
$options->recursive = true;
$options->specdocs = true;
$options->reporter = 'html';

PHPSpec_Runner::run($options);

I don't like CLI testing...But this might help someone.

andho