mirror of
https://github.com/Respect/Validation.git
synced 2026-03-15 14:55:44 +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.
69 lines
2.1 KiB
PHP
69 lines
2.1 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 Respect\Validation\Exceptions\ValidationException;
|
|
use Respect\Validation\Test\Stubs\MyValidator;
|
|
|
|
test('Should overwrite file and line in the Validator class', function (): void {
|
|
try {
|
|
v::intType()->assert('string');
|
|
} catch (ValidationException $e) {
|
|
expect($e->getFile())->toBe(__FILE__);
|
|
expect($e->getLine())->toBe(__LINE__ - 3);
|
|
}
|
|
});
|
|
|
|
test('Should overwrite file and line in ValidationException', function (): void {
|
|
try {
|
|
MyValidator::assertIntType('string');
|
|
} catch (ValidationException $e) {
|
|
expect($e->getFile())->toBe(__FILE__);
|
|
expect($e->getLine())->toBe(__LINE__ - 3);
|
|
}
|
|
});
|
|
|
|
test('Should not overwrite file and line when created manually', function (): void {
|
|
try {
|
|
throw new ValidationException('message', 'fullMessage', ['id' => 'message']);
|
|
} catch (ValidationException $e) {
|
|
expect($e->getFile())->toBe(__FILE__);
|
|
expect($e->getLine())->toBe(__LINE__ - 3);
|
|
}
|
|
});
|
|
|
|
|
|
test('Should not overwrite file and line when file cannot be ever traced', function (): void {
|
|
try {
|
|
throw new ValidationException('message', 'fullMessage', ['id' => 'message'], ['/tmp/unknown']);
|
|
} catch (ValidationException $e) {
|
|
expect($e->getFile())->toBe(__FILE__);
|
|
expect($e->getLine())->toBe(__LINE__ - 3);
|
|
}
|
|
});
|
|
|
|
|
|
test('Should go not overwrite file and line when it runs out of choices', function (): void {
|
|
try {
|
|
$trace = array_unique(
|
|
array_filter(
|
|
array_map(
|
|
fn($trace) => $trace['file'] ?? null,
|
|
debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS),
|
|
),
|
|
),
|
|
);
|
|
$trace[] = __FILE__;
|
|
|
|
throw new ValidationException('message', 'fullMessage', ['id' => 'message'], $trace);
|
|
} catch (ValidationException $e) {
|
|
expect($e->getFile())->toBe(__FILE__);
|
|
expect($e->getLine())->toBe(__LINE__ - 3);
|
|
}
|
|
});
|