1

I'm developing a HTTP server and for the first time I've decided to write the tests specs with PHPSpec, which is great.

I have two spec classes: spec\AppSpec and spec\RequestParserSpec.

Since the App is the interface between the server components and the outer world, it uses the RequestParser to parse the requests. So, in order to get the specs in AppSpec passing, the RequestParserSpec has to be ran before to check if the request parsing is working fine.

Here is the problem : $ phpspec run runs before AppSpec and then RequestParserSpec.

Is it possible to inverse that order? Presently, if RequestParser has a problem, AppSpec will fail without telling what's the root problem.

Yes, I know I can do phpspec run tests/spec/RequestParserSpec.php, then the others, but it would be more practical if this could be automated to run the tests in one pass.

suites:
    myapp_suite:
        namespace: MyApp
        psr4_prefix: MyApp
        spec_path: tests
Morgan Touverey Quilling
  • 4,181
  • 4
  • 29
  • 41
  • Can you please update question with the code for both classes and both specs? – gvf Jul 12 '15 at 12:52
  • Here are the specs : http://pastebin.com/5jQk5Rms and http://pastebin.com/7nTJ3VbE. Why are you interested in the sources? – Morgan Touverey Quilling Jul 12 '15 at 16:43
  • Sorry, I see that Pastebin have broken my indentation on AppSpec, some lines are shifted... – Morgan Touverey Quilling Jul 12 '15 at 16:45
  • 1
    To try and help you on how to spec them. Requiring a spec to run before another one means that you're probably not mocking/stubbing `RequestParser`. – gvf Jul 12 '15 at 17:12
  • Oh yes, that's perfectly true. This is the very first time I write tests so I'm not used to the different existing techniques and practices. `RequestParser` is an `EventEmitter` (mocking cannot handle this) and the code isn't built in a way that let me easily mimic a mocking (via calling directly `emit()` on the `RequestParser` for example.). What do you think about this code? http://pastebin.com/iZcDMkd6 – Morgan Touverey Quilling Jul 12 '15 at 18:21

1 Answers1

1

You could substitute

$parser = new RequestParser(clone $this->baseRequest);

with this:

$parser = $this->requestParserFactory->createFromBaseRequest(clone $this->baseRequest);

then inject a RequestParserFactory, and you can then mock it in the spec.

gvf
  • 1,039
  • 7
  • 6