/
githubmirror
/
framework
Обзор
Документация
Войти
/
githubmirror
/
framework
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
13.x
tests/Support/SupportEnumValueFunctionTest.php
48 строк
1 KB
Mior Muhammad Zaki
[11.x] Allows `enum_value()` to be use in standalone `illuminate/collections` (#53871)
13 дек 2024, 16:58
Не верифицирован
13 дек 2024, 16:58
8b6099d
Код
Авторство
О чём код?
<?php namespace Illuminate\Tests\Support; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use function Illuminate\Support\enum_value; include_once 'Enums.php'; class SupportEnumValueFunctionTest extends TestCase { #[DataProvider('scalarDataProvider')] public function test_it_can_handle_enum_value($given, $expected) { $this->assertSame($expected, enum_value($given)); } public function test_it_can_fallback_to_use_default_if_value_is_null() { $this->assertSame('laravel', enum_value(null, 'laravel')); $this->assertSame('laravel', enum_value(null, fn () => 'laravel')); } public static function scalarDataProvider() { yield [TestEnum::A, 'A']; yield [TestBackedEnum::A, 1]; yield [TestBackedEnum::B, 2]; yield [TestStringBackedEnum::A, 'A']; yield [TestStringBackedEnum::B, 'B']; yield [null, null]; yield [0, 0]; yield ['0', '0']; yield [false, false]; yield [1, 1]; yield ['1', '1']; yield [true, true]; yield [[], []]; yield ['', '']; yield ['laravel', 'laravel']; yield [true, true]; yield [1337, 1337]; yield [1.0, 1.0]; yield [$collect = collect(), $collect]; } }