/** * @test */ public function I_can_create_it() { $twentyFive = new PositiveNumberObject(25); self::assertSame(25, $twentyFive->getValue()); self::assertInstanceOf(NumberObject::getClass(), $twentyFive); self::assertInstanceOf('\\Granam\\Number\\PositiveNumber', $twentyFive); $twoHundredths = new PositiveNumberObject(0.02); self::assertSame(0.02, $twoHundredths->getValue()); self::assertInstanceOf(NumberObject::getClass(), $twoHundredths); self::assertInstanceOf('\\Granam\\Number\\PositiveNumber', $twoHundredths); $zero = new PositiveNumberObject(-0.0); self::assertSame(0.0, $zero->getValue()); self::assertInstanceOf(NumberObject::getClass(), $zero); self::assertInstanceOf('\\Granam\\Number\\PositiveNumber', $zero); }
/** * @param mixed $value * @param bool $strict = true allows only explicit values, not null and empty string * @param bool $paranoid Throws exception if some value is lost on cast because of rounding * @throws \Granam\Float\Tools\Exceptions\PositiveFloatCanNotBeNegative * @throws \Granam\Float\Tools\Exceptions\WrongParameterType * @throws \Granam\Float\Tools\Exceptions\ValueLostOnCast */ public function __construct($value, $strict = true, $paranoid = false) { /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ parent::__construct(ToFloat::toPositiveFloat($value, $strict, $paranoid)); }