beberlei / litecqrs-php

Small convention based CQRS library for PHP
MIT License
553 stars 47 forks source link

Add PHPUnit Assertions as Plugin #6

Open beberlei opened 12 years ago

liuggio commented 10 years ago

Do you also mean create an assertion like assertEventHasBeenRaised('\FQCN', EventProviderInterface $eventProvider)?

something like


    /**
     * Assert that the event class name was raised.
     *
     * @param string                           $eventClassName The string classname
     * @param \LiteCQRS\EventProviderInterface $eventProvider  The Event Provider
     */
    public function assertEventHasBeenRaised($eventClassName, \LiteCQRS\EventProviderInterface $eventProvider)
    {
        $eventClassName = trim($eventClassName, "\\");
        $count = count(array_filter($eventProvider->getAppliedEvents(), function($k) use($eventClassName) {

            return ($eventClassName == trim(get_class($k), "\\"));
        }));

        $this->assertGreaterThan(0, $count, sprintf('The event \'%s\' was not raised but the eventProvider.', $eventClassName));
    }