dox Executable Documentation

Handle actions

An Action gets published over the ActionDispatcher and the result is passed back.

Action reaches handler object

Given the class 'some\\MyAction'
Given an object 'myHandler'
Given I set 'myHandler' as handler for 'some\\MyAction'
When I dispatch the action 'some\\MyAction'
Then the method 'myAction' of 'myHandler' should be invoked

Action reaches handler class

Given the class 'classHandler\\MyAction'
Given the class 'classHandler\\Handler' with the body ' public static $executed = false; function myAction() { self::$executed = true; } '
Given I added the class 'classHandler\\Handler' as handler for 'classHandler\\MyAction'
When I dispatch the action 'classHandler\\MyAction'
Then 'classHandler\\Handler::$executed' should be true

Action reaches handler closure

Given the class 'closureHandler\\MyAction'
Given I added the closure function () { $GLOBALS['executed'] = true; } as handler for 'closureHandler\\MyAction'
When I dispatch the action 'closureHandler\\MyAction'
Then '$GLOBALS["executed"]' should be true

Action is passed as argument

Given the class 'argument\\MyAction'
Given an object 'myHandler'
Given I set 'myHandler' as handler for 'argument\\MyAction'
When I dispatch the action 'argument\\MyAction'
Then the method of 'myHandler' should be invoked with an instance of 'argument\\MyAction'

Returned value is passed back as success

Given the class 'success\\MyAction'
Given I added the closure function () { return 'Great Success!'; } as handler for 'success\\MyAction'
When I dispatch the action 'success\\MyAction'
Then the result should be successful with 'Great Success!'

Exception is passed back as exception

Given the class 'fail\\MyAction'
Given I added the closure function () { throw new \Exception('Bam!'); } as handler for 'fail\\MyAction'
When I try to dispatch the action 'fail\\MyAction'
Then the exception 'Bam!' should be thrown

Create representers on the fly

* @var \watoki\qrator\representer\generic\GenericEntityRepresenter $representer

$representer = $this->registry->registry->getEntityRepresenter(\DateTime::class);
$representer->setStringifier(function (\DateTime $d) {
    return $d->format('Y-m-d');
});
$again = $this->registry->registry->getEntityRepresenter(\DateTime::class);
$this->assertEquals('2001-02-03', $again->toString(new \DateTime('2001-02-03')));