Regex - isBinaryValue() method - returns information if given value is a binary value

This commit is contained in:
Meritoo
2018-01-10 17:35:42 +01:00
parent 780d4df17e
commit e9b8fb8852
2 changed files with 85 additions and 0 deletions

View File

@@ -344,6 +344,17 @@ class RegexTest extends BaseTestCase
self::assertEquals($expected, Regex::areValidHtmlAttributes($htmlAttributes));
}
/**
* @param string $value Value to verify
* @param bool $expected Information if value is a binary value
*
* @dataProvider provideBinaryValue
*/
public static function testIsBinaryValue($value, $expected)
{
self::assertEquals($expected, Regex::isBinaryValue($value));
}
/**
* Provides name of bundle and information if it's valid name
*
@@ -473,6 +484,62 @@ class RegexTest extends BaseTestCase
];
}
/**
* Provides value to verify if it is a binary value
*
* @return Generator
*/
public function provideBinaryValue()
{
$file1Path = $this->getFilePathForTesting('lorem-ipsum.txt');
$file2Path = $this->getFilePathForTesting('minion.jpg');
yield[
null,
false,
];
yield[
[],
false,
];
yield[
'',
false,
];
yield[
'abc',
false,
];
yield[
'1234',
false,
];
yield[
1234,
false,
];
yield[
12.34,
false,
];
yield[
fread(fopen($file1Path, 'r'), 1),
false,
];
yield[
fread(fopen($file2Path, 'r'), 1),
true,
];
}
/**
* {@inheritdoc}
*/