Implemented Int type.

This commit is contained in:
Alex Tselegidis 2016-07-09 10:33:13 +02:00
parent ea47793dc3
commit 64cc62ea9c
3 changed files with 34 additions and 4 deletions

View file

@ -11,8 +11,12 @@
* @since v1.2.0
* ---------------------------------------------------------------------------- */
namespace \EA\Engine\Types;
namespace EA\Engine\Types;
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);
}
}
}

View file

@ -11,7 +11,7 @@
* @since v1.2.0
* ---------------------------------------------------------------------------- */
namespace \EA\Engine\Types;
namespace EA\Engine\Types;
/**
* Abstract Type Class
@ -25,8 +25,8 @@ abstract class Type {
* @param mixed $value The type value to be validated.
*/
public function __construct($value) {
$this->_validate($value);
$this->value = $value;
$this->_validate($value);
}
/**

View 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');
}
}