mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-18 05:16:30 +00:00
improve test coverage and support negative int for random function
This commit is contained in:
@@ -299,7 +299,7 @@ function twig_random($values = null)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (is_int($values) || is_float($values)) {
|
if (is_int($values) || is_float($values)) {
|
||||||
return mt_rand(0, $values);
|
return ($values < 0) ? mt_rand($values, 0) : mt_rand(0, $values);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($values instanceof Traversable) {
|
if ($values instanceof Traversable) {
|
||||||
|
|||||||
@@ -48,6 +48,10 @@ class Twig_Tests_Extension_CoreTest extends PHPUnit_Framework_TestCase
|
|||||||
5.9,
|
5.9,
|
||||||
range(0, 5, 1),
|
range(0, 5, 1),
|
||||||
),
|
),
|
||||||
|
array( // negative
|
||||||
|
-2,
|
||||||
|
array(0, -1, -2),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,6 +65,14 @@ class Twig_Tests_Extension_CoreTest extends PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testRandomFunctionReturnsAsIs()
|
||||||
|
{
|
||||||
|
$this->assertSame('', twig_random(''));
|
||||||
|
|
||||||
|
$instance = new stdClass();
|
||||||
|
$this->assertSame($instance, twig_random($instance));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Twig_Error_Runtime
|
* @expectedException Twig_Error_Runtime
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user