Commit bf1000b3 authored by Simon Welsh's avatar Simon Welsh

Merge branch '23-main-constraint-contravariance' into 'phpunit-6.2'

Resolve "Main Constraint contravariance"

Closes #23

See merge request !12
parents 19029ad3 d0cbfb2e
Pipeline #234 passed with stages
in 10 minutes and 48 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