1<?php 2 3namespace Phalcon\Test\Listener; 4 5use ComponentX; 6use Phalcon\Events\Event; 7use Phalcon\Test\Unit\Events\ManagerTest; 8 9/** 10 * Phalcon\Test\Listener\ThirdListener 11 * 12 * @copyright (c) 2011-2017 Phalcon Team 13 * @link https://www.phalconphp.com 14 * @author Andres Gutierrez <andres@phalconphp.com> 15 * @author Serghei Iakovlev <serghei@phalconphp.com> 16 * @package Phalcon\Test\Listener 17 * 18 * The contents of this file are subject to the New BSD License that is 19 * bundled with this package in the file LICENSE.txt 20 * 21 * If you did not receive a copy of the license and are unable to obtain it 22 * through the world-wide-web, please send an email to license@phalconphp.com 23 * so that we can send you a copy immediately. 24 */ 25class ThirdListener 26{ 27 /** @var ManagerTest */ 28 protected $testCase; 29 30 protected $before = 0; 31 32 protected $after = 0; 33 34 public function __construct() 35 { 36 include_once PATH_DATA . 'events/ComponentX.php'; 37 } 38 39 public function setTestCase(ManagerTest $testCase) 40 { 41 $this->testCase = $testCase; 42 } 43 44 public function beforeAction($event, $component, $data) 45 { 46 $this->testCase->assertInstanceOf(Event::class, $event); 47 $this->testCase->assertInstanceOf(ComponentX::class, $component); 48 $this->testCase->assertEquals($data, 'extra data'); 49 50 $this->before++; 51 } 52 53 public function afterAction($event, $component) 54 { 55 $this->testCase->assertInstanceOf(Event::class, $event); 56 $this->testCase->assertInstanceOf(ComponentX::class, $component); 57 $this->testCase->assertEquals($event->getData(), ['extra', 'data']); 58 59 $this->after++; 60 61 $this->testCase->setLastListener($this); 62 } 63 64 public function getBeforeCount() 65 { 66 return $this->before; 67 } 68 69 public function getAfterCount() 70 { 71 return $this->after; 72 } 73} 74