/**
  * @param Suite $suite
  */
 public function onSuiteStart(Suite $suite)
 {
     $scope = new TemporaryScope();
     $suite->getScope()->peridotAddChildScope($scope);
     $suite->addTearDownFunction(function () use(&$scope) {
         $scope->cleanUpTemporary();
     });
 }
 /**
  * @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 \Peridot\Core\Suite $suite
  */
 public function onSuiteStart(Suite $suite)
 {
     $parentScope = $suite->getScope();
     $parentScope->peridotAddChildScope($this->scope);
 }
예제 #4
0
     $fn = function () {
         assert($this->log == "setup", "should have setup in log");
     };
     $suite->addTest(new Test("should have log", $fn));
     $suite->addTest(new Test("should also have log", $fn));
     $result = new TestResult($this->eventEmitter);
     $suite->setEventEmitter($this->eventEmitter);
     $suite->run($result);
     $expected = "2 run, 0 failed";
     $actual = $result->getSummary();
     assert($expected == $actual, "expected {$expected}, got {$actual}");
 });
 it('should pass child scopes to tests', function () {
     $suite = new Suite("Suite", function () {
     });
     $suite->getScope()->use(new SuiteScope());
     $test = new Test("this is a test", function () {
         assert($this->getNumber() == 5, "parent scope should be set on test");
     });
     $suite->addTest($test);
     $result = new TestResult($this->eventEmitter);
     $suite->setEventEmitter($this->eventEmitter);
     $suite->run($result);
     assert('1 run, 0 failed' == $result->getSummary(), "result summary should show 1/0");
 });
 it("should pass teardown functions to tests", function () {
     $suite = new Suite("Suite", function () {
     });
     $suite->addTearDownFunction(function () {
         $this->log = "torn";
     });
        $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");
        });
    });
});
 /**
  * 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);
 }
예제 #7
0
     $fn = function () {
         assert($this->log == "setup", "should have setup in log");
     };
     $suite->addTest(new Test("should have log", $fn));
     $suite->addTest(new Test("should also have log", $fn));
     $result = new TestResult($this->eventEmitter);
     $suite->setEventEmitter($this->eventEmitter);
     $suite->run($result);
     $expected = "2 run, 0 failed";
     $actual = $result->getSummary();
     assert($expected == $actual, "expected {$expected}, got {$actual}");
 });
 it('should pass child scopes to tests', function () {
     $suite = new Suite("Suite", function () {
     });
     $suite->getScope()->peridotAddChildScope(new SuiteScope());
     $test = new Test("this is a test", function () {
         assert($this->getNumber() == 5, "parent scope should be set on test");
     });
     $suite->addTest($test);
     $result = new TestResult($this->eventEmitter);
     $suite->setEventEmitter($this->eventEmitter);
     $suite->run($result);
     assert('1 run, 0 failed' == $result->getSummary(), "result summary should show 1/0");
 });
 it("should pass teardown functions to tests", function () {
     $suite = new Suite("Suite", function () {
     });
     $suite->addTearDownFunction(function () {
         $this->log = "torn";
     });
<?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');
        });
    });
});