Login   Register  
PHP Classes
elePHPant
Icontem

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

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Protung Dragos  >  PHP Event Dispatcher  >  tests/Wingu/OctopusCore/EventDispatcher/Tests/Unit/EventNameMatcher/RegexMatcherTest.php  >  Download  
File: tests/Wingu/OctopusCore/EventDispatcher/Tests/Unit/EventNameMatcher/RegexMatcherTest.php
Role: Unit test script
Content type: text/plain
Description:
Class: PHP Event Dispatcher
Register events and call registered listeners
Author: By
Last change:
Date: 2013-02-21 06:55
Size: 1,840 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\RegexMatcher;

class 
RegexMatcherTest extends TestCase {

    protected function 
getEventMock($eventName) {
        
$mock $this->getMock('\Wingu\OctopusCore\EventDispatcher\EventInterface');
        
$mock->expects($this->any())->method('getName')->will($this->returnValue($eventName));
        return 
$mock;
    }

    public function 
getDataInvalidNameToMatch() {
        return array(
            [
1], [new \stdClass()], [STDIN]
        );
    }

    public function 
getDataMatch() {
        return array(
            [
'myevent''/myevent$/'true], ['myevent''/MYEVENT$/i'true],
            [
'myevent''/myevent2$/'false], ['myevent''/MYEVENT$/'false],
            [
'abcdef''/def$/'true], ['system.core''/\bsystem\b/i'true],
            [
'system.log.error.53''/[0-9]/'true],
            [
'abcdef''/^def/'false],

        );
    }

    
/**
     * @dataProvider getDataInvalidNameToMatch
     * @expectedException Wingu\OctopusCore\EventDispatcher\Exceptions\InvalidArgumentException
     */
    
public function testInvalidArgumentExceptionThrownIfNameToMatchIsNotSctring($pattern) {
        
$matcher = new RegexMatcher($pattern);
    }

    
/**
     * @dataProvider getDataMatch
     */
    
public function testMatch($event$pattern$match) {
        
$event $this->getEventMock($event);
        
$matcher = new RegexMatcher($pattern);
        
$this->assertSame($match$matcher->match($event));
    }

    
/**
     * @dataProvider getDataMatch
     */
    
public function testGetHash($event$pattern) {
        
$matcher = new RegexMatcher($pattern);
        
$this->assertSame($pattern$matcher->getHash());
    }
}