Commit d0cbfb2e authored by lv's avatar lv

Add contravariance for main constraint class

parent 19029ad3
Pipeline #233 failed with stages
in 0 seconds
......@@ -2,7 +2,8 @@
namespace PHPUnit\Framework\Constraint;
abstract class Constraint<T>
// @see #23
abstract class Constraint<-T>
implements \Countable, \PHPUnit\Framework\SelfDescribing {
protected /*SebastianBergmann\Exporter\Exporter */ $exporter;
......
......@@ -6,4 +6,8 @@ class ConstraintTest extends HHITest {
public function testIsTypeHasTypes(): void {
$this->runTestFile('constraint/isType/hasTypes');
}
public function testConnstraitContravariance(): void {
$this->runTestFile('constraint/ConnstraitContravariance');
}
}
---FILE---
<?hh // strict
use PHPUnit\Framework\Constraint\Constraint;
use PHPUnit\Framework\Constraint\IsEqual;
/**
* Examples:
* https://github.com/sebastianbergmann/phpunit/blob/master/src/Framework/Constraint/LogicalOr.php
* https://github.com/sebastianbergmann/phpunit/blob/master/src/Framework/Constraint/LogicalAnd.php
* https://github.com/sebastianbergmann/phpunit/blob/master/src/Framework/Constraint/LogicalXor.php
**/
class ConnstraitContravariance<T> extends Constraint<T>
{
protected array<Constraint<T>> $constraints = [];
public function setConstraints(array<Constraint<T>> $constraints): void
{
$this->constraints = [];
foreach ($constraints as $constraint) {
if (! $constraint instanceof Constraint) {
$constraint = new IsEqual(
$constraint
);
}
$this->constraints[] = $constraint;
}
}
public function toString(): string
{
return '';
}
}
---PASS---
1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment