forked from sebastianbergmann/phpunit
-
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.
Add Tests for StringMatchesFormatDescription
Add a test file for the StringMatchesFormatDescription constraint, and add a simple test case for each format specifier.
- Loading branch information
Showing
1 changed file
with
142 additions
and
0 deletions.
There are no files selected for viewing
142 changes: 142 additions & 0 deletions
142
tests/Framework/Constraint/StringMatchesFormatDescriptionTest.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 |
---|---|---|
@@ -0,0 +1,142 @@ | ||
<?php | ||
/* | ||
* This file is part of PHPUnit. | ||
* | ||
* (c) Sebastian Bergmann <[email protected]> | ||
* | ||
* 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\ExpectationFailedException; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class StringMatchesFormatDescriptionTest extends TestCase | ||
{ | ||
/** | ||
* @param bool $expected | ||
* @param string $format | ||
* @param string $other | ||
* @dataProvider evaluateDataProvider | ||
*/ | ||
public function testEvaluate($expected, $format, $other) | ||
{ | ||
$constraint = new StringMatchesFormatDescription($format); | ||
|
||
$this->assertSame($expected, $constraint->evaluate($other, '', true)); | ||
} | ||
|
||
public function evaluateDataProvider() | ||
{ | ||
return [ | ||
'Simple %e' => [ | ||
true, | ||
'%e', | ||
DIRECTORY_SEPARATOR | ||
], | ||
'Negative %e' => [ | ||
false, | ||
'%e', | ||
'a' | ||
], | ||
'Simple %s' => [ | ||
true, | ||
'%s', | ||
'string' | ||
], | ||
'Negative %s' => [ | ||
false, | ||
'%s', | ||
"\n" | ||
], | ||
'Simple %S' => [ | ||
true, | ||
'%S', | ||
'string' | ||
], | ||
'Negative %S' => [ | ||
false, | ||
'%S', | ||
"1\n2\n2" | ||
], | ||
'Simple %a' => [ | ||
true, | ||
'%a', | ||
'string' | ||
], | ||
'Negative %a' => [ | ||
false, | ||
'%a', | ||
'' | ||
], | ||
'Simple %A' => [ | ||
true, | ||
'%A', | ||
'string' | ||
], | ||
// Negative %A is not possible - it will match pretty much anything. | ||
'Simple %w' => [ | ||
true, | ||
'%w', | ||
' ' | ||
], | ||
'Negative %w' => [ | ||
false, | ||
'%w', | ||
'nowhitespace' | ||
], | ||
'Simple %i' => [ | ||
true, | ||
'%i', | ||
'-10' | ||
], | ||
'Negative %i' => [ | ||
false, | ||
'%i', | ||
'abc' | ||
], | ||
'Simple %d' => [ | ||
true, | ||
'%d', | ||
'1' | ||
], | ||
'Negative %d' => [ | ||
false, | ||
'%d', | ||
'abc' | ||
], | ||
'Simple %x' => [ | ||
true, | ||
'%x', | ||
'0123456789abcdefABCDEF' | ||
], | ||
'Negative %x' => [ | ||
false, | ||
'%x', | ||
'_' | ||
], | ||
'Simple %f' => [ | ||
true, | ||
'%f', | ||
'-1.2e-10' | ||
], | ||
'Negative %f' => [ | ||
false, | ||
'%f', | ||
'foo' | ||
], | ||
'Simple %c' => [ | ||
true, | ||
'%c', | ||
'a' | ||
], | ||
'Negative %c' => [ | ||
false, | ||
'%c', | ||
'abc' | ||
] | ||
]; | ||
} | ||
} |