mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-22 16:02:54 +03:00
Implemented Int type.
This commit is contained in:
parent
ea47793dc3
commit
64cc62ea9c
3 changed files with 34 additions and 4 deletions
|
@ -11,8 +11,12 @@
|
||||||
* @since v1.2.0
|
* @since v1.2.0
|
||||||
* ---------------------------------------------------------------------------- */
|
* ---------------------------------------------------------------------------- */
|
||||||
|
|
||||||
namespace \EA\Engine\Types;
|
namespace EA\Engine\Types;
|
||||||
|
|
||||||
class Int extends Type {
|
class Int extends Type {
|
||||||
|
protected function _validate() {
|
||||||
|
if (!is_numeric($this->value) && (int)$this->value !== (float)$this->value) {
|
||||||
|
throw new \InvalidArgumentException('Invalid type value provided (expected int): ' . $this->value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
* @since v1.2.0
|
* @since v1.2.0
|
||||||
* ---------------------------------------------------------------------------- */
|
* ---------------------------------------------------------------------------- */
|
||||||
|
|
||||||
namespace \EA\Engine\Types;
|
namespace EA\Engine\Types;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract Type Class
|
* Abstract Type Class
|
||||||
|
@ -25,8 +25,8 @@ abstract class Type {
|
||||||
* @param mixed $value The type value to be validated.
|
* @param mixed $value The type value to be validated.
|
||||||
*/
|
*/
|
||||||
public function __construct($value) {
|
public function __construct($value) {
|
||||||
$this->_validate($value);
|
|
||||||
$this->value = $value;
|
$this->value = $value;
|
||||||
|
$this->_validate($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
26
test/php/engine/Types/IntTest.php
Normal file
26
test/php/engine/Types/IntTest.php
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Easy!Appointments - Open Source Web Scheduler
|
||||||
|
*
|
||||||
|
* @package EasyAppointments
|
||||||
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||||
|
* @copyright Copyright (c) 2013 - 2016, Alex Tselegidis
|
||||||
|
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||||
|
* @link http://easyappointments.org
|
||||||
|
* @since v1.2.0
|
||||||
|
* ---------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
namespace EA\Engine\Types;
|
||||||
|
|
||||||
|
class AuthorizationTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
public function testIntType() {
|
||||||
|
$type = new Int(1);
|
||||||
|
$this->assertEquals(1, $type->get());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIntTypeThrowsExceptionWithInvalidValue() {
|
||||||
|
$this->setExpectedException('\InvalidArgumentException');
|
||||||
|
new Int('invalid');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue