Server IP : 173.249.157.85 / Your IP : 3.141.196.30 Web Server : Apache System : Linux server.frogzhost.com 3.10.0-1127.19.1.el7.x86_64 #1 SMP Tue Aug 25 17:23:54 UTC 2020 x86_64 User : econtech ( 1005) PHP Version : 7.3.33 Disable Function : NONE MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/econtech/www/vendor/phpunit/phpunit/tests/unit/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) ); } }