mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-11 18:06:46 +00:00
Fix implicit flot to int casts
This commit is contained in:
@@ -349,7 +349,7 @@ function twig_cycle($values, $position)
|
|||||||
function twig_random(Environment $env, $values = null, $max = null)
|
function twig_random(Environment $env, $values = null, $max = null)
|
||||||
{
|
{
|
||||||
if (null === $values) {
|
if (null === $values) {
|
||||||
return null === $max ? mt_rand() : mt_rand(0, $max);
|
return null === $max ? mt_rand() : mt_rand(0, (int) $max);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (\is_int($values) || \is_float($values)) {
|
if (\is_int($values) || \is_float($values)) {
|
||||||
@@ -366,7 +366,7 @@ function twig_random(Environment $env, $values = null, $max = null)
|
|||||||
$max = $max;
|
$max = $max;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mt_rand($min, $max);
|
return mt_rand((int) $min, (int) $max);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (\is_string($values)) {
|
if (\is_string($values)) {
|
||||||
|
|||||||
+10
-3
@@ -11,6 +11,7 @@ namespace Twig\Tests;
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
use Twig\Environment;
|
use Twig\Environment;
|
||||||
use Twig\Error\RuntimeError;
|
use Twig\Error\RuntimeError;
|
||||||
use Twig\Extension\SandboxExtension;
|
use Twig\Extension\SandboxExtension;
|
||||||
@@ -23,7 +24,7 @@ use Twig\Sandbox\SecurityError;
|
|||||||
use Twig\Sandbox\SecurityPolicy;
|
use Twig\Sandbox\SecurityPolicy;
|
||||||
use Twig\Template;
|
use Twig\Template;
|
||||||
|
|
||||||
class TemplateTest extends \PHPUnit\Framework\TestCase
|
class TemplateTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testDisplayBlocksAcceptTemplateOnlyAsBlocks()
|
public function testDisplayBlocksAcceptTemplateOnlyAsBlocks()
|
||||||
{
|
{
|
||||||
@@ -238,9 +239,15 @@ class TemplateTest extends \PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
$this->assertSame('Zero', $array[false]);
|
$this->assertSame('Zero', $array[false]);
|
||||||
$this->assertSame('One', $array[true]);
|
$this->assertSame('One', $array[true]);
|
||||||
$this->assertSame('One', $array[1.5]);
|
if (\PHP_VERSION_ID < 80100) {
|
||||||
|
// This line will trigger a deprecation warning on PHP 8.1.
|
||||||
|
$this->assertSame('One', $array[1.5]);
|
||||||
|
}
|
||||||
$this->assertSame('One', $array['1']);
|
$this->assertSame('One', $array['1']);
|
||||||
$this->assertSame('MinusOne', $array[-1.5]);
|
if (\PHP_VERSION_ID < 80100) {
|
||||||
|
// This line will trigger a deprecation warning on PHP 8.1.
|
||||||
|
$this->assertSame('MinusOne', $array[-1.5]);
|
||||||
|
}
|
||||||
$this->assertSame('FloatButString', $array['1.5']);
|
$this->assertSame('FloatButString', $array['1.5']);
|
||||||
$this->assertSame('IntegerButStringWithLeadingZeros', $array['01']);
|
$this->assertSame('IntegerButStringWithLeadingZeros', $array['01']);
|
||||||
$this->assertSame('EmptyString', $array[null]);
|
$this->assertSame('EmptyString', $array[null]);
|
||||||
|
|||||||
Reference in New Issue
Block a user