Skip to content

Commit

Permalink
Add Tests for StringMatchesFormatDescription
Browse files Browse the repository at this point in the history
Add a test file for the StringMatchesFormatDescription constraint, and
add a simple test case for each format specifier.
  • Loading branch information
mkasberg committed Dec 9, 2017
1 parent e5b7ff9 commit cb1eea3
Showing 1 changed file with 142 additions and 0 deletions.
142 changes: 142 additions & 0 deletions tests/Framework/Constraint/StringMatchesFormatDescriptionTest.php
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'
]
];
}
}

0 comments on commit cb1eea3

Please sign in to comment.