Skip to content

Commit

Permalink
Merge pull request #7 from hopeseekr/better_arrays
Browse files Browse the repository at this point in the history
Now filters out the "[]" when checking for arrays of something.
  • Loading branch information
hopeseekr authored Jul 29, 2019
2 parents 8d3b606 + 05cd1a5 commit 64856c3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
23 changes: 13 additions & 10 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
<phpunit bootstrap="./vendor/autoload.php"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
testdox="true"
stopOnError="true"
stopOnFailure="true">
<testsuites>
<testsuite name="Package">
<directory suffix=".php">./tests/</directory>
<testsuite name="main">
<directory>./tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src/</directory>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>

<logging>
<log type="coverage-html" target="./coverage" lowUpperBound="35" highLowerBound="85"/>
</logging>
</phpunit>
1 change: 1 addition & 0 deletions src/DataTypeValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public function assertIsArrayOfSomething($values, string $dataType): void
{
$this->assertIsArray($values);

$dataType = substr($dataType, -2) === '[]' ? substr($dataType, 0, -2) : $dataType;
foreach ($values as $i => $value) {
if (!$this->isA->isType($value, $dataType)) {
throw new InvalidDataTypeException("Index '$i' is not a valid '$dataType'.");
Expand Down
6 changes: 6 additions & 0 deletions tests/DataTypeValidatorAssertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,17 @@ public function testWillAssertAnArrayOfSomething()
{
$goodArrays = [
'int' => $this->getDataByType('int', DataTypesLists::getValidStrictDataAndTypes()),
'int[]' => $this->getDataByType('int', DataTypesLists::getValidStrictDataAndTypes()),
'bool' => $this->getDataByType('bool', DataTypesLists::getValidStrictDataAndTypes()),
'bool[]' => $this->getDataByType('bool', DataTypesLists::getValidStrictDataAndTypes()),
'float' => $this->getDataByType('float', DataTypesLists::getValidStrictDataAndTypes()),
'float[]' => $this->getDataByType('float', DataTypesLists::getValidStrictDataAndTypes()),
'string' => $this->getDataByType('string', DataTypesLists::getValidStrictDataAndTypes()),
'string[]' => $this->getDataByType('string', DataTypesLists::getValidStrictDataAndTypes()),
'isAStrictDataType' => [new IsAStrictDataType(), new IsAStrictDataType(), new IsAStrictDataType()],
'isAStrictDataType[]' => [new IsAStrictDataType(), new IsAStrictDataType(), new IsAStrictDataType()],
'isAFuzzyDataType' => [new IsAFuzzyDataType(), new IsAFuzzyDataType(), new IsAFuzzyDataType()],
'isAFuzzyDataType[]' => [new IsAFuzzyDataType(), new IsAFuzzyDataType(), new IsAFuzzyDataType()],
isAFuzzyDataType::class => [new IsAFuzzyDataType(), new IsAFuzzyDataType(), new IsAFuzzyDataType()],
];

Expand Down

0 comments on commit 64856c3

Please sign in to comment.