Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test PHP
8.3
language features (#1299)
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
- Loading branch information
Showing
10 changed files
with
125 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace Fixture\PHP83; | ||
|
||
class ClassName { | ||
public const CONSTANT = 42; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace Fixture\PHP83; | ||
|
||
class Classes implements Interfaces { | ||
use Traits; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace Fixture\PHP83; | ||
|
||
enum Enums { | ||
const string FOO = "bar"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Fixture\PHP83; | ||
|
||
interface Interfaces { | ||
const string BAR = Enums::FOO; | ||
|
||
public function foo(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Fixture\PHP83; | ||
|
||
trait Traits { | ||
const string BAR = Enums::FOO; | ||
|
||
public function foo(): string | ||
{ | ||
return Interfaces::BAR; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mockery\Tests\Unit\PHP83; | ||
|
||
use Fixture\PHP83\Classes; | ||
use Fixture\PHP83\ClassName; | ||
use Fixture\PHP83\Enums; | ||
use Fixture\PHP83\Interfaces; | ||
use Fixture\PHP83\Traits; | ||
use Mockery\Adapter\Phpunit\MockeryTestCase; | ||
use Mockery\Exception; | ||
|
||
/** | ||
* @requires PHP 8.3.0-dev | ||
*/ | ||
class Php83LanguageFeaturesTest extends MockeryTestCase | ||
{ | ||
public function testCanMockClassTypedClassConstants(): void | ||
{ | ||
$mock = mock(Classes::class); | ||
|
||
self::assertInstanceOf(Classes::class, $mock); | ||
self::assertSame(Enums::FOO, $mock::BAR); | ||
} | ||
|
||
public function testCanMockInterfaceTypedClassConstants(): void | ||
{ | ||
$mock = mock(Interfaces::class); | ||
|
||
self::assertInstanceOf(Interfaces::class, $mock); | ||
self::assertSame(Enums::FOO, $mock::BAR); | ||
} | ||
|
||
public function testCanMockTraitTypedClassConstants(): void | ||
{ | ||
$mock = mock(Traits::class); | ||
|
||
self::assertSame(Enums::FOO, $mock->foo()); | ||
self::assertSame(Enums::FOO, $mock::BAR); | ||
} | ||
|
||
public function testCanMockWithDynamicClassConstantFetch(): void | ||
{ | ||
$mock = mock(ClassName::class); | ||
|
||
$constant = 'CONSTANT'; | ||
|
||
self::assertSame(ClassName::CONSTANT, $mock::CONSTANT); | ||
self::assertSame(ClassName::CONSTANT, $mock::{$constant}); | ||
self::assertSame(ClassName::{$constant}, $mock::CONSTANT); | ||
self::assertSame(ClassName::{$constant}, $mock::{$constant}); | ||
} | ||
|
||
/** | ||
* Enumerations ( enum ) are final classes and therefore cannot be mocked. | ||
*/ | ||
public function testCanNotMockEnumsFinalClasses(): void | ||
{ | ||
$this->expectException(Exception::class); | ||
|
||
mock(Enums::class); | ||
} | ||
} |