|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Bridge\PhpUnit\Tests; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Symfony\Bridge\PhpUnit\ClassExistsMock; |
| 16 | + |
| 17 | +class EnumExistsMockTest extends TestCase |
| 18 | +{ |
| 19 | + public static function setUpBeforeClass(): void |
| 20 | + { |
| 21 | + ClassExistsMock::register(__CLASS__); |
| 22 | + } |
| 23 | + |
| 24 | + protected function setUp(): void |
| 25 | + { |
| 26 | + ClassExistsMock::withMockedClasses([ |
| 27 | + ExistingEnum::class => false, |
| 28 | + 'NonExistingEnum' => true, |
| 29 | + ]); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * @requires PHP 8.1 |
| 34 | + */ |
| 35 | + public function testEnumExists() |
| 36 | + { |
| 37 | + $this->assertFalse(enum_exists(ExistingEnum::class)); |
| 38 | + $this->assertFalse(enum_exists(ExistingEnum::class, false)); |
| 39 | + $this->assertFalse(enum_exists('\\'.ExistingEnum::class)); |
| 40 | + $this->assertFalse(enum_exists('\\'.ExistingEnum::class, false)); |
| 41 | + $this->assertTrue(enum_exists('NonExistingEnum')); |
| 42 | + $this->assertTrue(enum_exists('NonExistingEnum', false)); |
| 43 | + $this->assertTrue(enum_exists('\\NonExistingEnum')); |
| 44 | + $this->assertTrue(enum_exists('\\NonExistingEnum', false)); |
| 45 | + $this->assertTrue(enum_exists(ExistingEnumReal::class)); |
| 46 | + $this->assertTrue(enum_exists(ExistingEnumReal::class, false)); |
| 47 | + $this->assertTrue(enum_exists('\\'.ExistingEnumReal::class)); |
| 48 | + $this->assertTrue(enum_exists('\\'.ExistingEnumReal::class, false)); |
| 49 | + $this->assertFalse(enum_exists('NonExistingClassReal')); |
| 50 | + $this->assertFalse(enum_exists('NonExistingClassReal', false)); |
| 51 | + $this->assertFalse(enum_exists('\\NonExistingEnumReal')); |
| 52 | + $this->assertFalse(enum_exists('\\NonExistingEnumReal', false)); |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +enum ExistingEnum |
| 57 | +{ |
| 58 | +} |
| 59 | + |
| 60 | +enum ExistingEnumReal |
| 61 | +{ |
| 62 | +} |
0 commit comments