1

I have installed phpspec through composer within codebase root by doing composer require phpspec/phpspec. I wanted to run it without prefixing it each time with vendor/bin, but I also didn't want to add that to PATH, so I installed it globally first with composer global require phpspec/phpspec (both versions are the same) and added to path with export PATH=$PATH:~/.composer/vendor/bin (I am on MacOS Catalina).

Now I can run phpspec from the codebase root, and it does indeed run. I can run phpspec describe xxx which does create a file and works, however doing a phpspec run fails miserably:

✘ Fatal error happened while executing the following

    Uncaught TypeError: Argument 2 passed to Symfony\Component\EventDispatcher\EventDispatcher::dispatch() must be an instance of Symfony\Component\EventDispatcher\Event or null, string given, called in /Users/.../.composer/vendor/phpspec/phpspec/src/PhpSpec/Util/DispatchTrait.php on line 22 and defined in /Users/.../.composer/vendor/symfony/event-dispatcher/EventDispatcher.php:37
Stack trace:
#0 /Users/.../.composer/vendor/phpspec/phpspec/src/PhpSpec/Util/DispatchTrait.php(22): Symfony\Component\EventDispatcher\EventDispatcher->dispatch(Object(PhpSpec\Event\SuiteEvent), 'beforeSuite')
#1 /Users/.../.composer/vendor/phpspec/phpspec/src/PhpSpec/Runner/SuiteRunner.php(52): PhpSpec\Runner\SuiteRunner->dispatch(Object(Symfony\Component\EventDispatcher\EventDispatcher), Object(PhpSpec\Event\SuiteEvent), 'beforeSuite')
#2 /Users/.../.composer/vendor/phpspec/phpspec/src/PhpSpec/Console/Command/RunCommand.php(178): PhpSpec\Runner\SuiteRunner->run(Object(PhpSpec\Loader\Suite))
#3 /Users/.../.composer/ven in /Users/.../.composer/vendor/symfony/event-dispatcher/EventDispatcher.php on line 37

However running vendor/bin/phpspec run goes through fine.

What might be the error here?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Norgul
  • 4,613
  • 13
  • 61
  • 144
  • What makes you think that `phpspec` and `vendor/bin/phpspec` point to the same instance? – Nico Haase Feb 25 '20 at 09:21
  • Additionally, there is a bug report at https://github.com/phpspec/phpspec/issues/1294 which matches the given error – Nico Haase Feb 25 '20 at 09:21
  • I never said they point to same instance. Obviously those are 2 separate dependencies (but same version nevertheless). I'm baffled as to why the same code behaves differently depending on location – Norgul Feb 25 '20 at 11:57
  • Maybe, the vendor version pulls in more stuff from the rest of your application, such that even the exact same version of phpspec uses different depending packages? – Nico Haase Feb 25 '20 at 12:40
  • My "app" is literally a composer file with phpspec dependency. Even with that in mind it is strange how `describe` option does work in both cases though – Norgul Feb 25 '20 at 13:03
  • I have the same problem. Thanks for asking the question. – John Walker May 15 '20 at 15:18

0 Answers0