Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support trigger($eventName) and Cake\EventManager proxy #119

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
},
"require-dev": {
"phpunit/phpunit": "~5.0",
"symfony/http-foundation": "~2.7.6"
"symfony/http-foundation": "~2.7.6",
"cakephp/event": "~3.0"
},
"license": "MIT",
"authors": [
Expand Down
39 changes: 39 additions & 0 deletions src/Event/CakeEvmProxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
namespace Penny\Event;

use Cake\Event\EventManager;

class CakeEvmProxy implements PennyEvmInterface
{
/**
* @var EventManager
*/
private $eventManager;

/**
* Proxy EventManager
*/
public function __construct()
{
$this->eventManager = new EventManager();
}

/**
* {@inheritDoc}
*/
public function trigger($event)
{
$this->eventManager->dispatch($event);
return $this;
}

/**
* {@inheritDoc}
*/
public function attach($eventName, callable $listener, $priority = 1)
{
$options['priority'] = $priority;
$this->eventManager->attach($listener, $eventName, $options);
return $this;
}
}
4 changes: 2 additions & 2 deletions src/Event/PennyEvmInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ interface PennyEvmInterface
/**
* Triggerer event
*
* @param PennyEventInterface $event Trigger specific event
* @param PennyEventInterface|string $event Trigger specific event
*/
public function trigger(PennyEventInterface $event);
public function trigger($event);

/**
* Attach new listener at specific event
Expand Down
2 changes: 1 addition & 1 deletion src/Event/ZendEvmProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct()
/**
* {@inheritDoc}
*/
public function trigger(PennyEventInterface $event)
public function trigger($event)
{
$this->eventManager->trigger($event);
return $this;
Expand Down
38 changes: 38 additions & 0 deletions tests/Event/CakeEvmProxyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace PennyTest\Event;

use Penny\Event\CakeEvmProxy;
use PHPUnit_Framework_TestCase;

class CakeEmvProxyTest extends PHPUnit_Framework_TestCase
{
/** @var CakeEmvProxy */
protected $evmProxy;

protected function setUp()
{
$this->evmProxy = new CakeEvmProxy();
}

public function testAttachTrigger()
{
$listener1 = function() {
echo 'triggered1';
};
$listener2 = function() {
echo 'triggered2';
};

$eventKey = 'foo';

$this->evmProxy->attach($eventKey, $listener1, 102);
$this->evmProxy->attach($eventKey, $listener2, 101);

ob_start();
$this->evmProxy->trigger($eventKey);
$content = ob_get_clean();

$this->assertEquals('triggered2triggered1', $content);
}
}
1 change: 0 additions & 1 deletion tests/Http/SymfonyKernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use FastRoute;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use TestApp\Controller\IndexController;

class SymfonyKernelTest extends \PHPUnit_Framework_TestCase
{
Expand Down