aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2017-08-29 17:01:35 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2017-08-29 17:01:35 +0200
commit76ddd85f055ffac9364957b0f4ca8a5310029cee (patch)
tree5723233e529a15856427f0b6f5452e5b79f84eff
parentb305147568a30ac64c2429107fc022008e327974 (diff)
downloadEvent-76ddd85f055ffac9364957b0f4ca8a5310029cee.zip
Event-76ddd85f055ffac9364957b0f4ca8a5310029cee.tar.gz
Event-76ddd85f055ffac9364957b0f4ca8a5310029cee.tar.bz2
chore(php) Move to PHP 7.
-rw-r--r--Source/Bucket.php49
-rw-r--r--Source/Event.php97
-rw-r--r--Source/Exception.php9
-rw-r--r--Source/Listenable.php15
-rw-r--r--Source/Listener.php65
-rw-r--r--Source/Listens.php32
-rw-r--r--Source/Source.php7
-rw-r--r--Test/Unit/Bucket.php19
-rw-r--r--Test/Unit/Event.php70
-rw-r--r--Test/Unit/Exception.php11
-rw-r--r--Test/Unit/Listenable.php11
-rw-r--r--Test/Unit/Listener.php43
-rw-r--r--Test/Unit/Listens.php15
-rw-r--r--Test/Unit/Source.php11
14 files changed, 157 insertions, 297 deletions
diff --git a/Source/Bucket.php b/Source/Bucket.php
index 968350d..d9972fb 100644
--- a/Source/Bucket.php
+++ b/Source/Bucket.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -37,35 +39,24 @@
namespace Hoa\Event;
/**
- * Class \Hoa\Event\Bucket.
- *
* This class is the object which is transmit through event channels.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Bucket
{
/**
- * Source object.
- *
- * @var \Hoa\Event\Source
+ * The source object (must be of kind `Hoa\Event\Source`).
*/
protected $_source = null;
/**
- * Data.
- *
- * @var mixed
+ * Data attached to the bucket.
*/
protected $_data = null;
/**
- * Set data.
- *
- * @param mixed $data Data.
+ * Allocates a new bucket with various data attached to it.
*/
public function __construct($data = null)
{
@@ -75,24 +66,17 @@ class Bucket
}
/**
- * Send this object on the event channel.
- *
- * @param string $eventId Event ID.
- * @param \Hoa\Event\Source $source Source.
- * @return void
+ * Sends this object on the event channel.
*/
- public function send($eventId, Source $source)
+ public function send(string $eventId, Source $source)
{
return Event::notify($eventId, $source, $this);
}
/**
- * Set source.
- *
- * @param \Hoa\Event\Source $source Source.
- * @return \Hoa\Event\Source
+ * Sets a new source.
*/
- public function setSource(Source $source)
+ public function setSource(Source $source): ?Source
{
$old = $this->_source;
$this->_source = $source;
@@ -101,20 +85,15 @@ class Bucket
}
/**
- * Get source.
- *
- * @return \Hoa\Event\Source
+ * Returns the source.
*/
- public function getSource()
+ public function getSource(): ?Source
{
return $this->_source;
}
/**
- * Set data.
- *
- * @param mixed $data Data.
- * @return mixed
+ * Sets new data.
*/
public function setData($data)
{
@@ -125,9 +104,7 @@ class Bucket
}
/**
- * Get data.
- *
- * @return mixed
+ * Returns the data.
*/
public function getData()
{
diff --git a/Source/Event.php b/Source/Event.php
index 23b3292..b4776ef 100644
--- a/Source/Event.php
+++ b/Source/Event.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -39,43 +41,30 @@ namespace Hoa\Event;
use Hoa\Consistency;
/**
- * Class \Hoa\Event\Event.
- *
* Events are asynchronous at registration, anonymous at use (until we
* receive a bucket) and useful to largely spread data through components
* without any known connection between them.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Event
{
/**
* Event ID key.
- *
- * @const int
*/
- const KEY_EVENT = 0;
+ public const KEY_EVENT = 0;
/**
* Source object key.
- *
- * @const int
*/
- const KEY_SOURCE = 1;
+ public const KEY_SOURCE = 1;
/**
- * Static register of all observable objects, i.e. \Hoa\Event\Source
+ * Static register of all observable objects, i.e. `Hoa\Event\Source`
* object, i.e. object that can send event.
- *
- * @var array
*/
private static $_register = [];
/**
- * Callables, i.e. observer objects.
- *
- * @var array
+ * Collection of callables, i.e. observer objects.
*/
protected $_callable = [];
@@ -83,7 +72,6 @@ class Event
/**
* Privatize the constructor.
- *
*/
private function __construct()
{
@@ -93,11 +81,8 @@ class Event
/**
* Manage multiton of events, with the principle of asynchronous
* attachments.
- *
- * @param string $eventId Event ID.
- * @return \Hoa\Event\Event
*/
- public static function getEvent($eventId)
+ public static function getEvent(string $eventId): Event
{
if (!isset(self::$_register[$eventId][self::KEY_EVENT])) {
self::$_register[$eventId] = [
@@ -110,15 +95,10 @@ class Event
}
/**
- * Declare a new object in the observable collection.
- * Note: Hoa's libraries use hoa://Event/AnID for their observable objects;
- *
- * @param string $eventId Event ID.
- * @param \Hoa\Event\Source|string $source Observable object or class.
- * @return void
- * @throws \Hoa\Event\Exception
+ * Declares a new object in the observable collection.
+ * Note: Hoa's libraries use `hoa://Event/anID` for their observable objects.
*/
- public static function register($eventId, $source)
+ public static function register(string $eventId, /*Source|string*/ $source): void
{
if (true === self::eventExists($eventId)) {
throw new Exception(
@@ -154,38 +134,30 @@ class Event
}
self::$_register[$eventId][self::KEY_SOURCE] = $source;
-
- return;
}
/**
- * Undeclare an object in the observable collection.
+ * Undeclares an object in the observable collection.
*
- * @param string $eventId Event ID.
- * @param bool $hard If false, just delete the source, else,
- * delete source and attached callables.
- * @return void
+ * If `$hard` is set to `true, then the source and its attached callables
+ * will be deleted.
*/
- public static function unregister($eventId, $hard = false)
+ public static function unregister(string $eventId, bool $hard = false): void
{
if (false !== $hard) {
unset(self::$_register[$eventId]);
} else {
self::$_register[$eventId][self::KEY_SOURCE] = null;
}
-
- return;
}
/**
* Attach an object to an event.
- * It can be a callable or an accepted callable form (please, see the
- * \Hoa\Consistency\Xcallable class).
*
- * @param mixed $callable Callable.
- * @return \Hoa\Event\Event
+ * It can be a callable or an accepted callable form (please, see the
+ * `Hoa\Consistency\Xcallable` class).
*/
- public function attach($callable)
+ public function attach($callable): self
{
$callable = xcallable($callable);
$this->_callable[$callable->getHash()] = $callable;
@@ -194,13 +166,11 @@ class Event
}
/**
- * Detach an object to an event.
- * Please see $this->attach() method.
+ * Detaches an object to an event.
*
- * @param mixed $callable Callable.
- * @return \Hoa\Event\Event
+ * Please see `self::attach` method.
*/
- public function detach($callable)
+ public function detach($callable): self
{
unset($this->_callable[xcallable($callable)->getHash()]);
@@ -208,25 +178,17 @@ class Event
}
/**
- * Check if at least one callable is attached to an event.
- *
- * @return bool
+ * Checks if at least one callable is attached to an event.
*/
- public function isListened()
+ public function isListened(): bool
{
return !empty($this->_callable);
}
/**
- * Notify, i.e. send data to observers.
- *
- * @param string $eventId Event ID.
- * @param \Hoa\Event\Source $source Source.
- * @param \Hoa\Event\Bucket $data Data.
- * @return void
- * @throws \Hoa\Event\Exception
+ * Notifies, i.e. send data to observers.
*/
- public static function notify($eventId, Source $source, Bucket $data)
+ public static function notify(string $eventId, Source $source, Bucket $data): void
{
if (false === self::eventExists($eventId)) {
throw new Exception(
@@ -242,17 +204,12 @@ class Event
foreach ($event->_callable as $callable) {
$callable($data);
}
-
- return;
}
/**
- * Check whether an event exists.
- *
- * @param string $eventId Event ID.
- * @return bool
+ * Checks whether an event exists.
*/
- public static function eventExists($eventId)
+ public static function eventExists(string $eventId): bool
{
return
array_key_exists($eventId, self::$_register) &&
@@ -263,4 +220,4 @@ class Event
/**
* Flex entity.
*/
-Consistency::flexEntity('Hoa\Event\Event');
+Consistency::flexEntity(Event::class);
diff --git a/Source/Exception.php b/Source/Exception.php
index 94b92f7..e71ae16 100644
--- a/Source/Exception.php
+++ b/Source/Exception.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -39,12 +41,7 @@ namespace Hoa\Event;
use Hoa\Exception as HoaException;
/**
- * Class \Hoa\Event\Exception.
- *
- * Extending the \Hoa\Exception\Exception class.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
+ * Extending the `Hoa\Exception\Exception` class.
*/
class Exception extends HoaException
{
diff --git a/Source/Listenable.php b/Source/Listenable.php
index 3fa5a70..255b34c 100644
--- a/Source/Listenable.php
+++ b/Source/Listenable.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -37,21 +39,12 @@
namespace Hoa\Event;
/**
- * Interface \Hoa\Event\Listenable.
- *
* Each object which is listenable must implement this interface.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
interface Listenable extends Source
{
/**
- * Attach a callable to a listenable component.
- *
- * @param string $listenerId Listener ID.
- * @param mixed $callable Callable.
- * @return \Hoa\Event\Listenable
+ * Attaches a callable to a listenable component.
*/
- public function on($listenerId, $callable);
+ public function on(string $listenerId, $callable): Listenable;
}
diff --git a/Source/Listener.php b/Source/Listener.php
index 2cc8adc..4669171 100644
--- a/Source/Listener.php
+++ b/Source/Listener.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -37,27 +39,18 @@
namespace Hoa\Event;
/**
- * Class \Hoa\Event\Listener.
- *
* A contrario of events, listeners are synchronous, identified at use and
* useful for close interactions between one or some components.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Listener
{
/**
- * Source of listener (for Bucket).
- *
- * @var \Hoa\Event\Listenable
+ * Source of listener (for `Hoa\Event\Bucket`).
*/
protected $_source = null;
/**
* All listener IDs and associated listeners.
- *
- * @var array
*/
protected $_callables = [];
@@ -65,9 +58,6 @@ class Listener
/**
* Build a listener.
- *
- * @param \Hoa\Event\Listenable $source Source (for Bucket).
- * @param array $ids Accepted ID.
*/
public function __construct(Listenable $source, array $ids)
{
@@ -78,29 +68,19 @@ class Listener
}
/**
- * Add acceptable ID (or reset).
- *
- * @param array $ids Accepted ID.
- * @return void
+ * Adds acceptable ID (or reset).
*/
- public function addIds(array $ids)
+ public function addIds(array $ids): void
{
foreach ($ids as $id) {
$this->_callables[$id] = [];
}
-
- return;
}
/**
- * Attach a callable to a listenable component.
- *
- * @param string $listenerId Listener ID.
- * @param mixed $callable Callable.
- * @return \Hoa\Event\Listener
- * @throws \Hoa\Event\Exception
+ * Attaches a callable to a listenable component.
*/
- public function attach($listenerId, $callable)
+ public function attach(string $listenerId, $callable): self
{
if (false === $this->listenerExists($listenerId)) {
throw new Exception(
@@ -117,13 +97,9 @@ class Listener
}
/**
- * Detach a callable from a listenable component.
- *
- * @param string $listenerId Listener ID.
- * @param mixed $callable Callable.
- * @return \Hoa\Event\Listener
+ * Detaches a callable from a listenable component.
*/
- public function detach($listenerId, $callable)
+ public function detach(string $listenerId, $callable): self
{
unset($this->_callables[$listenerId][xcallable($callable)->getHash()]);
@@ -131,12 +107,9 @@ class Listener
}
/**
- * Detach all callables from a listenable component.
- *
- * @param string $listenerId Listener ID.
- * @return \Hoa\Event\Listener
+ * Detaches all callables from a listenable component.
*/
- public function detachAll($listenerId)
+ public function detachAll(string $listenerId): self
{
unset($this->_callables[$listenerId]);
@@ -144,25 +117,17 @@ class Listener
}
/**
- * Check if a listener exists.
- *
- * @param string $listenerId Listener ID.
- * @return bool
+ * Checks if a listener exists.
*/
- public function listenerExists($listenerId)
+ public function listenerExists(string $listenerId): bool
{
return array_key_exists($listenerId, $this->_callables);
}
/**
- * Send/fire a bucket to a listener.
- *
- * @param string $listenerId Listener ID.
- * @param \Hoa\Event\Bucket $data Data.
- * @return array
- * @throws \Hoa\Event\Exception
+ * Sends/fires a bucket to a listener.
*/
- public function fire($listenerId, Bucket $data)
+ public function fire(string $listenerId, Bucket $data): array
{
if (false === $this->listenerExists($listenerId)) {
throw new Exception(
diff --git a/Source/Listens.php b/Source/Listens.php
index 83f6223..5988547 100644
--- a/Source/Listens.php
+++ b/Source/Listens.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -37,32 +39,21 @@
namespace Hoa\Event;
/**
- * Trait \Hoa\Event\Listens.
- *
* Implementation of a listener.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
trait Listens
{
/**
- * Listener instance.
- *
- * @var \Hoa\Event\Listener
+ * Listener instance of type `Hoa\Event\Listener`.
*/
protected $_listener = null;
/**
- * Attach a callable to a listenable component.
- *
- * @param string $listenerId Listener ID.
- * @param mixed $callable Callable.
- * @return \Hoa\Event\Listenable
+ * Attaches a callable to a listenable component.
*/
- public function on($listenerId, $callable)
+ public function on(string $listenerId, $callable): Listenable
{
$listener = $this->getListener();
@@ -81,12 +72,9 @@ trait Listens
}
/**
- * Set listener.
- *
- * @param \Hoa\Event\Listener $listener Listener.
- * @return \Hoa\Event\Listener
+ * Sets a new listener.
*/
- protected function setListener(Listener $listener)
+ protected function setListener(Listener $listener): ?Listener
{
$old = $this->_listener;
$this->_listener = $listener;
@@ -95,11 +83,9 @@ trait Listens
}
/**
- * Get listener.
- *
- * @return \Hoa\Event\Listener
+ * Returns the listener.
*/
- protected function getListener()
+ protected function getListener(): ?Listener
{
return $this->_listener;
}
diff --git a/Source/Source.php b/Source/Source.php
index d1510ca..201317a 100644
--- a/Source/Source.php
+++ b/Source/Source.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -37,12 +39,7 @@
namespace Hoa\Event;
/**
- * Interface \Hoa\Event\Source.
- *
* Each object which is listenable must implement this interface.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
interface Source
{
diff --git a/Test/Unit/Bucket.php b/Test/Unit/Bucket.php
index 0947bc2..aa7cee5 100644
--- a/Test/Unit/Bucket.php
+++ b/Test/Unit/Bucket.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -41,27 +43,22 @@ use Hoa\Event\Bucket as SUT;
use Hoa\Test;
/**
- * Class \Hoa\Event\Test\Unit\Bucket.
- *
* Test suite of the bucket.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Bucket extends Test\Unit\Suite
{
- public function case_constructor()
+ public function case_constructor(): void
{
$this
->when($result = new SUT('foo'))
->then
->object($result)
- ->isInstanceOf('Hoa\Event\Bucket')
+ ->isInstanceOf(SUT::class)
->string($result->getData())
->isEqualTo('foo');
}
- public function case_send()
+ public function case_send(): void
{
$self = $this;
@@ -74,7 +71,7 @@ class Bucket extends Test\Unit\Suite
$bucket = new SUT('foo'),
LUT::getEvent($eventId)->attach(
- function (SUT $receivedBucket) use ($self, $bucket, &$called) {
+ function (SUT $receivedBucket) use ($self, $bucket, &$called): void {
$called = true;
$self
@@ -91,7 +88,7 @@ class Bucket extends Test\Unit\Suite
->isTrue();
}
- public function case_set_source()
+ public function case_set_source(): void
{
$this
->given(
@@ -114,7 +111,7 @@ class Bucket extends Test\Unit\Suite
->isIdenticalTo($sourceB);
}
- public function case_set_data()
+ public function case_set_data(): void
{
$this
->given(
diff --git a/Test/Unit/Event.php b/Test/Unit/Event.php
index daf03eb..14ca2c2 100644
--- a/Test/Unit/Event.php
+++ b/Test/Unit/Event.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -41,28 +43,23 @@ use Hoa\Event\Event as SUT;
use Hoa\Test;
/**
- * Class \Hoa\Event\Test\Unit\Event.
- *
* Test suite of the event class.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Event extends Test\Unit\Suite
{
- public function case_multiton()
+ public function case_multiton(): void
{
$this
->given($eventId = 'hoa://Event/Test')
->when($result = SUT::getEvent($eventId))
->then
->object($result)
- ->isInstanceOf('Hoa\Event\Event')
+ ->isInstanceOf(SUT::class)
->object(SUT::getEvent($eventId))
->isIdenticalTo($result);
}
- public function case_register_source_instance()
+ public function case_register_source_instance(): void
{
$this
->given(
@@ -77,7 +74,7 @@ class Event extends Test\Unit\Suite
->isTrue();
}
- public function case_register_source_name()
+ public function case_register_source_name(): void
{
$this
->given(
@@ -92,7 +89,7 @@ class Event extends Test\Unit\Suite
->isTrue();
}
- public function case_register_redeclare()
+ public function case_register_redeclare(): void
{
$this
->given(
@@ -100,39 +97,39 @@ class Event extends Test\Unit\Suite
$source = new \Mock\Hoa\Event\Source(),
SUT::register($eventId, $source)
)
- ->exception(function () use ($eventId, $source) {
+ ->exception(function () use ($eventId, $source): void {
SUT::register($eventId, $source);
})
- ->isInstanceOf('Hoa\Event\Exception');
+ ->isInstanceOf(LUT\Exception::class);
}
- public function case_register_not_a_source_instance()
+ public function case_register_not_a_source_instance(): void
{
$this
->given(
$eventId = 'hoa://Event/Test',
$source = new \StdClass()
)
- ->exception(function () use ($eventId, $source) {
+ ->exception(function () use ($eventId, $source): void {
$result = SUT::register($eventId, $source);
})
- ->isInstanceOf('Hoa\Event\Exception');
+ ->isInstanceOf(LUT\Exception::class);
}
- public function case_register_not_a_source_name()
+ public function case_register_not_a_source_name(): void
{
$this
->given(
$eventId = 'hoa://Event/Test',
$source = 'StdClass'
)
- ->exception(function () use ($eventId, $source) {
+ ->exception(function () use ($eventId, $source): void {
$result = SUT::register($eventId, $source);
})
- ->isInstanceOf('Hoa\Event\Exception');
+ ->isInstanceOf(LUT\Exception::class);
}
- public function case_unregister()
+ public function case_unregister(): void
{
$this
->given(
@@ -146,7 +143,7 @@ class Event extends Test\Unit\Suite
->isFalse();
}
- public function case_unregister_hard()
+ public function case_unregister_hard(): void
{
$this
->given(
@@ -163,7 +160,7 @@ class Event extends Test\Unit\Suite
->isNotIdenticalTo($event);
}
- public function case_unregister_not_registered()
+ public function case_unregister_not_registered(): void
{
$this
->given($eventId = 'hoa://Event/Test')
@@ -173,12 +170,13 @@ class Event extends Test\Unit\Suite
->isNull();
}
- public function case_attach()
+ public function case_attach(): void
{
$this
->given(
$event = SUT::getEvent('hoa://Event/Test'),
- $callable = function () { }
+ $callable = function (): void {
+ }
)
->when($result = $event->attach($callable))
->then
@@ -188,12 +186,13 @@ class Event extends Test\Unit\Suite
->isTrue();
}
- public function case_detach()
+ public function case_detach(): void
{
$this
->given(
$event = SUT::getEvent('hoa://Event/Test'),
- $callable = function () { },
+ $callable = function (): void {
+ },
$event->attach($callable)
)
->when($result = $event->detach($callable))
@@ -204,12 +203,13 @@ class Event extends Test\Unit\Suite
->isFalse();
}
- public function case_detach_unattached()
+ public function case_detach_unattached(): void
{
$this
->given(
$event = SUT::getEvent('hoa://Event/Test'),
- $callable = function () { }
+ $callable = function (): void {
+ }
)
->when($result = $event->detach($callable))
->then
@@ -219,7 +219,7 @@ class Event extends Test\Unit\Suite
->isFalse();
}
- public function case_is_listened()
+ public function case_is_listened(): void
{
$this
->given($event = SUT::getEvent('hoa://Event/Test'))
@@ -229,7 +229,7 @@ class Event extends Test\Unit\Suite
->isFalse();
}
- public function case_notify()
+ public function case_notify(): void
{
$self = $this;
@@ -241,7 +241,7 @@ class Event extends Test\Unit\Suite
SUT::register($eventId, $source),
SUT::getEvent($eventId)->attach(
- function (LUT\Bucket $receivedBucket) use ($self, $source, $bucket, &$called) {
+ function (LUT\Bucket $receivedBucket) use ($self, $source, $bucket, &$called): void {
$called = true;
$this
@@ -260,7 +260,7 @@ class Event extends Test\Unit\Suite
->isTrue();
}
- public function case_notify_unregistered_event_id()
+ public function case_notify_unregistered_event_id(): void
{
$this
->given(
@@ -268,13 +268,13 @@ class Event extends Test\Unit\Suite
$source = new \Mock\Hoa\Event\Source(),
$data = new LUT\Bucket()
)
- ->exception(function () use ($eventId, $source, $data) {
+ ->exception(function () use ($eventId, $source, $data): void {
SUT::notify($eventId, $source, $data);
})
- ->isInstanceOf('Hoa\Event\Exception');
+ ->isInstanceOf(LUT\Exception::class);
}
- public function case_event_exists()
+ public function case_event_exists(): void
{
$this
->given(
@@ -288,7 +288,7 @@ class Event extends Test\Unit\Suite
->isTrue();
}
- public function case_event_not_exists()
+ public function case_event_not_exists(): void
{
$this
->given($eventId = 'hoa://Event/Test')
diff --git a/Test/Unit/Exception.php b/Test/Unit/Exception.php
index e24f4af..8f030d7 100644
--- a/Test/Unit/Exception.php
+++ b/Test/Unit/Exception.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -40,21 +42,16 @@ use Hoa\Event\Exception as SUT;
use Hoa\Test;
/**
- * Class \Hoa\Event\Test\Unit\Exception.
- *
* Test suite of the exception.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Exception extends Test\Unit\Suite
{
- public function case_hoa_exception()
+ public function case_hoa_exception(): void
{
$this
->when($result = new SUT('foo', 0))
->then
->object($result)
- ->isInstanceOf('Hoa\Exception\Exception');
+ ->isInstanceOf(SUT::class);
}
}
diff --git a/Test/Unit/Listenable.php b/Test/Unit/Listenable.php
index 4ba1ca2..98407a6 100644
--- a/Test/Unit/Listenable.php
+++ b/Test/Unit/Listenable.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -39,21 +41,16 @@ namespace Hoa\Event\Test\Unit;
use Hoa\Test;
/**
- * Class \Hoa\Event\Test\Unit\Listenable.
- *
* Test suite of the listenable interface.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Listenable extends Test\Unit\Suite
{
- public function case_interface()
+ public function case_interface(): void
{
$this
->when($result = new \Mock\Hoa\Event\Listenable())
->then
->object($result)
- ->isInstanceOf('Hoa\Event\Listenable');
+ ->isInstanceOf(\Hoa\Event\Listenable::class);
}
}
diff --git a/Test/Unit/Listener.php b/Test/Unit/Listener.php
index 8216302..4997d11 100644
--- a/Test/Unit/Listener.php
+++ b/Test/Unit/Listener.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -41,16 +43,11 @@ use Hoa\Event\Listener as SUT;
use Hoa\Test;
/**
- * Class \Hoa\Event\Test\Unit\Listener.
- *
* Test suite of the listener.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Listener extends Test\Unit\Suite
{
- public function case_constructor()
+ public function case_constructor(): void
{
$this
->given(
@@ -60,7 +57,7 @@ class Listener extends Test\Unit\Suite
->when($result = new SUT($source, $ids))
->then
->object($result)
- ->isInstanceOf('Hoa\Event\Listener')
+ ->isInstanceOf(SUT::class)
->boolean($result->listenerExists('foo'))
->isTrue()
->boolean($result->listenerExists('bar'))
@@ -69,7 +66,7 @@ class Listener extends Test\Unit\Suite
->isTrue();
}
- public function case_attach()
+ public function case_attach(): void
{
$this
->given(
@@ -88,22 +85,23 @@ class Listener extends Test\Unit\Suite
->isEqualTo([42]);
}
- public function case_attach_to_an_undefined_listener()
+ public function case_attach_to_an_undefined_listener(): void
{
$this
->given(
$source = new \Mock\Hoa\Event\Listenable(),
$listenerId = 'bar',
$listener = new SUT($source, ['foo', 'baz']),
- $callable = function () { }
+ $callable = function (): void {
+ }
)
- ->exception(function () use ($listener, $listenerId, $callable) {
+ ->exception(function () use ($listener, $listenerId, $callable): void {
$listener->attach($listenerId, $callable);
})
- ->isInstanceOf('Hoa\Event\Exception');
+ ->isInstanceOf(LUT\Exception::class);
}
- public function case_detach()
+ public function case_detach(): void
{
$this
->given(
@@ -123,14 +121,15 @@ class Listener extends Test\Unit\Suite
->isEmpty();
}
- public function case_detach_an_undefined_listener()
+ public function case_detach_an_undefined_listener(): void
{
$this
->given(
$source = new \Mock\Hoa\Event\Listenable(),
$listenerId = 'bar',
$listener = new SUT($source, ['foo', 'baz']),
- $callable = function () { }
+ $callable = function (): void {
+ }
)
->when($result = $listener->detach($listenerId, $callable))
->then
@@ -138,7 +137,7 @@ class Listener extends Test\Unit\Suite
->isIdenticalTo($listener);
}
- public function case_detach_all()
+ public function case_detach_all(): void
{
$this
->given(
@@ -154,7 +153,7 @@ class Listener extends Test\Unit\Suite
->isFalse();
}
- public function case_detach_all_with_an_undefined_listener()
+ public function case_detach_all_with_an_undefined_listener(): void
{
$this
->given(
@@ -168,7 +167,7 @@ class Listener extends Test\Unit\Suite
->isIdenticalTo($listener);
}
- public function case_listener_exists()
+ public function case_listener_exists(): void
{
$this
->given(
@@ -189,7 +188,7 @@ class Listener extends Test\Unit\Suite
->isTrue();
}
- public function case_fire()
+ public function case_fire(): void
{
$self = $this;
@@ -224,7 +223,7 @@ class Listener extends Test\Unit\Suite
->isTrue();
}
- public function case_fire_an_undefined_listenerId()
+ public function case_fire_an_undefined_listenerId(): void
{
$this
->given(
@@ -232,9 +231,9 @@ class Listener extends Test\Unit\Suite
$ids = [],
$listener = new SUT($source, $ids)
)
- ->exception(function () use ($listener) {
+ ->exception(function () use ($listener): void {
$listener->fire('foo', new LUT\Bucket());
})
- ->isInstanceOf('Hoa\Event\Exception');
+ ->isInstanceOf(LUT\Exception::class);
}
}
diff --git a/Test/Unit/Listens.php b/Test/Unit/Listens.php
index 8978c82..627c1e2 100644
--- a/Test/Unit/Listens.php
+++ b/Test/Unit/Listens.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -45,12 +47,11 @@ use Hoa\Test;
*
* Test suite of the listens trait.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Listens extends Test\Unit\Suite
{
- public function case_set_listener()
+ public function case_set_listener(): void
{
$this
->given(
@@ -63,7 +64,7 @@ class Listens extends Test\Unit\Suite
->isNull();
}
- public function case_get_listener()
+ public function case_get_listener(): void
{
$this
->given(
@@ -77,7 +78,7 @@ class Listens extends Test\Unit\Suite
->isIdenticalTo($listener);
}
- public function case_on()
+ public function case_on(): void
{
$this
->given(
@@ -101,7 +102,7 @@ class Listens extends Test\Unit\Suite
->isTrue();
}
- public function case_on_unregistered_listener()
+ public function case_on_unregistered_listener(): void
{
$this
->given(
@@ -109,7 +110,7 @@ class Listens extends Test\Unit\Suite
$listener = new LUT\Listener($listenable, ['foo']),
$listenable->_setListener($listener)
)
- ->exception(function () use ($listenable) {
+ ->exception(function () use ($listenable): void {
$listenable->on('bar', null);
})
->isInstanceOf('Hoa\Event\Exception');
@@ -130,7 +131,7 @@ class _Listenable implements LUT\Listenable
return $this->getListener();
}
- public function doSomethingThatFires()
+ public function doSomethingThatFires(): void
{
$this->getListener()->fire('foo', new LUT\Bucket('bar'));
diff --git a/Test/Unit/Source.php b/Test/Unit/Source.php
index 1d41880..1630b2f 100644
--- a/Test/Unit/Source.php
+++ b/Test/Unit/Source.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -39,21 +41,16 @@ namespace Hoa\Event\Test\Unit;
use Hoa\Test;
/**
- * Class \Hoa\Event\Test\Unit\Source.
- *
* Test suite of the source interface.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Source extends Test\Unit\Suite
{
- public function case_interface()
+ public function case_interface(): void
{
$this
->when($result = new \Mock\Hoa\Event\Source())
->then
->object($result)
- ->isInstanceOf('Hoa\Event\Source');
+ ->isInstanceOf(\Hoa\Event\Source::class);
}
}