I have a unit test that is used to test variable conversions from string to integer. So far it's good, except for the last one.
$_GET['name'] = '42000000000000000000000000000000000000';
$text = $input->get( 'name', Convert::T_INTEGER );
$this->assertEquals( 92233720368547755807, $text );
The expectancy is (which is confirmed by the test itself), is that the large value, when converted from string to integer using intval() causes an overflow which defaults to the largest integer value that php can handle on my system. Yet, it still fails:
Failed asserting that <integer:92233720368547755807> matches expected <double:9.2233720368548E+19>
And when I try to force the expected number into an integer:
$this->assertEquals( intval(92233720368547755807), $text );
I get this:
Failed asserting that <integer:92233720368547755807> matches expected <integer:0>
Which is what the test run literally right before this one tests for...
Relevant code:
public function get( $name, $type = null )
{
$value = $_GET['value'];
if( !is_null( $type ) )
$value = Convert::to( $value, $type );
return $value;
}
And
public static function to( $value, $type )
{
switch( $type )
{
case self::T_INTEGER:
return intval( $value );
default:
return null;
}
}
So the question is this: How do I get this test to return positive?