mirror of
https://github.com/Respect/Validation.git
synced 2026-03-16 23:35:45 +01:00
This commit introduces REUSE compliance by annotating all files with SPDX information and placing the reused licences in the LICENSES folder. We additionally removed the docheader tool which is made obsolete by this change. The main LICENSE and copyright text of the project is now not under my personal name anymore, and it belongs to "The Respect Project Contributors" instead. This change restores author names to several files, giving the appropriate attribution for contributions.
80 lines
4 KiB
PHP
80 lines
4 KiB
PHP
<?php
|
|
|
|
/*
|
|
* SPDX-License-Identifier: MIT
|
|
* SPDX-FileCopyrightText: (c) Respect Project Contributors
|
|
* SPDX-FileContributor: Henrique Moody <henriquemoody@gmail.com>
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
use org\bovigo\vfs\content\LargeFileContent;
|
|
use org\bovigo\vfs\vfsStream;
|
|
|
|
beforeEach(function (): void {
|
|
$this->root = vfsStream::setup();
|
|
|
|
$this->file2Kb = vfsStream::newFile('2kb.txt')
|
|
->withContent(LargeFileContent::withKilobytes(2))
|
|
->at($this->root);
|
|
|
|
$this->file2Mb = vfsStream::newFile('3mb.txt')
|
|
->withContent(LargeFileContent::withMegabytes(3))
|
|
->at($this->root);
|
|
});
|
|
|
|
test('Default', catchAll(
|
|
fn() => v::size('KB', v::lessThan(2))->assert($this->file2Kb->url()),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('The size in kilobytes of "vfs://root/2kb.txt" must be less than 2')
|
|
->and($fullMessage)->toBe('- The size in kilobytes of "vfs://root/2kb.txt" must be less than 2')
|
|
->and($messages)->toBe(['sizeLessThan' => 'The size in kilobytes of "vfs://root/2kb.txt" must be less than 2']),
|
|
));
|
|
|
|
test('Wrong type', catchAll(
|
|
fn() => v::size('KB', v::lessThan(2))->assert(new stdClass()),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('`stdClass {}` must be a filename or an instance of SplFileInfo or a PSR-7 interface')
|
|
->and($fullMessage)->toBe('- `stdClass {}` must be a filename or an instance of SplFileInfo or a PSR-7 interface')
|
|
->and($messages)->toBe(['sizeLessThan' => '`stdClass {}` must be a filename or an instance of SplFileInfo or a PSR-7 interface']),
|
|
));
|
|
|
|
test('Inverted', catchAll(
|
|
fn() => v::size('MB', v::not(v::equals(3)))->assert($this->file2Mb->url()),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('The size in megabytes of "vfs://root/3mb.txt" must not be equal to 3')
|
|
->and($fullMessage)->toBe('- The size in megabytes of "vfs://root/3mb.txt" must not be equal to 3')
|
|
->and($messages)->toBe(['sizeNotEquals' => 'The size in megabytes of "vfs://root/3mb.txt" must not be equal to 3']),
|
|
));
|
|
|
|
test('Wrapped with name', catchAll(
|
|
fn() => v::size('KB', v::named('Wrapped', v::lessThan(2)))->assert($this->file2Kb->url()),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('The size in kilobytes of Wrapped must be less than 2')
|
|
->and($fullMessage)->toBe('- The size in kilobytes of Wrapped must be less than 2')
|
|
->and($messages)->toBe(['sizeLessThan' => 'The size in kilobytes of Wrapped must be less than 2']),
|
|
));
|
|
|
|
test('Wrapper with name', catchAll(
|
|
fn() => v::named('Wrapper', v::size('KB', v::lessThan(2)))->assert($this->file2Kb->url()),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('The size in kilobytes of Wrapper must be less than 2')
|
|
->and($fullMessage)->toBe('- The size in kilobytes of Wrapper must be less than 2')
|
|
->and($messages)->toBe(['sizeLessThan' => 'The size in kilobytes of Wrapper must be less than 2']),
|
|
));
|
|
|
|
test('Chained wrapped rule', catchAll(
|
|
fn() => v::size('KB', v::between(5, 7)->odd())->assert($this->file2Kb->url()),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('The size in kilobytes of "vfs://root/2kb.txt" must be between 5 and 7')
|
|
->and($fullMessage)->toBe(<<<'FULL_MESSAGE'
|
|
- "vfs://root/2kb.txt" must pass all the rules
|
|
- The size in kilobytes of "vfs://root/2kb.txt" must be between 5 and 7
|
|
- The size in kilobytes of "vfs://root/2kb.txt" must be an odd number
|
|
FULL_MESSAGE)
|
|
->and($messages)->toBe([
|
|
'__root__' => '"vfs://root/2kb.txt" must pass all the rules',
|
|
'sizeBetween' => 'The size in kilobytes of "vfs://root/2kb.txt" must be between 5 and 7',
|
|
'sizeOdd' => 'The size in kilobytes of "vfs://root/2kb.txt" must be an odd number',
|
|
]),
|
|
));
|