Login   Register  
PHP Classes
elePHPant
Icontem

File: tests/Wingu/OctopusCore/EventDispatcher/Tests/Unit/EventDispatcherTest.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/EventDispatcherTest.php  >  Download  
File: tests/Wingu/OctopusCore/EventDispatcher/Tests/Unit/EventDispatcherTest.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: 1 year ago
Size: 2,477 bytes
 

Contents

Class file image Download
<?php

namespace Wingu\OctopusCore\EventDispatcher\Tests\Unit;

use 
Wingu\OctopusCore\EventDispatcher\EventDispatcher;

class 
EventDispatcherTest extends TestCase {

    protected function 
getMockSubscription($match$priority) {
        
$matcher $this->getMock('Wingu\OctopusCore\EventDispatcher\EventNameMatcher\EventNameMatcherInterface');
        
$matcher->expects($this->any())->method('matchByName')->will($this->returnValue($match));

        
$mock $this->getMock('Wingu\OctopusCore\EventDispatcher\SubscriptionInterface');
        
$mock->expects($this->any())->method('getPriority')->will($this->returnValue($priority));
        
$mock->expects($this->any())->method('getEventNameMatcher')->will($this->returnValue($matcher));
        return 
$mock;
    }

    public function 
testHasSubscriptions() {
        
$ed = new EventDispatcher();

        
$this->assertFalse($ed->hasSubscriptions());
    }

    public function 
testGetEventSubscriptions() {
        
$ed = new EventDispatcher();

        
$ed->addSubscription($this->getMockSubscription(true0));
        
$ed->addSubscription($this->getMockSubscription(true1));
        
$ed->addSubscription($this->getMockSubscription(true0));

        
$this->assertCount(3$ed->getEventSubscriptions('test'));
    }

    public function 
testRemoveSubscription() {
        
$ed = new EventDispatcher();
        
$subscription1 $this->getMockSubscription(true0);
        
$subscription2 $this->getMockSubscription(true0);

        
$ed->addSubscription($subscription1);
        
$ed->addSubscription($subscription2);
        
$this->assertCount(2$ed->getEventSubscriptions('test'));

        
$ed->removeSubscription($subscription1);
        
$this->assertCount(1$ed->getEventSubscriptions('test'));

        
$ed->removeSubscription($subscription2);
        
$this->assertCount(0$ed->getEventSubscriptions('test'));
    }

    public function 
testSerialization() {
        
$ed = new EventDispatcher();

        
$subscription1 $this->getMockSubscription(true0);
        
$subscription2 $this->getMockSubscription(true0);

        
$ed->addSubscription($subscription1);
        
$ed->addSubscription($subscription2);

        
$this->assertTrue($ed->hasSubscriptions());

        
$serialize serialize($ed);
        
$this->assertSame('O:49:"Wingu\OctopusCore\EventDispatcher\EventDispatcher":0:{}'$serialize);

        
$ed unserialize($serialize);
        
$this->assertFalse($ed->hasSubscriptions());
    }
}