mirror of
https://github.com/Respect/Validation.git
synced 2024-06-08 16:52:16 +02:00
Increase test coverage for some rules (#1412)
- Add test for null value in the Cnpj rule. - Add UploadedFileInterface object test for Size rule. - Add test for invalid values in Sorted rule.
This commit is contained in:
parent
508566eafc
commit
afa4cc41ea
|
@ -75,6 +75,7 @@ final class CnpjTest extends RuleTestCase
|
||||||
[$rule, '123'],
|
[$rule, '123'],
|
||||||
[$rule, '992999999999929384'],
|
[$rule, '992999999999929384'],
|
||||||
[$rule, '99-010-0.'],
|
[$rule, '99-010-0.'],
|
||||||
|
[$rule, null],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,9 @@ namespace Respect\Validation\Rules;
|
||||||
|
|
||||||
use org\bovigo\vfs\content\LargeFileContent;
|
use org\bovigo\vfs\content\LargeFileContent;
|
||||||
use org\bovigo\vfs\vfsStream;
|
use org\bovigo\vfs\vfsStream;
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use Psr\Http\Message\StreamInterface;
|
use Psr\Http\Message\StreamInterface;
|
||||||
|
use Psr\Http\Message\UploadedFileInterface;
|
||||||
use Respect\Validation\Exceptions\ComponentException;
|
use Respect\Validation\Exceptions\ComponentException;
|
||||||
use Respect\Validation\Test\RuleTestCase;
|
use Respect\Validation\Test\RuleTestCase;
|
||||||
use SplFileInfo;
|
use SplFileInfo;
|
||||||
|
@ -40,6 +42,14 @@ final class SizeTest extends RuleTestCase
|
||||||
->withContent(LargeFileContent::withMegabytes(2))
|
->withContent(LargeFileContent::withMegabytes(2))
|
||||||
->at($root);
|
->at($root);
|
||||||
|
|
||||||
|
/** @var MockObject $psr7Stream1Mb */
|
||||||
|
$psr7Stream1Mb = $this->createMock(StreamInterface::class);
|
||||||
|
$psr7Stream1Mb->expects(self::once())->method('getSize')->willReturn(1024);
|
||||||
|
|
||||||
|
/** @var MockObject $psr7UploadedFileMb */
|
||||||
|
$psr7UploadedFileMb = $this->createMock(UploadedFileInterface::class);
|
||||||
|
$psr7UploadedFileMb->expects(self::once())->method('getSize')->willReturn(1024);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'file with at least 1kb' => [new Size('1kb', null), $file2Kb->url()],
|
'file with at least 1kb' => [new Size('1kb', null), $file2Kb->url()],
|
||||||
'file with at least 2k' => [new Size('2kb', null), $file2Kb->url()],
|
'file with at least 2k' => [new Size('2kb', null), $file2Kb->url()],
|
||||||
|
@ -52,6 +62,8 @@ final class SizeTest extends RuleTestCase
|
||||||
'file with up to 3mb' => [new Size(null, '3mb'), $file2Mb->url()],
|
'file with up to 3mb' => [new Size(null, '3mb'), $file2Mb->url()],
|
||||||
'file between 1mb and 3mb' => [new Size('1mb', '3mb'), $file2Mb->url()],
|
'file between 1mb and 3mb' => [new Size('1mb', '3mb'), $file2Mb->url()],
|
||||||
'SplFileInfo instance' => [new Size('1mb', '3mb'), new SplFileInfo($file2Mb->url())],
|
'SplFileInfo instance' => [new Size('1mb', '3mb'), new SplFileInfo($file2Mb->url())],
|
||||||
|
'PSR-7 stream' => [new Size('1kb', '2kb'), $psr7Stream1Mb],
|
||||||
|
'PSR-7 UploadedFile' => [new Size('1kb', '2kb'), $psr7UploadedFileMb],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,9 +80,14 @@ final class SizeTest extends RuleTestCase
|
||||||
->withContent(LargeFileContent::withMegabytes(2))
|
->withContent(LargeFileContent::withMegabytes(2))
|
||||||
->at($root);
|
->at($root);
|
||||||
|
|
||||||
|
/** @var MockObject $psr7Stream1Mb */
|
||||||
$psr7Stream1Mb = $this->createMock(StreamInterface::class);
|
$psr7Stream1Mb = $this->createMock(StreamInterface::class);
|
||||||
$psr7Stream1Mb->expects(self::once())->method('getSize')->willReturn(1024);
|
$psr7Stream1Mb->expects(self::once())->method('getSize')->willReturn(1024);
|
||||||
|
|
||||||
|
/** @var MockObject $psr7UploadedFileMb */
|
||||||
|
$psr7UploadedFileMb = $this->createMock(UploadedFileInterface::class);
|
||||||
|
$psr7UploadedFileMb->expects(self::once())->method('getSize')->willReturn(1024);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'file with at least 3kb' => [new Size('3kb', null), $file2Kb->url()],
|
'file with at least 3kb' => [new Size('3kb', null), $file2Kb->url()],
|
||||||
'file with up to 1kb' => [new Size(null, '1kb'), $file2Kb->url()],
|
'file with up to 1kb' => [new Size(null, '1kb'), $file2Kb->url()],
|
||||||
|
@ -82,6 +99,7 @@ final class SizeTest extends RuleTestCase
|
||||||
'SplFileInfo instancia' => [new Size('1pb', '3pb'), new SplFileInfo($file2Mb->url())],
|
'SplFileInfo instancia' => [new Size('1pb', '3pb'), new SplFileInfo($file2Mb->url())],
|
||||||
'parameter invalid' => [new Size('1pb', '3pb'), []],
|
'parameter invalid' => [new Size('1pb', '3pb'), []],
|
||||||
'PSR-7 stream' => [new Size('1MB', '1.1MB'), $psr7Stream1Mb],
|
'PSR-7 stream' => [new Size('1MB', '1.1MB'), $psr7Stream1Mb],
|
||||||
|
'PSR-7 UploadedFile' => [new Size('1MB', '1.1MB'), $psr7UploadedFileMb],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ namespace Respect\Validation\Rules;
|
||||||
|
|
||||||
use Respect\Validation\Exceptions\ComponentException;
|
use Respect\Validation\Exceptions\ComponentException;
|
||||||
use Respect\Validation\Test\RuleTestCase;
|
use Respect\Validation\Test\RuleTestCase;
|
||||||
|
use stdClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group rules
|
* @group rules
|
||||||
|
@ -55,6 +56,10 @@ final class SortedTest extends RuleTestCase
|
||||||
'DESC string-sequence with ASC validation' => [new Sorted('ASC'), '321'],
|
'DESC string-sequence with ASC validation' => [new Sorted('ASC'), '321'],
|
||||||
'ASC array-sequence with DESC validation' => [new Sorted('DESC'), [1, 2, 3]],
|
'ASC array-sequence with DESC validation' => [new Sorted('DESC'), [1, 2, 3]],
|
||||||
'ASC string-sequence with DESC validation' => [new Sorted('DESC'), 'abc'],
|
'ASC string-sequence with DESC validation' => [new Sorted('DESC'), 'abc'],
|
||||||
|
'unsupported value (integer)' => [new Sorted('DESC'), 1 ],
|
||||||
|
'unsupported value (float)' => [new Sorted('DESC'), 1.2 ],
|
||||||
|
'unsupported value (bool)' => [new Sorted('DESC'), true ],
|
||||||
|
'unsupported value (object)' => [new Sorted('DESC'), new stdClass() ],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue