PHP Classes

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

Recommend this page to a friend!
  Classes of Protung Dragos   PHP Event Dispatcher   tests/Wingu/OctopusCore/EventDispatcher/Tests/Unit/EventNameMatcher/NameMatcherTest.php   Download  
File: tests/Wingu/OctopusCore/EventDispatcher/Tests/Unit/EventNameMatcher/NameMatcherTest.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: 3 years ago
Size: 1,749 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\NameMatcher;

class
NameMatcherTest 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', true],
            [
'system.log', 'system.log', true], ['system.log.error', 'system.log.ERROR', true],
            [
'myevent', 'myevent2', false], ['myevent', 'MYEVENT2', false],
        );
    }

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

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

   
/**
     * @dataProvider getDataMatch
     */
   
public function testGetHash($eventName) {
       
$matcher = new NameMatcher($eventName);
       
$this->assertSame($eventName, $matcher->getHash());
    }
}