$child->addTest($grandchild); $this->suite->addTest($child); $count = 0; $this->eventEmitter->on('suite.end', function () use(&$count) { $count++; }); $this->runner->run(new TestResult($this->eventEmitter)); assert(3 == $count, "expected 3 suite:end events to fire"); }); context("when configured to bail on failure", function () { it("should stop running on failure", function () { $suite = new Suite("suite", function () { }); $passing = new Test("passing spec", function () { }); $suite->addTest($passing); $childSuite = new Suite("child suite", function () { }); $passingChild = new Test("passing child", function () { }); $failingChild = new Test("failing child", function () { throw new Exception("booo"); }); $passing2Child = new Test("passing2 child", function () { }); $childSuite->addTest($passingChild); $childSuite->addTest($failingChild); $childSuite->addTest($passing2Child); $suite->addTest($childSuite); $passing2 = new Test("passing2 spec", function () { });
$suite = new Suite("Suite", function () { }); $suite->setEventEmitter($this->eventEmitter); $suite->addTest(new Test("this was run", function () { })); $suite->addTest(new Test("this was also run", function () { })); $suite->run($result); assert($result->getTestCount() === 2, "two specs should have run"); }); it("should return the number of tests failed", function () { $result = new TestResult($this->eventEmitter); $suite = new Suite("Suite", function () { }); $suite->setEventEmitter($this->eventEmitter); $suite->addTest(new Test("this was run", function () { })); $suite->addTest(new Test("this was also run", function () { })); $suite->addTest(new Test("this failed", function () { throw new Exception('spec failed'); })); $suite->run($result); assert($result->getFailureCount() === 1, "one specs should have failed"); }); describe('->startTest()', function () { beforeEach(function () { $this->eventEmitter = new EventEmitter(); $this->result = new TestResult($this->eventEmitter); }); it('should increment the test count', function () { $this->result->startTest(new Test('some test'));
}); $test->run(new TestResult($emitter)); assert($count == 1, "should not have emitted a pass and fail event"); }); }); }); describe("->getTitle()", function () { it("should return the full text for a spec including parents", function () { $root = new Suite("parent", function () { }); $child = new Suite("nested", function () { }); $test = new Test("should be rad", function () { }); $child->addTest($test); $root->addTest($child); assert($test->getTitle() == "parent nested should be rad", "title should include text from parents"); }); }); describe('->setPending()', function () { it('should set the pending status', function () { $test = new Test("spec", function () { }); assert(is_null($test->getPending()), "spec pending should be null by default"); $test->setPending(true); assert($test->getPending(), "spec should be pending"); }); }); describe('->setScope()', function () { it('should set the scope of the test', function () { $scope = new Scope();
assert($reporter == 'test', 'reporter name should be "test"'); }); }); it('should emit a load event', function () { $command = null; $config = null; $this->emitter->on('peridot.load', function ($cmd, $cfg) use(&$command, &$config) { $command = $cmd; $config = $cfg; }); $this->command->run(new ArrayInput([], $this->definition), $this->output); assert($command === $this->command, "command should have been received by event"); assert($config === $this->configuration, "configuration should have been received by event"); }); context('when there are failing tests', function () { it('should return an exit code', function () { $suite = new Suite("fail suite", function () { }); $test = new Test('fail', function () { throw new Exception('fail'); }); $suite->addTest($test); $runner = new Runner($suite, $this->configuration, $this->emitter); $command = new Command($runner, $this->configuration, $this->factory, $this->emitter); $command->setApplication($this->application); $exit = $command->run(new ArrayInput([], $this->definition), $this->output); assert($exit == 1, "exit code should be 1"); }); }); }); });
}); context('when test.failed event is emitted', function () { it('should output the fully qualified test name', function () { $suite = new Suite("A bad thing", function () { }); $childSuite = new Suite("when not rad", function () { }); $test = new Test("should not be rad", function () { }); $suite->addTest($childSuite); $childSuite->addTest($test); $this->emitter->emit('test.failed', [$test, new \Exception("failure")]); $output = $this->output->fetch(); assert(strpos($output, "A bad thing when not rad should not be rad") !== false, "full suite name should be output for failure"); }); }); context('when test.pending event is emitted', function () { it('should output the fully qualified test name', function () { $suite = new Suite("A meh thing", function () { }); $childSuite = new Suite("when not rad or bad", function () { }); $test = new Test("should not be rad or bad"); $suite->addTest($childSuite); $childSuite->addTest($test); $this->emitter->emit('test.pending', [$test]); $output = $this->output->fetch(); assert(strpos($output, "A meh thing when not rad or bad should not be rad or bad") !== false, "full suite name should be output for pending"); }); }); });