Вход Регистрация
Файл: vkolhoze.com/vendor/guzzle/guzzle/tests/Guzzle/Tests/Common/AbstractHasDispatcherTest.php
Строк: 62
<?php

namespace GuzzleTestsCommon;

use 
GuzzleCommonEvent;
use 
GuzzleCommonAbstractHasDispatcher;
use 
SymfonyComponentEventDispatcherEventDispatcher;

/**
 * @covers GuzzleCommonAbstractHasDispatcher
 */
class AbstractHasAdapterTest extends GuzzleTestsGuzzleTestCase
{
    public function 
testDoesNotRequireRegisteredEvents()
    {
        
$this->assertEquals(array(), AbstractHasDispatcher::getAllEvents());
    }

    public function 
testAllowsDispatcherToBeInjected()
    {
        
$d = new EventDispatcher();
        
$mock $this->getMockForAbstractClass('GuzzleCommonAbstractHasDispatcher');
        
$this->assertSame($mock$mock->setEventDispatcher($d));
        
$this->assertSame($d$mock->getEventDispatcher());
    }

    public function 
testCreatesDefaultEventDispatcherIfNeeded()
    {
        
$mock $this->getMockForAbstractClass('GuzzleCommonAbstractHasDispatcher');
        
$this->assertInstanceOf('SymfonyComponentEventDispatcherEventDispatcher'$mock->getEventDispatcher());
    }

    public function 
testHelperDispatchesEvents()
    {
        
$data = array();
        
$mock $this->getMockForAbstractClass('GuzzleCommonAbstractHasDispatcher');
        
$mock->getEventDispatcher()->addListener('test', function(Event $e) use (&$data) {
            
$data $e->getIterator()->getArrayCopy();
        });
        
$mock->dispatch('test', array(
            
'param' => 'abc'
        
));
        
$this->assertEquals(array(
            
'param' => 'abc',
        ), 
$data);
    }

    public function 
testHelperAttachesSubscribers()
    {
        
$mock $this->getMockForAbstractClass('GuzzleCommonAbstractHasDispatcher');
        
$subscriber $this->getMockForAbstractClass('SymfonyComponentEventDispatcherEventSubscriberInterface');

        
$dispatcher $this->getMockBuilder('SymfonyComponentEventDispatcherEventDispatcher')
            ->
setMethods(array('addSubscriber'))
            ->
getMock();

        
$dispatcher->expects($this->once())
            ->
method('addSubscriber');

        
$mock->setEventDispatcher($dispatcher);
        
$mock->addSubscriber($subscriber);
    }
}
Онлайн: 3
Реклама