aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2017-08-29 16:41:21 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2017-08-29 16:41:21 +0200
commit897c9f9fe31d2a6e0acdc7a26f63fc39c7786f2f (patch)
tree7ec497645fa208c9a1b700a044b923ca1dd1c4ee
parent94635bc20ad9e34f551e9d7bc39eaac4461d3c82 (diff)
downloadException-897c9f9fe31d2a6e0acdc7a26f63fc39c7786f2f.zip
Exception-897c9f9fe31d2a6e0acdc7a26f63fc39c7786f2f.tar.gz
Exception-897c9f9fe31d2a6e0acdc7a26f63fc39c7786f2f.tar.bz2
chore(php) Move to PHP 7 and rewrite the doc.
-rw-r--r--Source/Error.php32
-rw-r--r--Source/Exception.php37
-rw-r--r--Source/Group.php98
-rw-r--r--Source/Idle.php116
-rw-r--r--Test/Unit/Error.php15
-rw-r--r--Test/Unit/Exception.php11
-rw-r--r--Test/Unit/Group.php84
-rw-r--r--Test/Unit/Idle.php44
8 files changed, 175 insertions, 262 deletions
diff --git a/Source/Error.php b/Source/Error.php
index 898aaf8..57e8fb2 100644
--- a/Source/Error.php
+++ b/Source/Error.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -37,29 +39,18 @@
namespace Hoa\Exception;
/**
- * Class \Hoa\Exception\Error.
- *
* This exception is the equivalent representation of PHP errors.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Error extends Exception
{
/**
- * Constructor.
- *
- * @param string $message Message.
- * @param int $code Code (the ID).
- * @param string $file File.
- * @param int $line Line.
- * @param array $trace Trace.
+ * Allocate a new error exception.
*/
public function __construct(
- $message,
- $code,
- $file,
- $line,
+ string $message,
+ int $code,
+ string $file,
+ int $line,
array $trace = []
) {
$this->file = $file;
@@ -72,19 +63,16 @@ class Error extends Exception
}
/**
- * Enable error handler: Transform PHP error into `\Hoa\Exception\Error`.
- *
- * @param bool $enable Enable.
- * @return mixed
+ * Enables error handler: Transforms a PHP error into a `Hoa\Exception\Error` instance.
*/
- public static function enableErrorHandler($enable = true)
+ public static function enableErrorHandler(bool $enable = true)
{
if (false === $enable) {
return restore_error_handler();
}
return set_error_handler(
- function ($no, $str, $file = null, $line = null, $ctx = null) {
+ function ($no, $str, $file = null, $line = null, $ctx = null): void {
if (0 === ($no & error_reporting())) {
return;
}
diff --git a/Source/Exception.php b/Source/Exception.php
index 23f95fb..54d0dce 100644
--- a/Source/Exception.php
+++ b/Source/Exception.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -40,31 +42,22 @@ use Hoa\Consistency;
use Hoa\Event;
/**
- * Class \Hoa\Exception\Exception.
- *
- * Each exception must extend \Hoa\Exception\Exception.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
+ * Each exception must extend `Hoa\Exception\Exception`.
*/
class Exception extends Idle implements Event\Source
{
/**
- * Create an exception.
+ * Allocates a new exception.
+ *
* An exception is built with a formatted message, a code (an ID), and an
* array that contains the list of formatted string for the message. If
- * chaining, we can add a previous exception.
- *
- * @param string $message Formatted message.
- * @param int $code Code (the ID).
- * @param array $arguments Arguments to format message.
- * @param \Throwable $previous Previous exception in chaining.
+ * chaining, a previous exception can be added.
*/
public function __construct(
- $message,
- $code = 0,
- $arguments = [],
- $previous = null
+ string $message,
+ int $code = 0,
+ array $arguments = [],
+ \Throwable $previous = null
) {
parent::__construct($message, $code, $arguments, $previous);
@@ -78,23 +71,19 @@ class Exception extends Idle implements Event\Source
}
/**
- * Send the exception on hoa://Event/Exception.
- *
- * @return void
+ * Sends the exception on `hoa://Event/Exception`.
*/
- public function send()
+ public function send(): void
{
Event::notify(
'hoa://Event/Exception',
$this,
new Event\Bucket($this)
);
-
- return;
}
}
/**
* Flex entity.
*/
-Consistency::flexEntity('Hoa\Exception\Exception');
+Consistency::flexEntity(Exception::class);
diff --git a/Source/Group.php b/Source/Group.php
index e5dee37..a1c9898 100644
--- a/Source/Group.php
+++ b/Source/Group.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -37,36 +39,24 @@
namespace Hoa\Exception;
/**
- * Class \Hoa\Exception\Group.
- *
- * This is an exception that contains a group of exceptions.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
+ * An exception that contains a group of exceptions.
*/
class Group extends Exception implements \ArrayAccess, \IteratorAggregate, \Countable
{
/**
- * All exceptions (stored in a stack for transactions).
- *
- * @var \SplStack
+ * All stack of exceptions.
*/
protected $_group = null;
/**
- * Create an exception.
- *
- * @param string $message Formatted message.
- * @param int $code Code (the ID).
- * @param array $arguments Arguments to format message.
- * @param \Exception $previous Previous exception in chaining.
+ * Allocates a new exception.
*/
public function __construct(
- $message,
- $code = 0,
- $arguments = [],
+ string $message,
+ int $code = 0,
+ array $arguments = [],
\Exception $previous = null
) {
parent::__construct($message, $code, $arguments, $previous);
@@ -77,14 +67,11 @@ class Group extends Exception implements \ArrayAccess, \IteratorAggregate, \Coun
}
/**
- * Raise an exception as a string.
- *
- * @param bool $previous Whether raise previous exception if exists.
- * @return string
+ * Raises an exception as a string.
*/
- public function raise($previous = false)
+ public function raise(bool $includePrevious = false): string
{
- $out = parent::raise($previous);
+ $out = parent::raise($includePrevious);
if (0 >= count($this)) {
return $out;
@@ -98,7 +85,7 @@ class Group extends Exception implements \ArrayAccess, \IteratorAggregate, \Coun
str_replace(
"\n",
"\n" . ' ',
- $exception->raise($previous)
+ $exception->raise($includePrevious)
);
}
@@ -106,11 +93,9 @@ class Group extends Exception implements \ArrayAccess, \IteratorAggregate, \Coun
}
/**
- * Begin a transaction.
- *
- * @return \Hoa\Exception\Group
+ * Begins a transaction.
*/
- public function beginTransaction()
+ public function beginTransaction(): Group
{
$this->_group->push(new \ArrayObject());
@@ -118,11 +103,9 @@ class Group extends Exception implements \ArrayAccess, \IteratorAggregate, \Coun
}
/**
- * Rollback a transaction.
- *
- * @return \Hoa\Exception\Group
+ * Rollbacks a transaction.
*/
- public function rollbackTransaction()
+ public function rollbackTransaction(): Group
{
if (1 >= count($this->_group)) {
return $this;
@@ -134,11 +117,9 @@ class Group extends Exception implements \ArrayAccess, \IteratorAggregate, \Coun
}
/**
- * Commit a transaction.
- *
- * @return \Hoa\Exception\Group
+ * Commits a transaction.
*/
- public function commitTransaction()
+ public function commitTransaction(): Group
{
if (false === $this->hasUncommittedExceptions()) {
$this->_group->pop();
@@ -154,11 +135,9 @@ class Group extends Exception implements \ArrayAccess, \IteratorAggregate, \Coun
}
/**
- * Check if there is uncommitted exceptions.
- *
- * @return bool
+ * Checks if there is uncommitted exceptions.
*/
- public function hasUncommittedExceptions()
+ public function hasUncommittedExceptions(): bool
{
return
1 < count($this->_group) &&
@@ -166,12 +145,9 @@ class Group extends Exception implements \ArrayAccess, \IteratorAggregate, \Coun
}
/**
- * Check if an index in the group exists.
- *
- * @param mixed $index Index.
- * @return bool
+ * Checks if an index in the group exists.
*/
- public function offsetExists($index)
+ public function offsetExists($index): bool
{
foreach ($this->_group as $group) {
if (isset($group[$index])) {
@@ -183,12 +159,9 @@ class Group extends Exception implements \ArrayAccess, \IteratorAggregate, \Coun
}
/**
- * Get an exception from the group.
- *
- * @param mixed $index Index.
- * @return Exception
+ * Returns an exception from the group.
*/
- public function offsetGet($index)
+ public function offsetGet($index): ?Exception
{
foreach ($this->_group as $group) {
if (isset($group[$index])) {
@@ -200,11 +173,7 @@ class Group extends Exception implements \ArrayAccess, \IteratorAggregate, \Coun
}
/**
- * Set an exception in the group.
- *
- * @param mixed $index Index.
- * @param Exception $exception Exception.
- * @return void
+ * Sets an exception in the group.
*/
public function offsetSet($index, $exception)
{
@@ -225,20 +194,15 @@ class Group extends Exception implements \ArrayAccess, \IteratorAggregate, \Coun
}
/**
- * Remove an exception in the group.
- *
- * @param mixed $index Index.
- * @return void
+ * Removes an exception in the group.
*/
- public function offsetUnset($index)
+ public function offsetUnset($index): void
{
foreach ($this->_group as $group) {
if (isset($group[$index])) {
unset($group[$index]);
}
}
-
- return;
}
/**
@@ -246,7 +210,7 @@ class Group extends Exception implements \ArrayAccess, \IteratorAggregate, \Coun
*
* @return \ArrayObject
*/
- public function getExceptions()
+ public function getExceptions(): \ArrayObject
{
return $this->_group->bottom();
}
@@ -256,7 +220,7 @@ class Group extends Exception implements \ArrayAccess, \IteratorAggregate, \Coun
*
* @return \ArrayIterator
*/
- public function getIterator()
+ public function getIterator(): \ArrayIterator
{
return $this->getExceptions()->getIterator();
}
@@ -266,7 +230,7 @@ class Group extends Exception implements \ArrayAccess, \IteratorAggregate, \Coun
*
* @return int
*/
- public function count()
+ public function count(): int
{
return count($this->getExceptions());
}
@@ -276,7 +240,7 @@ class Group extends Exception implements \ArrayAccess, \IteratorAggregate, \Coun
*
* @return int
*/
- public function getStackSize()
+ public function getStackSize(): int
{
return count($this->_group);
}
diff --git a/Source/Idle.php b/Source/Idle.php
index a942354..623cb52 100644
--- a/Source/Idle.php
+++ b/Source/Idle.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -37,69 +39,50 @@
namespace Hoa\Exception;
/**
- * Class \Hoa\Exception\Idle.
- *
- * `\Hoa\Exception\Idle` is the mother exception class of libraries. The only
- * difference between `\Hoa\Exception\Idle` and its directly child
- * `\Hoa\Exception` is that the latter fires events after beeing constructed.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
+ * `Hoa\Exception\Idle` is the mother exception class of libraries. The only
+ * difference between `Hoa\Exception\Idle` and its direct children
+ * `Hoa\Exception` is that the latter fires events after beeing constructed.
*/
class Idle extends \Exception
{
/**
* Delay processing on arguments.
- *
- * @var array
*/
protected $_tmpArguments = null;
/**
- * Arguments to format message.
- *
- * @var array
+ * List of arguments to format message.
*/
protected $_arguments = null;
/**
* Backtrace.
- *
- * @var array
*/
protected $_trace = null;
/**
- * Previous.
- *
- * @var \Exception
+ * Previous exception if any.
*/
protected $_previous = null;
/**
- * Original message.
- *
- * @var string
+ * Original exception message.
*/
protected $_rawMessage = null;
/**
- * Create an exception.
+ * Allocates a new exception.
+ *
* An exception is built with a formatted message, a code (an ID) and an
* array that contains the list of formatted strings for the message. If
* chaining, we can add a previous exception.
- *
- * @param string $message Formatted message.
- * @param int $code Code (the ID).
- * @param array $arguments Arguments to format message.
- * @param \Exception $previous Previous exception in chaining.
*/
public function __construct(
- $message,
- $code = 0,
- $arguments = [],
+ string $message,
+ int $code = 0,
+ /* array|string */ $arguments = [],
\Exception $previous = null
) {
$this->_tmpArguments = $arguments;
@@ -111,12 +94,11 @@ class Idle extends \Exception
}
/**
- * Get the backtrace.
- * Do not use \Exception::getTrace() any more.
+ * Returns the backtrace.
*
- * @return array
+ * Do not use `Exception::getTrace` any more.
*/
- public function getBacktrace()
+ public function getBacktrace(): ?array
{
if (null === $this->_trace) {
$this->_trace = $this->getTrace();
@@ -126,12 +108,11 @@ class Idle extends \Exception
}
/**
- * Get previous.
- * Do not use \Exception::getPrevious() any more.
+ * Returns the previous exception if any.
*
- * @return \Exception
+ * Do not use `Exception::getPrevious` any more.
*/
- public function getPreviousThrow()
+ public function getPreviousThrow(): ?\Exception
{
if (null === $this->_previous) {
$this->_previous = $this->getPrevious();
@@ -141,11 +122,9 @@ class Idle extends \Exception
}
/**
- * Get arguments for the message.
- *
- * @return array
+ * Returns the arguments of the message.
*/
- public function getArguments()
+ public function getArguments(): ?array
{
if (null === $this->_arguments) {
$arguments = $this->_tmpArguments;
@@ -168,31 +147,25 @@ class Idle extends \Exception
}
/**
- * Get the raw message.
- *
- * @return string
+ * Returns the raw message.
*/
- public function getRawMessage()
+ public function getRawMessage(): string
{
return $this->_rawMessage;
}
/**
- * Get the message already formatted.
- *
- * @return string
+ * Returns the message already formatted.
*/
- public function getFormattedMessage()
+ public function getFormattedMessage(): string
{
return $this->getMessage();
}
/**
- * Get the source of the exception (class, method, function, main etc.).
- *
- * @return string
+ * Returns the source of the exception (class, method, function, main etc.).
*/
- public function getFrom()
+ public function getFrom(): string
{
$trace = $this->getBacktrace();
$from = '{main}';
@@ -214,12 +187,9 @@ class Idle extends \Exception
}
/**
- * Raise an exception as a string.
- *
- * @param bool $previous Whether raise previous exception if exists.
- * @return string
+ * Raises an exception as a string.
*/
- public function raise($previous = false)
+ public function raise(bool $includePrevious = false): string
{
$message = $this->getFormattedMessage();
$trace = $this->getBacktrace();
@@ -228,8 +198,8 @@ class Idle extends \Exception
$pre = $this->getFrom();
if (!empty($trace)) {
- $file = isset($trace['file']) ? $trace['file'] : null;
- $line = isset($trace['line']) ? $trace['line'] : null;
+ $file = $trace['file'] ?? null;
+ $line = $trace['line'] ?? null;
}
$pre .= ': ';
@@ -245,7 +215,7 @@ class Idle extends \Exception
'in ' . $file . ' around line ' . $line . '.';
}
- if (true === $previous &&
+ if (true === $includePrevious &&
null !== $previous = $this->getPreviousThrow()) {
$out .=
"\n\n" . ' ⬇' . "\n\n" .
@@ -259,13 +229,9 @@ class Idle extends \Exception
}
/**
- * Catch uncaught exception (only \Hoa\Exception\Idle and children).
- *
- * @param \Throwable $exception The exception.
- * @return void
- * @throws \Throwable
+ * Catches uncaught exception (only `Hoa\Exception\Idle` and children).
*/
- public static function uncaught($exception)
+ public static function uncaught(\Throwable $exception): void
{
if (!($exception instanceof self)) {
throw $exception;
@@ -278,28 +244,22 @@ class Idle extends \Exception
echo
'Uncaught exception (' . get_class($exception) . '):' . "\n" .
$exception->raise(true);
-
- return;
}
/**
* String representation of object.
- *
- * @return string
*/
- public function __toString()
+ public function __toString(): string
{
return $this->raise();
}
/**
- * Enable uncaught exception handler.
- * This is restricted to Hoa's exceptions only.
+ * Enables uncaught exception handler.
*
- * @param bool $enable Enable.
- * @return mixed
+ * This is restricted to Hoa's exceptions only.
*/
- public static function enableUncaughtHandler($enable = true)
+ public static function enableUncaughtHandler(bool $enable = true)
{
if (false === $enable) {
return restore_exception_handler();
diff --git a/Test/Unit/Error.php b/Test/Unit/Error.php
index e4f3702..5021e7a 100644
--- a/Test/Unit/Error.php
+++ b/Test/Unit/Error.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -44,12 +46,11 @@ use Hoa\Test;
*
* Test suite of the error class.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Error extends Test\Unit\Suite
{
- public function case_is_an_exception()
+ public function case_is_an_exception(): void
{
$this
->when($result = new SUT('foo', 42, '/hoa/flatland', 153))
@@ -58,7 +59,7 @@ class Error extends Test\Unit\Suite
->isInstanceOf('Hoa\Exception\Exception');
}
- public function case_get_message()
+ public function case_get_message(): void
{
$this
->given($exception = new SUT('foo', 42, '/hoa/flatland', 153))
@@ -71,7 +72,7 @@ class Error extends Test\Unit\Suite
);
}
- public function case_disable_error_handler()
+ public function case_disable_error_handler(): void
{
$this
->given(
@@ -89,7 +90,7 @@ class Error extends Test\Unit\Suite
->isTrue();
}
- public function case_enable_error_handler()
+ public function case_enable_error_handler(): void
{
$self = $this;
@@ -132,11 +133,11 @@ class Error extends Test\Unit\Suite
->isTrue();
}
- public function case_error_handler()
+ public function case_error_handler(): void
{
$this
->given(SUT::enableErrorHandler())
- ->exception(function () {
+ ->exception(function (): void {
++$i;
})
->isInstanceOf('Hoa\Exception\Error')
diff --git a/Test/Unit/Exception.php b/Test/Unit/Exception.php
index d5cb492..76461d0 100644
--- a/Test/Unit/Exception.php
+++ b/Test/Unit/Exception.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -45,12 +47,11 @@ use Hoa\Test;
*
* Test suite of the exception class.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Exception extends Test\Unit\Suite
{
- public function case_is_an_idle_exception()
+ public function case_is_an_idle_exception(): void
{
$this
->when($result = new SUT('foo'))
@@ -59,7 +60,7 @@ class Exception extends Test\Unit\Suite
->isInstanceOf('Hoa\Exception\Idle');
}
- public function case_event_is_registered()
+ public function case_event_is_registered(): void
{
$this
->given(new SUT('foo'))
@@ -69,14 +70,14 @@ class Exception extends Test\Unit\Suite
->isTrue();
}
- public function case_event_is_sent()
+ public function case_event_is_sent(): void
{
$self = $this;
$this
->given(
Event::getEvent('hoa://Event/Exception')->attach(
- function (Event\Bucket $bucket) use ($self, &$called) {
+ function (Event\Bucket $bucket) use ($self, &$called): void {
$called = true;
$self
diff --git a/Test/Unit/Group.php b/Test/Unit/Group.php
index 45f371b..e970188 100644
--- a/Test/Unit/Group.php
+++ b/Test/Unit/Group.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -44,12 +46,11 @@ use Hoa\Test;
*
* Test suite of the group class.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Group extends Test\Unit\Suite
{
- public function case_is_an_exception_arrayaccess_iteratoraggregate_countable()
+ public function case_is_an_exception_arrayaccess_iteratoraggregate_countable(): void
{
$this
->when($result = new SUT('foo'))
@@ -61,7 +62,7 @@ class Group extends Test\Unit\Suite
->isInstanceOf('Countable');
}
- public function case_constructor()
+ public function case_constructor(): void
{
$this
->given(
@@ -84,7 +85,7 @@ class Group extends Test\Unit\Suite
->isFalse();
}
- public function case_raise_zero_exception()
+ public function case_raise_zero_exception(): void
{
$this
->given($group = new SUT('foo'), $line = __LINE__)
@@ -97,12 +98,14 @@ class Group extends Test\Unit\Suite
);
}
- public function case_raise_one_exception()
+ public function case_raise_one_exception(): void
{
$this
->given(
- $exception1 = new SUT('bar'), $barLine = __LINE__,
- $group = new SUT('foo'), $fooLine = __LINE__,
+ $exception1 = new SUT('bar'),
+ $barLine = __LINE__ - 1,
+ $group = new SUT('foo'),
+ $fooLine = __LINE__ - 1,
$group[] = $exception1
)
->when($result = $group->raise())
@@ -117,13 +120,16 @@ class Group extends Test\Unit\Suite
);
}
- public function case_raise_more_exceptions()
+ public function case_raise_more_exceptions(): void
{
$this
->given(
- $exception1 = new SUT('bar'), $barLine = __LINE__,
- $exception2 = new SUT('baz'), $bazLine = __LINE__,
- $group = new SUT('foo'), $fooLine = __LINE__,
+ $exception1 = new SUT('bar'),
+ $barLine = __LINE__ - 1,
+ $exception2 = new SUT('baz'),
+ $bazLine = __LINE__ - 1,
+ $group = new SUT('foo'),
+ $fooLine = __LINE__ - 1,
$group[] = $exception1,
$group[] = $exception2
)
@@ -141,7 +147,7 @@ class Group extends Test\Unit\Suite
);
}
- public function case_begin_transaction()
+ public function case_begin_transaction(): void
{
$this
->given(
@@ -161,7 +167,7 @@ class Group extends Test\Unit\Suite
->isEqualTo($oldStackSize + 1);
}
- public function case_rollback_transaction_with_an_empty_stack()
+ public function case_rollback_transaction_with_an_empty_stack(): void
{
$this
->given(
@@ -181,7 +187,7 @@ class Group extends Test\Unit\Suite
->isEqualTo($oldStackSize);
}
- public function case_rollback_transaction()
+ public function case_rollback_transaction(): void
{
$this
->given(
@@ -204,7 +210,7 @@ class Group extends Test\Unit\Suite
->isEqualTo($oldStackSize - 2);
}
- public function case_commit_transaction_with_an_empty_stack()
+ public function case_commit_transaction_with_an_empty_stack(): void
{
$this
->given(
@@ -231,7 +237,7 @@ class Group extends Test\Unit\Suite
->isEqualTo($oldStackSize - 1);
}
- public function case_commit_transaction()
+ public function case_commit_transaction(): void
{
$this
->given(
@@ -267,7 +273,7 @@ class Group extends Test\Unit\Suite
]);
}
- public function case_has_uncommitted_exceptions()
+ public function case_has_uncommitted_exceptions(): void
{
$this
->given(
@@ -281,7 +287,7 @@ class Group extends Test\Unit\Suite
->isTrue();
}
- public function case_has_no_uncommitted_exceptions()
+ public function case_has_no_uncommitted_exceptions(): void
{
$this
->given(
@@ -294,7 +300,7 @@ class Group extends Test\Unit\Suite
->isFalse();
}
- public function case_has_no_uncommitted_exceptions_with_empty_stack()
+ public function case_has_no_uncommitted_exceptions_with_empty_stack(): void
{
$this
->given(
@@ -307,7 +313,7 @@ class Group extends Test\Unit\Suite
->isFalse();
}
- public function case_offset_exists_with_no_uncommited_exceptions()
+ public function case_offset_exists_with_no_uncommited_exceptions(): void
{
$this
->given(
@@ -320,7 +326,7 @@ class Group extends Test\Unit\Suite
->isTrue();
}
- public function case_offset_does_not_exist_with_no_uncommited_exceptions()
+ public function case_offset_does_not_exist_with_no_uncommited_exceptions(): void
{
$this
->given(
@@ -333,7 +339,7 @@ class Group extends Test\Unit\Suite
->isFalse();
}
- public function case_offset_exists()
+ public function case_offset_exists(): void
{
$this
->given(
@@ -348,7 +354,7 @@ class Group extends Test\Unit\Suite
->isTrue();
}
- public function case_offset_does_not_exist()
+ public function case_offset_does_not_exist(): void
{
$this
->given(
@@ -363,7 +369,7 @@ class Group extends Test\Unit\Suite
->isFalse();
}
- public function case_offset_get_with_no_uncommited_exceptions()
+ public function case_offset_get_with_no_uncommited_exceptions(): void
{
$this
->given(
@@ -377,7 +383,7 @@ class Group extends Test\Unit\Suite
->isIdenticalTo($exception1);
}
- public function case_offset_get_does_not_exist_with_no_uncommited_exceptions()
+ public function case_offset_get_does_not_exist_with_no_uncommited_exceptions(): void
{
$this
->given(
@@ -391,7 +397,7 @@ class Group extends Test\Unit\Suite
->isNull();
}
- public function case_offset_get()
+ public function case_offset_get(): void
{
$this
->given(
@@ -407,7 +413,7 @@ class Group extends Test\Unit\Suite
->isIdenticalTo($exception1);
}
- public function case_offset_get_does_not_exist()
+ public function case_offset_get_does_not_exist(): void
{
$this
->given(
@@ -423,7 +429,7 @@ class Group extends Test\Unit\Suite
->isNull();
}
- public function case_offset_set_not_an_exception()
+ public function case_offset_set_not_an_exception(): void
{
$this
->given($group = new SUT('foo'))
@@ -433,7 +439,7 @@ class Group extends Test\Unit\Suite
->isFalse();
}
- public function case_offset_set()
+ public function case_offset_set(): void
{
$this
->given(
@@ -453,7 +459,7 @@ class Group extends Test\Unit\Suite
->isIdenticalTo($exception1);
}
- public function case_offset_set_with_a_null_index()
+ public function case_offset_set_with_a_null_index(): void
{
$this
->given(
@@ -468,7 +474,7 @@ class Group extends Test\Unit\Suite
->isIdenticalTo($exception1);
}
- public function case_offset_set_with_an_integer_index()
+ public function case_offset_set_with_an_integer_index(): void
{
$this
->given(
@@ -485,7 +491,7 @@ class Group extends Test\Unit\Suite
->isIdenticalTo($exception1);
}
- public function case_offset_unset_with_no_uncommited_exceptions()
+ public function case_offset_unset_with_no_uncommited_exceptions(): void
{
$this
->given(
@@ -498,7 +504,7 @@ class Group extends Test\Unit\Suite
->isFalse();
}
- public function case_offset_unset_does_not_exist_with_no_uncommited_exceptions()
+ public function case_offset_unset_does_not_exist_with_no_uncommited_exceptions(): void
{
$this
->given($group = new SUT('foo'))
@@ -508,7 +514,7 @@ class Group extends Test\Unit\Suite
->isFalse();
}
- public function case_offset_unset()
+ public function case_offset_unset(): void
{
$this
->given(
@@ -523,7 +529,7 @@ class Group extends Test\Unit\Suite
->isFalse();
}
- public function case_offset_unset_does_not_exist()
+ public function case_offset_unset_does_not_exist(): void
{
$this
->given(
@@ -537,7 +543,7 @@ class Group extends Test\Unit\Suite
->isFalse();
}
- public function case_get_exceptions()
+ public function case_get_exceptions(): void
{
$this
->given(
@@ -556,7 +562,7 @@ class Group extends Test\Unit\Suite
->isIdenticalTo($exception1);
}
- public function case_get_iterator()
+ public function case_get_iterator(): void
{
$this
->given(
@@ -574,7 +580,7 @@ class Group extends Test\Unit\Suite
]);
}
- public function case_count()
+ public function case_count(): void
{
$this
->given(
@@ -591,7 +597,7 @@ class Group extends Test\Unit\Suite
->isEqualTo(1);
}
- public function get_get_stack_size()
+ public function get_get_stack_size(): void
{
$this
->given(
diff --git a/Test/Unit/Idle.php b/Test/Unit/Idle.php
index df1f46f..b8a4a6c 100644
--- a/Test/Unit/Idle.php
+++ b/Test/Unit/Idle.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -44,12 +46,11 @@ use Hoa\Test;
*
* Test suite of the idle exception.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Idle extends Test\Unit\Suite
{
- public function case_is_a_real_exception()
+ public function case_is_a_real_exception(): void
{
$this
->when($result = new SUT('foo'))
@@ -58,7 +59,7 @@ class Idle extends Test\Unit\Suite
->isInstanceOf('Exception');
}
- public function case_get_backtrace()
+ public function case_get_backtrace(): void
{
$this
->given($exception = new SUT('foo'))
@@ -75,7 +76,7 @@ class Idle extends Test\Unit\Suite
->hasKey('args');
}
- public function case_get_previous_throw()
+ public function case_get_previous_throw(): void
{
$this
->given(
@@ -88,7 +89,7 @@ class Idle extends Test\Unit\Suite
->isIdenticalTo($previous);
}
- public function case_get_arguments()
+ public function case_get_arguments(): void
{
$this
->given($exception = new SUT('foo', 0, ['arg', 42, null]))
@@ -98,7 +99,7 @@ class Idle extends Test\Unit\Suite
->isEqualTo(['arg', 42, '(null)']);
}
- public function case_get_arguments_from_a_string()
+ public function case_get_arguments_from_a_string(): void
{
$this
->given($exception = new SUT('foo', 0, 'arg'))
@@ -108,7 +109,7 @@ class Idle extends Test\Unit\Suite
->isEqualTo(['arg']);
}
- public function case_get_raw_message()
+ public function case_get_raw_message(): void
{
$this
->given(
@@ -121,7 +122,7 @@ class Idle extends Test\Unit\Suite
->isEqualTo($message);
}
- public function case_get_formatted_message()
+ public function case_get_formatted_message(): void
{
$this
->given(
@@ -135,7 +136,7 @@ class Idle extends Test\Unit\Suite
->isEqualTo('foo bar');
}
- public function case_get_from_object()
+ public function case_get_from_object(): void
{
$this
->given($exception = new SUT('foo'))
@@ -145,7 +146,7 @@ class Idle extends Test\Unit\Suite
->isEqualTo(__METHOD__ . '()');
}
- public function case_raise()
+ public function case_raise(): void
{
$this
->given($exception = new SUT('foo'), $line = __LINE__)
@@ -158,12 +159,14 @@ class Idle extends Test\Unit\Suite
);
}
- public function case_raise_with_previous()
+ public function case_raise_with_previous(): void
{
$this
->given(
- $previous = new SUT('previous'), $previousLine = __LINE__,
- $exception = new SUT('foo', 0, [], $previous), $line = __LINE__
+ $previous = new SUT('previous'),
+ $previousLine = __LINE__ - 1,
+ $exception = new SUT('foo', 0, [], $previous),
+ $line = __LINE__ - 1
)
->when($result = $exception->raise(true))
->then
@@ -178,12 +181,13 @@ class Idle extends Test\Unit\Suite
);
}
- public function case_uncaught()
+ public function case_uncaught(): void
{
$this
->given(
$this->function->ob_get_level = 0,
- $exception = new SUT('foo'), $line = __LINE__
+ $exception = new SUT('foo'),
+ $line = __LINE__ - 1
)
->when($result = SUT::uncaught($exception))
->then
@@ -197,10 +201,10 @@ class Idle extends Test\Unit\Suite
);
}
- public function case_uncaught_not_Hoa()
+ public function case_uncaught_not_Hoa(): void
{
$this
- ->exception(function () {
+ ->exception(function (): void {
SUT::uncaught(new \Exception('foo'));
})
->isInstanceOf('Exception')
@@ -208,7 +212,7 @@ class Idle extends Test\Unit\Suite
->isEmpty();
}
- public function case_to_string()
+ public function case_to_string(): void
{
$this
->given($exception = new SUT('foo'))
@@ -218,7 +222,7 @@ class Idle extends Test\Unit\Suite
->isEqualTo($exception->raise());
}
- public function case_disable_uncaught_handler()
+ public function case_disable_uncaught_handler(): void
{
$this
->given(
@@ -236,7 +240,7 @@ class Idle extends Test\Unit\Suite
->isTrue();
}
- public function case_enable_uncaught_handler()
+ public function case_enable_uncaught_handler(): void
{
$self = $this;