Exemple #1
0
 public function setAssertionManager(test\assertion\manager $assertionManager = null)
 {
     $this->assertionManager = $assertionManager ?: new test\assertion\manager();
     $test = $this;
     $this->assertionManager->setHandler('when', function ($mixed) use($test) {
         if ($mixed instanceof \closure) {
             $mixed();
         }
         return $test;
     })->setHandler('dump', function () use($test) {
         call_user_func_array('var_dump', func_get_args());
         return $test;
     })->setPropertyHandler('exception', function () {
         return asserters\exception::getLastValue();
     });
     $returnTest = function () use($test) {
         return $test;
     };
     $this->assertionManager->setHandler('assert', $returnTest)->setHandler('if', $returnTest)->setHandler('and', $returnTest)->setHandler('then', $returnTest)->setHandler('given', $returnTest);
     $asserterGenerator = $this->asserterGenerator;
     $this->assertionManager->setDefaultHandler(function ($asserter, $arguments) use($asserterGenerator) {
         return $asserterGenerator->getAsserterInstance($asserter, $arguments);
     });
     return $this;
 }
Exemple #2
0
 public function testInvoke()
 {
     $this->if($assertionManager = new testedClass())->then->exception(function () use($assertionManager, &$event) {
         $assertionManager->invoke($event = uniqid());
     })->isInstanceOf('mageekguy\\atoum\\test\\assertion\\manager\\exception')->hasMessage('There is no handler defined for event \'' . $event . '\'')->if($assertionManager->setDefaultHandler(function ($event, $arg) {
         return $arg;
     }))->then->array($assertionManager->invoke(uniqid(), array($defaultArg = uniqid())))->isEqualTo(array($defaultArg))->if($assertionManager->setHandler($event = uniqid(), function ($eventArg) {
         return $eventArg;
     }))->then->string($assertionManager->invoke($event, array($eventArg = uniqid())))->isEqualTo($eventArg);
 }