Inheritance: extends Peridot\Core\AbstractTest
 /**
  * @param Suite $suite
  */
 public function onSuiteStart(Suite $suite)
 {
     if ($suite != $this->root) {
         ++$this->column;
         $this->output->writeln(sprintf('%s%s', $this->indent(), $suite->getDescription()));
     }
 }
 /**
  * Write a suite.end event on the message.
  *
  * @param Suite $suite
  * @return void
  */
 public function onSuiteEnd(Suite $suite)
 {
     if (!$suite->getDescription()) {
         return;
     }
     $this->message->setTest($suite)->setEvent('suite.end')->write();
 }
 /**
  * @param Suite $suite
  */
 public function onSuiteStart(Suite $suite)
 {
     $scope = new TemporaryScope();
     $suite->getScope()->peridotAddChildScope($scope);
     $suite->addTearDownFunction(function () use(&$scope) {
         $scope->cleanUpTemporary();
     });
 }
 /**
  * Handle the start of a suite.
  *
  * @access private
  */
 public function onSuiteStart(Suite $suite)
 {
     foreach ($suite->getTests() as $test) {
         $definition = new ReflectionFunction($test->getDefinition());
         $parameters = $definition->getParameters();
         if ($parameters) {
             $test->setDefinitionArguments($this->parameterArguments($parameters));
         }
     }
 }
Exemple #5
0
 /**
  * Creates a suite and adds it to the current suite. The newly
  * created suite will become the new "current" suite
  *
  * @param $description
  * @param callable $fn
  */
 public function addSuite($description, callable $fn, $pending = null)
 {
     $suite = new Suite($description, $fn);
     if (!is_null($pending)) {
         $suite->setPending($pending);
     }
     $this->getCurrentSuite()->addTest($suite);
     array_unshift($this->suites, $suite);
     call_user_func($suite->getDefinition());
     array_shift($this->suites);
     return $suite;
 }
Exemple #6
0
 /**
  * {@inheritdoc}
  *
  * @param TestResult $result
  */
 public function run(TestResult $result)
 {
     $this->eventEmitter->on('test.failed', function () {
         if ($this->configuration->shouldStopOnFailure()) {
             $this->eventEmitter->emit('suite.halt');
         }
     });
     $this->eventEmitter->emit('runner.start');
     $this->suite->setEventEmitter($this->eventEmitter);
     $start = microtime(true);
     $this->suite->run($result);
     $this->eventEmitter->emit('runner.end', [microtime(true) - $start]);
 }
Exemple #7
0
 /**
  * {@inheritdoc}
  *
  * @param TestResult $result
  */
 public function run(TestResult $result)
 {
     $this->handleErrors();
     $this->eventEmitter->on('test.failed', function () {
         if ($this->configuration->shouldStopOnFailure()) {
             $this->eventEmitter->emit('suite.halt');
         }
     });
     $this->eventEmitter->emit('runner.start');
     $this->suite->setEventEmitter($this->eventEmitter);
     $this->suite->run($result);
     $this->eventEmitter->emit('runner.end');
     restore_error_handler();
 }
 /**
  * @param Suite $suite
  */
 public function onSuiteStart(Suite $suite)
 {
     $suite->getScope()->peridotAddChildScope(new ProphecyScope());
     $description = $suite->getDescription();
     if (class_exists($description)) {
         $suite->addSetupFunction(function () use($description) {
             $prophet = $this->getProphet();
             $this->subject = $prophet->prophesize($description);
         });
         $suite->addTearDownFunction(function () {
             $this->clearProphet();
         });
     }
 }
 /**
  * @param string $description
  */
 public function __construct($description)
 {
     parent::__construct($description, function () {
         // noop
     });
 }
Exemple #10
0
 });
 it("should return the number of tests run", 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->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);
 /**
  * @param \Peridot\Core\Suite $suite
  */
 public function onSuiteStart(Suite $suite)
 {
     $parentScope = $suite->getScope();
     $parentScope->peridotAddChildScope($this->scope);
 }
Exemple #12
0
 /**
  * Create a Suite based on the state of the Context.
  *
  * @param $description
  * @param callable $fn
  * @param $pending
  * @return Suite
  */
 private function createSuite($description, callable $fn, $pending)
 {
     $suite = new Suite($description, $fn);
     if ($pending !== null) {
         $suite->setPending($pending);
     }
     $suite->setFile($this->file);
     $suite->setEventEmitter($this->getEventEmitter());
     return $suite;
 }
                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");
            });
        });
    });
});
Exemple #14
0
             $emitter->emit('suite.halt');
         });
         $passing2 = new Test("passing2 spec", function () {
         });
         $suite->addTest($passing);
         $suite->addTest($halting);
         $suite->addTest($passing2);
         $result = new TestResult($this->eventEmitter);
         $suite->setEventEmitter($this->eventEmitter);
         $suite->run($result);
         assert($result->getTestCount() == 2, "test count should be 2");
     });
 });
 describe("->addTest()", function () {
     it("should set parent property on child test", function () {
         $suite = new Suite("test suite", function () {
         });
         $test = new Test("test spec", function () {
         });
         $suite->addTest($test);
         assert($test->getParent() === $suite, "added test should have parent property set");
     });
 });
 describe('->setTests()', function () {
     beforeEach(function () {
         $this->suite = new Suite("test suite", function () {
         });
         $test = new Test("test", function () {
         });
         $this->suite->addTest($test);
     });
     it('should set the tests to the passed in value', function () {
        $this->emitter = new EventEmitter();
        $this->plugin = new ProphecyPlugin($this->emitter);
    });
    context('when suite.start event fires', function () {
        it('should set add the prophecy scope to the child scope', function () {
            $suite = new Suite("suite", function () {
            });
            $this->emitter->emit('suite.start', [$suite]);
            $prophet = $suite->getScope()->getProphet();
            assert($prophet instanceof Prophet, 'suite should be able to get a prophet');
        });
        it('should add a setup function that creates a subject', function () {
            $suite = new Suite('Peridot\\Core\\Suite', function () {
            });
            $this->emitter->emit('suite.start', [$suite]);
            call_user_func($suite->getSetupFunctions()[0]);
            $dummy = $suite->getScope()->subject->reveal();
            assert($dummy instanceof Suite, "subject->reveal() should be instance of Suite");
        });
        it('should add a tear down function that clears a prophet', function () {
            $suite = new Suite('Peridot\\Core\\Suite', function () {
            });
            $this->emitter->emit('suite.start', [$suite]);
            call_user_func($suite->getSetupFunctions()[0]);
            $prophet = $suite->getScope()->getProphet();
            call_user_func($suite->getTearDownFunctions()[0]);
            $again = $suite->getScope()->getProphet();
            assert($prophet !== $again, "prophet instance should have been cleared");
        });
    });
});
Exemple #16
0
             $emitter = new EventEmitter();
             $count = 0;
             $emitter->on('test.passed', function () use(&$count) {
                 $count++;
             });
             $emitter->on('test.failed', function () use(&$count) {
                 $count++;
             });
             $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);
<?php

use Doctrine\ORM\Mapping\Driver\SimplifiedYamlDriver;
use Evenement\EventEmitter;
use Peridot\Core\Suite;
use Peridot\Plugin\Doctrine\DoctrinePlugin;
use Peridot\Plugin\Doctrine\EntityManager\EntityManagerService;
describe('Peridot\\Plugin\\Doctrine\\DoctrinePlugin', function () {
    beforeEach(function () {
        $this->entityManagerService = (new EntityManagerService())->setMappingDriver(new SimplifiedYamlDriver([]));
        $this->eventEmitter = new EventEmitter();
        $this->plugin = new DoctrinePlugin($this->eventEmitter, $this->entityManagerService);
    });
    describe('->onSuiteStart()', function () {
        it('should add the doctrine scope to the child scope', function () {
            $suite = new Suite('my suite', ['foo', 'bar']);
            $this->eventEmitter->emit('suite.start', [$suite]);
            $entityManager = $suite->getScope()->createEntityManager();
            expect($entityManager)->to->be->instanceof('Doctrine\\ORM\\EntityManager');
        });
    });
});
Exemple #18
0
         $first = new Test('child');
         $removed = $this->node->removeNode($first);
         assert($removed === null, 'cannot remove node that is not child');
     });
     it('should be possible through parent references', function () {
         $first = new Test('child 1');
         $second = new Test('child 2');
         $this->node->setChildNodes([$first, $second]);
         $removed = $first->getParent()->removeNode($first);
         assert($removed === $first, 'should have returned removed node');
         assert(count($this->node->getChildNodes()) === 1, 'size should reflect removed node');
     });
 });
 describe('->walk()', function () {
     it('should walk a hierarchy', function () {
         $childSuite = new Suite('child suite');
         $grandChildTest = new Test(' grand child');
         $childSuite->addChildNode($grandChildTest);
         $this->node->addChildNode($childSuite);
         $joined = '';
         $this->node->walk(function (TestInterface $test) use(&$joined) {
             $joined .= $test->getDescription();
         });
         assert($joined === 'child suite grand child');
     });
 });
 describe('->filter()', function () {
     beforeEach(function () {
         $this->fast = new Test('should run @fast');
         $this->slow1 = new Test('should run @slow');
         $this->slow2 = new Test('should also be @slow');
 /**
  * Attach a new scope and, if enabled, auto instantiate the described class.
  * @param Suite $suite
  */
 public function onSuiteStart(Suite $suite)
 {
     $this->scope = new AutomockScope();
     $suite->getScope()->peridotAddChildScope($this->scope);
 }
use Peridot\Concurrency\Reporter\ConcurrentReporter;
use Peridot\Concurrency\Runner\StreamSelect\IO\TmpfileOpen;
use Peridot\Concurrency\Runner\StreamSelect\IO\Worker;
use Peridot\Configuration;
use Peridot\Core\Suite;
use Peridot\Core\Test;
use Symfony\Component\Console\Output\BufferedOutput;
describe('ConcurrentReporter', function () {
    beforeEach(function () {
        $configuration = new Configuration();
        $this->output = new BufferedOutput();
        $this->emitter = new EventEmitter();
        $this->reporter = new ConcurrentReporter($configuration, $this->output, $this->emitter);
    });
    beforeEach(function () {
        $suite = new Suite('description', function () {
        });
        $suite->setFile(__FILE__);
        $this->emitter->emit('suite.start', [$suite]);
        $this->test = new Test('description');
        $this->test->setFile(__FILE__);
        $this->exception = new \Peridot\Concurrency\Runner\StreamSelect\Model\Exception();
    });
    context('when the test.passed event is emitted', function () {
        beforeEach(function () {
            $this->emitter->emit('test.passed', [$this->test]);
        });
        it('should be set the test property of the entry', function () {
            expect($this->reporter->getSuites())->to->have->deep->property('[' . __FILE__ . '][0][test]', $this->test);
        });
        it('should have a null value for an exception', function () {
            expect($this->reporter->getSuites())->to->have->deep->property('[' . __FILE__ . '][0][exception]', null);
Exemple #21
0
     $child = new Suite("child suite", function () {
     });
     $grandchild = new Suite("grandchild suite", function () {
     });
     $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);
    });
    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");
        });
    });
});