Exemplo n.º 1
0
 /**
  * Execute the test along with any setup and tear down functions.
  *
  * @param  TestResult $result
  * @return void
  */
 public function run(TestResult $result)
 {
     $result->startTest($this);
     if ($this->getPending()) {
         $result->pendTest($this);
         return;
     }
     $this->executeTest($result);
     $result->endTest($this);
 }
 /**
  * Handle errors.
  *
  * @param $data
  * @return void
  */
 public function onError($error, WorkerInterface $worker)
 {
     $info = $worker->getJobInfo();
     $this->errors[$info->file] = $error;
     $failures = $this->result->getFailureCount();
     $this->result->setFailureCount(++$failures);
 }
Exemplo n.º 3
0
                $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);
            $result->setFailureCount(1);
            assert($result->getFailureCount() === 1, 'should have returned failure count');
        });
    });
    describe('test count accessors', function () {
        it('should allow access to the total number of tests', function () {
            $result = new TestResult($this->eventEmitter);
            $result->setTestCount(1);
            assert($result->getTestCount() === 1, 'should have returned test count');
        });
    });
});
Exemplo n.º 4
0
 /**
  * Set an error handler to handle errors within the test
  *
  * @param TestResult $result
  * @param array      &$action
  *
  * @return callable|null
  */
 protected function handleErrors(TestResult $result, array &$action)
 {
     $handler = null;
     $handler = set_error_handler(function ($severity, $message, $path, $line) use($result, &$action, &$handler) {
         // if there is an existing error handler, call it and record the result
         $isHandled = $handler && false !== $handler($severity, $message, $path, $line);
         if (!$isHandled) {
             $result->getEventEmitter()->emit('error', [$severity, $message, $path, $line]);
             // honor the error reporting configuration - this also takes care of the error control operator (@)
             $errorReporting = error_reporting();
             $shouldHandle = $severity === ($severity & $errorReporting);
             if ($shouldHandle) {
                 $this->failIfPassing($action, new ErrorException($message, 0, $severity, $path, $line));
             }
         }
     });
     return $handler;
 }
Exemplo n.º 5
0
            $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("->getPendingCount()", function () {
        it("should return the pending count tracked by the result", function () {
            $result = new TestResult($this->eventEmitter);
            $pending = new Test("pending");
            $result->pendTest($pending);
            $count = $result->getPendingCount();
            assert($count == 1, "pending count should be 1");
        });
    });
});