<?php
require_once( __DIR__ . '/../../Event/HandlerPriorityQueue.php' );
require_once( __DIR__ . '/../../Event/Handler.php' );
require_once( __DIR__ . '/../../Event/GenericEvent.php' );
require_once( __DIR__ . '/../../Patterns/Publisher.php' );
use Falcraft\Event;
use Falcraft\Patterns;
echo "Falcraft\\Event\\HandlerPriorityQueue.php Test\n";
echo "--------------------------------------------\n\n";
echo "Basic Instantiation -- \n";
echo " Empty Instantiation -> ";
$success = true;
$queue = null;
try {
$queue = new Event\HandlerPriorityQueue();
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success!\n\n";
} else {
echo "Failure...\n\n";
}
echo "Operations -- \n";
echo " Push Several Handlers -> ";
$handler = null;
try {
$handler = new Event\Handler(
null,
function ($e) {echo " 2\n";},
null,
2,
array('strict' => true)
);
$queue->push($handler);
$handler = new Event\Handler(
null,
function ($e) {echo " 1\n";},
null,
1,
array('strict' => true)
);
$queue->push($handler);
$handler = new Event\Handler(
null,
function ($e) {echo " 0\n";},
null,
0,
array('strict' => true)
);
$queue->push($handler);
$handler = new Event\Handler(
null,
function ($e) {echo " A\n";},
null,
1.5,
array('strict' => true)
);
$queue->push($handler);
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success!\n";
} else {
echo "Failure...\n";
}
echo " Fire! -> \n";
$success = true;
$publisher = $event = null;
try {
$publisher = new Patterns\Publisher();
$publisher->attachListener($queue);
$event = new Event\GenericEvent(
null,
null,
null,
null
);
$publisher->setState($event);
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success!\n\n";
} else {
echo "Failure...\n\n";
}
|