forked from DaveRandom/CallbackValidator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent DNF type tests from being loaded on PHP 8.2
- Loading branch information
Showing
11 changed files
with
59 additions
and
30 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
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
2 changes: 1 addition & 1 deletion
2
tests/Fixtures/ClassImplementingInvoke.php → ...Base/Fixtures/ClassImplementingInvoke.php
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
2 changes: 1 addition & 1 deletion
2
...es/ClassImplementingIteratorAggregate.php → ...es/ClassImplementingIteratorAggregate.php
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace DaveRandom\CallbackValidator\Test\Fixtures; | ||
namespace DaveRandom\CallbackValidator\Test\Base\Fixtures; | ||
|
||
abstract class ClassImplementingIteratorAggregate implements \IteratorAggregate {} |
2 changes: 1 addition & 1 deletion
2
tests/Fixtures/ClassImplementingNothing.php → ...ase/Fixtures/ClassImplementingNothing.php
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace DaveRandom\CallbackValidator\Test\Fixtures; | ||
namespace DaveRandom\CallbackValidator\Test\Base\Fixtures; | ||
|
||
class ClassImplementingNothing {} |
2 changes: 1 addition & 1 deletion
2
tests/Fixtures/ClassImplementingToString.php → ...se/Fixtures/ClassImplementingToString.php
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 DaveRandom\CallbackValidator\Test\Base\Fixtures; | ||
|
||
interface Interface1{ | ||
|
||
} |
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 DaveRandom\CallbackValidator\Test\Base\Fixtures; | ||
|
||
interface Interface2{ | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace DaveRandom\CallbackValidator\Test\Php82; | ||
|
||
use DaveRandom\CallbackValidator\CallbackType; | ||
use DaveRandom\CallbackValidator\Test\Base\Fixtures\Interface1; | ||
use DaveRandom\CallbackValidator\Test\Base\Fixtures\Interface2; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class CallbackTypeTest extends TestCase{ | ||
|
||
public static function returnCovarianceProvider() : \Generator{ | ||
//DNF types - PHP 8.2+ only | ||
yield [function() : (Interface1&Interface2)|string{}, function() : Interface1{}, false, "given type not covariant with any part of required union"]; | ||
yield [function() : (Interface1&Interface2)|string{}, function() : Interface1&Interface2{}, true, "given type covariant with at least 1 part of required union"]; | ||
} | ||
|
||
public static function paramContravarianceProvider() : \Generator{ | ||
//DNF types - PHP 8.2+ only | ||
yield [function((Interface1&Interface2)|string $a) : void{}, function(Interface1&Interface2 $a) : void{}, false, "given type must accept string"]; | ||
yield [function(Interface1&Interface2 $a) : void{}, function((Interface1&Interface2)|string $a) : void{}, true, "given type accepts string, which is not required by the signature"]; | ||
|
||
yield [function((Interface1&Interface2)|string $a) : void{}, function(mixed $a) : void{}, true, "mixed is contravariant with DNF type"]; | ||
} | ||
|
||
#[DataProvider('returnCovarianceProvider')] | ||
#[DataProvider('paramContravarianceProvider')] | ||
public function testCompatibility(\Closure $required, \Closure $given, bool $matches, string $reason) : void{ | ||
$required = CallbackType::createFromCallable($required); | ||
|
||
$serializedRequire = (string) $required; | ||
$serializedGiven = (string) CallbackType::createFromCallable($given); | ||
self::assertSame($required->isSatisfiedBy($given), $matches, $reason . " ($serializedRequire, $serializedGiven)"); | ||
} | ||
} |