/** * Create a test and add it to the current suite * * @param $description * @param $fn */ public function addTest($description, callable $fn = null, $pending = null) { $test = new Test($description, $fn); if (!is_null($pending)) { $test->setPending($pending); } $this->getCurrentSuite()->addTest($test); return $test; }
}); $this->result->passTest($test); assert($emitted === $test, 'should have emitted test.passed event'); }); }); describe("->pendTest()", function () { beforeEach(function () { $this->emitter = new EventEmitter(); $this->result = new TestResult($this->emitter); }); it('should emit a test.pending event', function () { $emitted = null; $this->emitter->on('test.pending', function ($test) use(&$emitted) { $emitted = $test; }); $test = new Test('spec', function () { }); $test->setPending(true); $this->result->pendTest($test); assert($emitted === $test, 'should have emitted test.pending event'); }); }); describe('pending test accessors', function () { it('should allow access to the total number of pending tests', function () { $result = new TestResult($this->eventEmitter); $result->setPendingCount(1); assert($result->getPendingCount() === 1, 'should have returned pending count'); }); }); describe('failure accessors', function () { it('should allow access to the total number of failures', function () { $result = new TestResult($this->eventEmitter);
/** * @param string $description * @param callable $definition */ public function __construct($description, callable $definition) { parent::__construct($description, $definition); $this->getScope()->wasRun = false; $this->getScope()->log = false; }
}); describe('->setScope()', function () { it('should set the scope of the test', function () { $scope = new Scope(); $test = new Test("spec", function () { }); $test->setScope($scope); assert($scope === $test->getScope(), "setScope should have set scope"); }); }); describe('->setParent()', function () { it('should bind the parent scope to the child', function () { $scope = new Scope(); $parent = new Suite("parent", function () { }); $parent->setScope($scope); $test = new Test("child", function () { }); $test->setParent($parent); assert($scope === $test->getScope(), "scope should be parent scope"); }); }); describe('file accessors', function () { it('should allow access to the file property', function () { $test = new Test('test'); $test->setFile(__FILE__); $file = $test->getFile(); assert($file === __FILE__); }); }); });
/** * @param Test $test */ public function onTestPending(Test $test) { $this->output->writeln(sprintf($this->color('pending', " %s- %s"), $this->indent(), $test->getDescription())); }
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(); $test = new Test("spec", function () { }); $test->setScope($scope); assert($scope === $test->getScope(), "setScope should have set scope"); }); }); describe('->setParent()', function () { it('should bind the parent scope to the child', function () { $scope = new Scope(); $parent = new Suite("parent", function () { }); $parent->setScope($scope); $test = new Test("child", function () { }); $test->setParent($parent); assert($scope === $test->getScope(), "scope should be parent scope"); }); }); });
} $this->message->setEvent('test.failed')->setException($exception)->write(); fseek($this->tmpfile, 0); $read = trim(fread($this->tmpfile, 8192)); $content = json_decode($read); $packer = $this->message->getStringPacker(); expect($content[6])->to->not->be->null('message should not be null'); expect($content[7])->to->equal($packer->packString($exception->getTraceAsString())); expect($content[8])->to->not->be->null('type should not be null'); }); }); }); context('when receiving a data event', function () { context('and the data represents a test', function () { beforeEach(function () { $test = new Test('description'); $test->setFile(__FILE__); $this->message->setTest($test)->setEvent('test.passed')->setStatus(TestMessage::TEST_PASS)->write(); fseek($this->tmpfile, 0); $this->content = fread($this->tmpfile, 8192); $this->offset = ftell($this->tmpfile); }); it('should emit a test event when a complete passing test is received', function () { $test = null; $this->message->on('test.passed', function ($t) use(&$test) { $test = $t; }); $this->message->emit('data', [$this->content]); expect($test)->to->not->be->null->and->to->satisfy(function (Test $test) { return $test->getDescription() === 'description' && $test->getFile() === __FILE__; });