Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

RyanHavoc's avatar

PHPSpec not running

Hey,

I have a Laravel 5 build and am using Homestead. I have PHPSpec ~2.1 installed and /vendor/bin in my $PATH but when I try and run PHPSpec I get this:

$ phpspec
You must set up the project dependencies, run the following commands:
curl -s http://getcomposer.org/installer | php
php composer.phar install

I've run composer install and update and everything is up to date.

Does anyone know what this is happening?

0 likes
8 replies
RyanHavoc's avatar

So I've tracked down where the message is generated. By the actual /vendor/bin/phpspec file itself. The files looks like this:

#!/usr/bin/env php
<?php

define('PHPSPEC_VERSION', '2.1.1');


if (is_file($autoload = getcwd() . '/vendor/autoload.php')) {
    require $autoload;
} elseif (is_file($autoload = getcwd() . '/../../autoload.php')) {
    require $autoload;
}

if (is_file($autoload = __DIR__ . '/../vendor/autoload.php')) {
    require($autoload);
} elseif (is_file($autoload = __DIR__ . '/../../../autoload.php')) {
    require($autoload);
} else {
    fwrite(STDERR,
        'You must set up the project dependencies, run the following commands:' . PHP_EOL .
        'curl -s http://getcomposer.org/installer | php' . PHP_EOL .
        'php composer.phar install' . PHP_EOL
    );
    exit(1);
}

$app = new PhpSpec\Console\Application(PHPSPEC_VERSION);
$app->run();

This looks pretty odd to me. The first if/else finds my autoload then the send if/elseif/else doesn't so throws the error I'm seeing. If I comment out this section phpspec runs.

If it's checking lots of possible locations for the autoload.php why isn't it if/elseif/elseif/elseif/else. Why two separate ifs?

kikim792's avatar

@RyanHavoc I agree the structure of if/else does not make sense to me.

However, I have noticed that vendor/bin/phpspec used to be a symlink, phpspec -> ../phpspec/phpspec/bin/phpspec circa laravel 5.0.5, and it had worked.

At current version (5.0.23), vendor/bin/phpspec is a file with the same content of phpspec/phpspec/bin/phpspec, and is now broken. It is same situation for phpunit.

I am trying hard to understand TDD with laravel 5. I've watched most of the videos at http://laracasts.com/collections/testing-in-php and am still struggling to get the hang of it.

What I'd like to see is instruction video(s) showing how to properly use phpunit for testing laravel 5. Many of the details in the video collections are already outdated and are mostly for developers who are already seasoned with TDD.

From what I've got, there seems to be two kinds of tests, unit test and functional test. (I've also heard about integration test. It's perhaps similar to functional test?)

Jeffrey seems to favor phpspec over phpunit for unit test and recommends behat or codecept for functional test. However, it can be overwhelming for a beginner to have to learn various test suites. It seems to me that phpunit is capable of both unit and functional tests. I don't care much about sugary syntax at the moment (about phpspec reading better than phpunit). I am more interested in what can be done (and cannot) with the test suite.

msalom28's avatar

Try vendor/bin/phpspec in your terminal

1 like
RyanHavoc's avatar

@kikim792 With regards to the phpspec issue, are you using Homestead?

I had a long discussion with the devs on phpspec (who were really helpful) but it turned out that vendor/bin/phpspec should still be a symlink and we believe what was happened to me at least was that the file sync between my machine and homestead was turning into an actual file. I cleared out my vendor folder and deleted composer.lock, reinstalled everything and it was a symlink this time round and working for both phpspec and phpunit. Give it a try.

I know what you mean about getting your head around all the testing stuff. Just when I think I have a handle on it I watch a tutorial that covered a completely different test suite and I'm thrown again. Should I use that are this?

Even Jeffrey's Testing Jargon series (https://laracasts.com/series/testing-jargon) throws me a bit. He started with PHPUnit, then uses PHPSpec, then Codeception, then Behat... I'd have been ok if the Integration Testing tutorial was in PHPSpec as well but now I'm like, how do I do integration testing in PHPSpec then?

What really confuses me is Codeception looks to do everything from Acceptance to Unit. Obviously it just comes down to preference but I kind of just want to use the most commonly used thing and not have the "why the hell did you use that suite" conversation with other developers 2 years down the line. :-S

kikim792's avatar

@RyanHavoc I've read your comments at github trying to understand what's going on. I am not using homestead and just am using native LAMP stack on a mac.

I've just installed a fresh laravel ($ laravel new test-site) and it creates files (phpspec and phpunit) under vendor/bin instead of symlinks, and they don't work.

Testing Jargon series I think was supposed to cover the basics, but was harder than other videos and was the only one I had to skip for now :)

Appkr's avatar

Same here. So I just make a bash script on the project root to run vendor/phpspec/phpspec/bin/phpspec directly.

// cd path/to/laravel/project/root && touch phpspec && chmod 755 phpspec
#! /usr/bin/env sh
./vendor/phpspec/phpspec/bin/phpspec $1 $2

EDIT: As @kikim792 mentioned, it always happen, when you intstall laravel using laravel installer ($ laravel new myApp). The solution is simple: reinstalling phpspec. $ composer remove phpspec/phpspec and then composer require phpspec/phpspec --dev.

3 likes

Please or to participate in this conversation.