/
githubmirror
/
symfony
Обзор
Документация
Войти
/
githubmirror
/
symfony
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
8.2
src/Symfony/Component/Config/Tests/Definition/FloatNodeTest.php
87 строк
2 KB
Nicolas Grekas
Merge branch '6.4' into 7.4
29 апр 2026, 16:21
29 апр 2026, 16:21
7bedf70
Код
Авторство
О чём код?
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Config\Tests\Definition; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Config\Definition\Exception\InvalidTypeException; use Symfony\Component\Config\Definition\FloatNode; use Symfony\Component\Config\Definition\NumericNode; class FloatNodeTest extends TestCase { #[DataProvider('getValidValues')] public function testNormalize(int|float $value) { $node = new FloatNode('test'); $this->assertSame($value, $node->normalize($value)); } #[DataProvider('getValidValues')] public function testValidNonEmptyValues(int|float $value) { $node = new FloatNode('test'); $node->setAllowEmptyValue(false); $this->assertSame($value, $node->finalize($value)); } public static function getValidValues(): array { return [ [1798.0], [-678.987], [12.56E45], [0.0], // Integer are accepted too, they will be cast [17], [-10], [0], ]; } #[DataProvider('getInvalidValues')] public function testNormalizeThrowsExceptionOnInvalidValues($value) { $node = new FloatNode('test'); $this->expectException(InvalidTypeException::class); $node->normalize($value); } public static function getInvalidValues(): array { return [ [null], [''], ['foo'], [true], [false], [[]], [['foo' => 'bar']], [new \stdClass()], ]; } public function testFinalizeAcceptsEnvPlaceholderBelowMin() { $node = new FloatNode('multiplier', null, 1); NumericNode::setPlaceholder('env_FOO', ['float' => 0.0]); try { $this->assertSame('env_FOO', $node->finalize('env_FOO')); } finally { NumericNode::resetPlaceholders(); } } }