|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 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 ClassExistsMockTest extends TestCase |
| 18 | +{ |
| 19 | + public static function setUpBeforeClass() |
| 20 | + { |
| 21 | + ClassExistsMock::register(__CLASS__); |
| 22 | + } |
| 23 | + |
| 24 | + protected function setUp() |
| 25 | + { |
| 26 | + ClassExistsMock::withMockedClasses(array( |
| 27 | + ExistingClass::class => false, |
| 28 | + 'NonExistingClass' => true, |
| 29 | + ExistingInterface::class => false, |
| 30 | + 'NonExistingInterface' => true, |
| 31 | + ExistingTrait::class => false, |
| 32 | + 'NonExistingTrait' => true, |
| 33 | + )); |
| 34 | + } |
| 35 | + |
| 36 | + public function testClassExists() |
| 37 | + { |
| 38 | + $this->assertFalse(class_exists(ExistingClass::class)); |
| 39 | + $this->assertFalse(class_exists(ExistingClass::class, false)); |
| 40 | + $this->assertFalse(class_exists('\\'.ExistingClass::class)); |
| 41 | + $this->assertFalse(class_exists('\\'.ExistingClass::class, false)); |
| 42 | + $this->assertTrue(class_exists('NonExistingClass')); |
| 43 | + $this->assertTrue(class_exists('NonExistingClass', false)); |
| 44 | + $this->assertTrue(class_exists('\\NonExistingClass')); |
| 45 | + $this->assertTrue(class_exists('\\NonExistingClass', false)); |
| 46 | + $this->assertTrue(class_exists(ExistingClassReal::class)); |
| 47 | + $this->assertTrue(class_exists(ExistingClassReal::class, false)); |
| 48 | + $this->assertTrue(class_exists('\\'.ExistingClassReal::class)); |
| 49 | + $this->assertTrue(class_exists('\\'.ExistingClassReal::class, false)); |
| 50 | + $this->assertFalse(class_exists('NonExistingClassReal')); |
| 51 | + $this->assertFalse(class_exists('NonExistingClassReal', false)); |
| 52 | + $this->assertFalse(class_exists('\\NonExistingClassReal')); |
| 53 | + $this->assertFalse(class_exists('\\NonExistingClassReal', false)); |
| 54 | + } |
| 55 | + |
| 56 | + public function testInterfaceExists() |
| 57 | + { |
| 58 | + $this->assertFalse(interface_exists(ExistingInterface::class)); |
| 59 | + $this->assertFalse(interface_exists(ExistingInterface::class, false)); |
| 60 | + $this->assertFalse(interface_exists('\\'.ExistingInterface::class)); |
| 61 | + $this->assertFalse(interface_exists('\\'.ExistingInterface::class, false)); |
| 62 | + $this->assertTrue(interface_exists('NonExistingInterface')); |
| 63 | + $this->assertTrue(interface_exists('NonExistingInterface', false)); |
| 64 | + $this->assertTrue(interface_exists('\\NonExistingInterface')); |
| 65 | + $this->assertTrue(interface_exists('\\NonExistingInterface', false)); |
| 66 | + $this->assertTrue(interface_exists(ExistingInterfaceReal::class)); |
| 67 | + $this->assertTrue(interface_exists(ExistingInterfaceReal::class, false)); |
| 68 | + $this->assertTrue(interface_exists('\\'.ExistingInterfaceReal::class)); |
| 69 | + $this->assertTrue(interface_exists('\\'.ExistingInterfaceReal::class, false)); |
| 70 | + $this->assertFalse(interface_exists('NonExistingClassReal')); |
| 71 | + $this->assertFalse(interface_exists('NonExistingClassReal', false)); |
| 72 | + $this->assertFalse(interface_exists('\\NonExistingInterfaceReal')); |
| 73 | + $this->assertFalse(interface_exists('\\NonExistingInterfaceReal', false)); |
| 74 | + } |
| 75 | + |
| 76 | + public function testTraitExists() |
| 77 | + { |
| 78 | + $this->assertFalse(trait_exists(ExistingTrait::class)); |
| 79 | + $this->assertFalse(trait_exists(ExistingTrait::class, false)); |
| 80 | + $this->assertFalse(trait_exists('\\'.ExistingTrait::class)); |
| 81 | + $this->assertFalse(trait_exists('\\'.ExistingTrait::class, false)); |
| 82 | + $this->assertTrue(trait_exists('NonExistingTrait')); |
| 83 | + $this->assertTrue(trait_exists('NonExistingTrait', false)); |
| 84 | + $this->assertTrue(trait_exists('\\NonExistingTrait')); |
| 85 | + $this->assertTrue(trait_exists('\\NonExistingTrait', false)); |
| 86 | + $this->assertTrue(trait_exists(ExistingTraitReal::class)); |
| 87 | + $this->assertTrue(trait_exists(ExistingTraitReal::class, false)); |
| 88 | + $this->assertTrue(trait_exists('\\'.ExistingTraitReal::class)); |
| 89 | + $this->assertTrue(trait_exists('\\'.ExistingTraitReal::class, false)); |
| 90 | + $this->assertFalse(trait_exists('NonExistingClassReal')); |
| 91 | + $this->assertFalse(trait_exists('NonExistingClassReal', false)); |
| 92 | + $this->assertFalse(trait_exists('\\NonExistingTraitReal')); |
| 93 | + $this->assertFalse(trait_exists('\\NonExistingTraitReal', false)); |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +class ExistingClass |
| 98 | +{ |
| 99 | +} |
| 100 | + |
| 101 | +class ExistingClassReal |
| 102 | +{ |
| 103 | +} |
| 104 | + |
| 105 | +interface ExistingInterface |
| 106 | +{ |
| 107 | +} |
| 108 | + |
| 109 | +interface ExistingInterfaceReal |
| 110 | +{ |
| 111 | +} |
| 112 | + |
| 113 | +trait ExistingTrait |
| 114 | +{ |
| 115 | +} |
| 116 | + |
| 117 | +trait ExistingTraitReal |
| 118 | +{ |
| 119 | +} |
0 commit comments