public function __invoke()
 {
     $suite = new Suite();
     $exception = new \Exception();
     $suite->addTest(function () {
     }, 'passing test 1');
     $suite->addTest(function () {
     }, 'passing test 2');
     $result = $suite(new Runner());
     $expected = Result::passed();
     Assert::like($result, $expected);
 }
 public function __invoke()
 {
     $test = function () {
     };
     $suite = new Suite();
     Assert::same($suite->getTestsCount(), 0);
     $suite = new Suite();
     $suite->addTest($test, 'test1');
     Assert::same($suite->getTestsCount(), 1);
     $suite = new Suite();
     $suite->addTest($test, 'test1');
     $suite->addTest($test, 'test2');
     Assert::same($suite->getTestsCount(), 2);
 }
Example #3
0
/**
 * @param string $file
 * @return Suite
 */
function loadSuiteFromFile(string $file)
{
    $suite = new Suite();
    $tests = (require_once $file);
    foreach ($tests as $testName => $test) {
        $suite->addTest($test, $testName);
    }
    return $suite;
}
Example #4
0
 public function __invoke()
 {
     $test1 = function () {
     };
     $test1name = 'testName1';
     $test2 = function () {
     };
     $test2name = 'testName2';
     $suite = new Suite();
     $runTestsCount = 0;
     $testsNames = [];
     $afterSuiteCallback = function ($testNumber, $testName) use(&$runTestsCount, &$testsNames) {
         $testsNames[] = $testName;
         $runTestsCount++;
     };
     $suite->addTest($test1, $test1name);
     $suite->addTest($test2, $test2name);
     $suite->setAfterTestCallback($afterSuiteCallback);
     $expectedTests = [$test1name, $test2name];
     $suite(new Runner());
     Assert::same($testsNames, $expectedTests);
     Assert::same($runTestsCount, 2);
 }
 public function __invoke()
 {
     $passingTest = function () {
     };
     $passingTestName = 'passing test';
     $afterTestCallback = function ($testNumber, $testName, $testResult) use(&$spy) {
         $spy = (object) ['testNumber' => $testNumber, 'testName' => $testName, 'testResult' => $testResult];
     };
     $runner = new Runner();
     $suite = new Suite();
     $suite->setAfterTestCallback($afterTestCallback);
     $suite->addTest($passingTest, $passingTestName);
     $suite($runner);
     $expected = new \stdClass();
     $expected->testNumber = 1;
     $expected->testName = $passingTestName;
     $expected->testResult = Result::passed($passingTestName);
     Assert::like($spy, $expected);
 }