-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[PhpUnitBridge] Add enum_exists
mock
#48516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
CHANGELOG | ||
========= | ||
|
||
6.3 | ||
--- | ||
|
||
* Add support for mocking the `enum_exists` function | ||
|
||
6.2 | ||
--- | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?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\Bridge\PhpUnit\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Bridge\PhpUnit\ClassExistsMock; | ||
use Symfony\Bridge\PhpUnit\Tests\Fixtures\ExistingEnum; | ||
use Symfony\Bridge\PhpUnit\Tests\Fixtures\ExistingEnumReal; | ||
|
||
/** | ||
* @requires PHP 8.1 | ||
*/ | ||
class EnumExistsMockTest extends TestCase | ||
{ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
ClassExistsMock::register(__CLASS__); | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
ClassExistsMock::withMockedEnums([ | ||
ExistingEnum::class => false, | ||
'NonExistingEnum' => true, | ||
]); | ||
} | ||
|
||
public function testClassExists() | ||
{ | ||
$this->assertFalse(class_exists(ExistingEnum::class)); | ||
$this->assertFalse(class_exists(ExistingEnum::class, false)); | ||
$this->assertFalse(class_exists('\\'.ExistingEnum::class)); | ||
$this->assertFalse(class_exists('\\'.ExistingEnum::class, false)); | ||
$this->assertTrue(class_exists('NonExistingEnum')); | ||
$this->assertTrue(class_exists('NonExistingEnum', false)); | ||
$this->assertTrue(class_exists('\\NonExistingEnum')); | ||
$this->assertTrue(class_exists('\\NonExistingEnum', false)); | ||
$this->assertTrue(class_exists(ExistingEnumReal::class)); | ||
$this->assertTrue(class_exists(ExistingEnumReal::class, false)); | ||
$this->assertTrue(class_exists('\\'.ExistingEnumReal::class)); | ||
$this->assertTrue(class_exists('\\'.ExistingEnumReal::class, false)); | ||
$this->assertFalse(class_exists('\\NonExistingEnumReal')); | ||
$this->assertFalse(class_exists('\\NonExistingEnumReal', false)); | ||
} | ||
|
||
public function testEnumExists() | ||
{ | ||
$this->assertFalse(enum_exists(ExistingEnum::class)); | ||
$this->assertFalse(enum_exists(ExistingEnum::class, false)); | ||
$this->assertFalse(enum_exists('\\'.ExistingEnum::class)); | ||
$this->assertFalse(enum_exists('\\'.ExistingEnum::class, false)); | ||
$this->assertTrue(enum_exists('NonExistingEnum')); | ||
$this->assertTrue(enum_exists('NonExistingEnum', false)); | ||
$this->assertTrue(enum_exists('\\NonExistingEnum')); | ||
$this->assertTrue(enum_exists('\\NonExistingEnum', false)); | ||
$this->assertTrue(enum_exists(ExistingEnumReal::class)); | ||
$this->assertTrue(enum_exists(ExistingEnumReal::class, false)); | ||
$this->assertTrue(enum_exists('\\'.ExistingEnumReal::class)); | ||
$this->assertTrue(enum_exists('\\'.ExistingEnumReal::class, false)); | ||
$this->assertFalse(enum_exists('NonExistingClassReal')); | ||
$this->assertFalse(enum_exists('NonExistingClassReal', false)); | ||
$this->assertFalse(enum_exists('\\NonExistingEnumReal')); | ||
$this->assertFalse(enum_exists('\\NonExistingEnumReal', false)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?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\Bridge\PhpUnit\Tests\Fixtures; | ||
|
||
enum ExistingEnum | ||
{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?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\Bridge\PhpUnit\Tests\Fixtures; | ||
|
||
enum ExistingEnumReal | ||
{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,8 @@ | |
}, | ||
"require-dev": { | ||
"symfony/deprecation-contracts": "^2.5|^3.0", | ||
"symfony/error-handler": "^5.4|^6.0" | ||
"symfony/error-handler": "^5.4|^6.0", | ||
"symfony/polyfill-php81": "^1.27" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this dependency? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because of this: #48516 (comment) 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, okay, it's just a dev dependency, so I guess it's fine. |
||
}, | ||
"suggest": { | ||
"symfony/error-handler": "For tracking deprecated interfaces usages at runtime with DebugClassLoader" | ||
|
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.