| Server IP : 54.94.228.101 / Your IP : 172.28.20.13 Web Server : Apache System : Linux ip-172-28-29-189 6.5.0-1014-aws #14~22.04.1-Ubuntu SMP Thu Feb 15 15:27:06 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.2.34-43+ubuntu22.04.1+deb.sury.org+1 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/vinumday2_0/vendor/phpunit/phpunit/tests/Framework/Constraint/ |
Upload File : |
<?php
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Framework\Constraint;
use PHPUnit\Framework\Exception;
use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Framework\TestFailure;
final class LogicalAndTest extends ConstraintTestCase
{
public function testSetConstraintsRejectsInvalidConstraint()
{
$constraints = [
new \TruthyConstraint(),
new \FalsyConstraint(),
new \stdClass(),
];
$constraint = new LogicalAnd();
$this->expectException(Exception::class);
$this->expectExceptionMessage(\sprintf(
'All parameters to %s must be a constraint object.',
LogicalAnd::class
));
$constraint->setConstraints($constraints);
}
public function testCountReturnsCountOfComposedConstraints()
{
$counts = [
3,
5,
8,
];
$constraints = \array_map(function (int $count) {
return \CountConstraint::fromCount($count);
}, $counts);
$constraint = new LogicalAnd();
$constraint->setConstraints($constraints);
$expected = \array_sum($counts);
$this->assertSame($expected, $constraint->count());
}
public function testToStringReturnsImplodedStringRepresentationOfComposedConstraintsGluedWithAnd()
{
$names = [
'is healthy',
'is rich in amino acids',
'is rich in unsaturated fats',
];
$constraints = \array_map(function (string $name) {
return \NamedConstraint::fromName($name);
}, $names);
$constraint = new LogicalAnd();
$constraint->setConstraints($constraints);
$expected = \implode(' and ', $names);
$this->assertSame($expected, $constraint->toString());
}
/**
* @dataProvider providerFailingConstraints
*
* @param Constraint[] $constraints
*/
public function testEvaluateReturnsFalseIfAnyOfTheComposedConstraintsEvaluateToFalse(array $constraints)
{
$constraint = new LogicalAnd();
$constraint->setConstraints($constraints);
$this->assertFalse($constraint->evaluate('whatever', '', true));
}
/**
* @dataProvider providerSucceedingConstraints
*
* @param Constraint[] $constraints
*/
public function testEvaluateReturnsTrueIfAllOfTheComposedConstraintsEvaluateToTrue(array $constraints)
{
$constraint = new LogicalAnd();
$constraint->setConstraints($constraints);
$this->assertTrue($constraint->evaluate('whatever', '', true));
}
/**
* @dataProvider providerFailingConstraints
*
* @param Constraint[] $constraints
*/
public function testEvaluateThrowsExceptionIfAnyOfTheComposedConstraintsEvaluateToFalse(array $constraints)
{
$other = 'whatever';
$constraint = new LogicalAnd();
$constraint->setConstraints($constraints);
try {
$constraint->evaluate($other);
} catch (ExpectationFailedException $exception) {
$toString = $this->stringify($constraints);
$expectedDescription = <<<EOF
Failed asserting that '$other' $toString.
EOF;
$this->assertEquals($expectedDescription, TestFailure::exceptionToString($exception));
return;
}
$this->fail();
}
/**
* @dataProvider providerFailingConstraints
*
* @param Constraint[] $constraints
*/
public function testEvaluateThrowsExceptionWithCustomMessageIfAnyOfTheComposedConstraintsEvaluateToFalse(array $constraints)
{
$other = 'whatever';
$customDescription = 'Not very happy about the results at this point in time, I have to admit!';
$constraint = new LogicalAnd();
$constraint->setConstraints($constraints);
try {
$constraint->evaluate(
$other,
$customDescription
);
} catch (ExpectationFailedException $exception) {
$toString = $this->stringify($constraints);
$expectedDescription = <<<EOF
$customDescription
Failed asserting that '$other' $toString.
EOF;
$this->assertEquals($expectedDescription, TestFailure::exceptionToString($exception));
return;
}
$this->fail();
}
/**
* @dataProvider providerSucceedingConstraints
*
* @param Constraint[] $constraints
*/
public function testEvaluateReturnsNothingIfAllOfTheComposedConstraintsEvaluateToTrue(array $constraints)
{
$constraint = new LogicalAnd();
$constraint->setConstraints($constraints);
$this->assertNull($constraint->evaluate('whatever'));
}
public function providerFailingConstraints(): \Generator
{
$values = [
'single' => [
new \FalsyConstraint(),
],
'multiple' => [
new \TruthyConstraint(),
new \FalsyConstraint(),
new \TruthyConstraint(),
],
];
foreach ($values as $key => $constraints) {
yield $key => [
$constraints,
];
}
}
public function providerSucceedingConstraints(): \Generator
{
$values = [
'single' => [
new \TruthyConstraint(),
],
'multiple' => [
new \TruthyConstraint(),
new \TruthyConstraint(),
new \TruthyConstraint(),
],
];
foreach ($values as $key => $constraints) {
yield $key => [
$constraints,
];
}
}
private function stringify(array $constraints) : string
{
return \implode(
' and ',
\array_map(function (Constraint $constraint) {
return $constraint->toString();
}, $constraints)
);
}
}