3

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

edthix
  • 1,752
  • 16
  • 18

8 Answers8

6

Development on PHPSpec has restarted since August 2010, after a 2 years break. The code base looks more stable now. I would give another try.

The website is now located at www.phpspec.net

You can find the documentation at http://www.phpspec.net/documentation. It is basically an update of the first version.

Should you require any further assistance you can also reach the developers through their mailing list: http://groups.google.com/group/phpspec-dev

Marcello Duarte
  • 634
  • 6
  • 5
0

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
  • 1,166
  • 1
  • 15
  • 27
0

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

Wieczo
  • 455
  • 6
  • 11
0

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

edthix
  • 1,752
  • 16
  • 18
0

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

Bob Fanger
  • 28,949
  • 7
  • 62
  • 78
0

Hello its pretty old Q. in deed, but i think http://behat.org/ should be here. Everyone has this problem should check it out.

palmic
  • 1,846
  • 2
  • 20
  • 30
0

Note that PHPSpec is discontinued:

http://blog.astrumfutura.com/2010/05/the-mockery-php-mock-objects-made-simple/#comment-88628508

koen
  • 13,349
  • 10
  • 46
  • 51
  • 1
    I would like to add here that PHPSpec development has been restarted. Check http://www.phpspec.net/. – andho May 22 '11 at 02:57
0

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
  • 485
  • 2
  • 9