PHP Classes

File: tests/Wingu/OctopusCore/EventDispatcher/Tests/Unit/EventNameMatcher/EventNameMatcherFactoryTest.php

Recommend this page to a friend!
  Classes of Protung Dragos   PHP Event Dispatcher   tests/Wingu/OctopusCore/EventDispatcher/Tests/Unit/EventNameMatcher/EventNameMatcherFactoryTest.php   Download  
File: tests/Wingu/OctopusCore/EventDispatcher/Tests/Unit/EventNameMatcher/EventNameMatcherFactoryTest.php
Role: Unit test script
Content type: text/plain
Description:
Class: PHP Event Dispatcher
Register events and call registered listeners
Author: By
Last change: Initial commit
Date: 2 years ago
Size: 2,103 bytes
 

Contents

Class file image Download
<?php

namespace Wingu\OctopusCore\EventDispatcher\Tests\Unit\EventNameMatcher;

use
Wingu\OctopusCore\EventDispatcher\Tests\Unit\TestCase;
use
Wingu\OctopusCore\EventDispatcher\EventNameMatcher\EventNameMatcherFactory;

class
EventNameMatcherFactoryTest extends TestCase {

    public function
getDataPatterns() {
        return array(
            [
EventNameMatcherFactory::EVENT_NAME_ALL, 'AllNamesMatcher'],
            [
'/^def/', 'RegexMatcher'], ['#/.+/[a-zA-Z]*#', 'RegexMatcher'], ['/^event(.*)/i', 'RegexMatcher'], ['/\\\\n/', 'RegexMatcher'],
            [
'/[\x{0600}-\x{06FF}\x]{1,32}/u', 'RegexMatcher'], ['/(?P<name>\w+): (?P<digit>\d+)/', 'RegexMatcher'], ['/[0-9]+/', 'RegexMatcher'],
            [
'system.*', 'WildcardMatcher'], ['system.*.error', 'WildcardMatcher'], ['system#', 'WildcardMatcher'], ['system.*.error.#', 'WildcardMatcher'],
            [
'system', 'NameMatcher'], ['system.log', 'NameMatcher'], ['system-error', 'NameMatcher'], ['system(error)', 'NameMatcher']
        );
    }

   
/**
     * @dataProvider getDataPatterns
     */
   
public function testGetEventNameMatcher($pattern, $expectedInstance) {
       
$actual = EventNameMatcherFactory::getEventNameMatcher($pattern);
       
$this->assertInstanceOf('Wingu\OctopusCore\EventDispatcher\EventNameMatcher\\'.$expectedInstance, $actual);
    }

    public function
testGetEventNameMatcherInstancePattern() {
       
$pattern = $this->getMock('Wingu\OctopusCore\EventDispatcher\EventNameMatcher\EventNameMatcherInterface');
       
$actual = EventNameMatcherFactory::getEventNameMatcher($pattern);
       
$this->assertSame($pattern, $actual);
    }

    public function
getDataInvalidPattern() {
        return array(
            [array()], [
null], [123], [new \stdClass()], [STDIN]
        );
    }

   
/**
     * @dataProvider getDataInvalidPattern
     * @expectedException Wingu\OctopusCore\EventDispatcher\Exceptions\InvalidArgumentException
     */
   
public function testGetEventNameMatcherInstancePatternThrowsException($pattern) {
       
EventNameMatcherFactory::getEventNameMatcher($pattern);
    }
}