mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
feat: not.toHaveSuspiciousCharacters
This commit is contained in:
@ -4,6 +4,9 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Pest\ArchPresets;
|
namespace Pest\ArchPresets;
|
||||||
|
|
||||||
|
use Pest\Arch\Contracts\ArchExpectation;
|
||||||
|
use Pest\Expectation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
@ -89,5 +92,9 @@ final class Php extends AbstractPreset
|
|||||||
'xdebug_var_dump',
|
'xdebug_var_dump',
|
||||||
'trap',
|
'trap',
|
||||||
])->not->toBeUsed();
|
])->not->toBeUsed();
|
||||||
|
|
||||||
|
$this->eachUserNamespace(
|
||||||
|
fn (Expectation $namespace): ArchExpectation => $namespace->not->toHaveSuspiciousCharacters(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -897,16 +897,9 @@ final class Expectation
|
|||||||
/**
|
/**
|
||||||
* Asserts that the source code of the given expectation target does not include suspicious characters.
|
* Asserts that the source code of the given expectation target does not include suspicious characters.
|
||||||
*/
|
*/
|
||||||
public function toNotIncludeSuspiciousCharacters(): ArchExpectation
|
public function toHaveSuspiciousCharacters(): ArchExpectation
|
||||||
{
|
{
|
||||||
$checker = new Spoofchecker();
|
throw InvalidExpectation::fromMethods(['toHaveSuspiciousCharacters']);
|
||||||
|
|
||||||
return Targeted::make(
|
|
||||||
$this,
|
|
||||||
fn (ObjectDescription $object) => ! $checker->isSuspicious(file_get_contents($object->path)),
|
|
||||||
'to not include suspicious characters',
|
|
||||||
FileLineFinder::where(fn (string $line) => $checker->isSuspicious($line)),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -24,6 +24,7 @@ use PHPUnit\Framework\AssertionFailedError;
|
|||||||
use PHPUnit\Framework\ExpectationFailedException;
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
use ReflectionMethod;
|
use ReflectionMethod;
|
||||||
use ReflectionProperty;
|
use ReflectionProperty;
|
||||||
|
use Spoofchecker;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -278,6 +279,24 @@ final readonly class OppositeExpectation
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the given expectation target does not have suspicious characters.
|
||||||
|
*/
|
||||||
|
public function toHaveSuspiciousCharacters(): ArchExpectation
|
||||||
|
{
|
||||||
|
$checker = new Spoofchecker;
|
||||||
|
|
||||||
|
/** @var Expectation<array<int, string>|string> $original */
|
||||||
|
$original = $this->original;
|
||||||
|
|
||||||
|
return Targeted::make(
|
||||||
|
$original,
|
||||||
|
fn (ObjectDescription $object): bool => ! $checker->isSuspicious((string) file_get_contents($object->path)),
|
||||||
|
'to not include suspicious characters',
|
||||||
|
FileLineFinder::where(fn (string $line): bool => $checker->isSuspicious($line)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that the given expectation target does not have the given methods.
|
* Asserts that the given expectation target does not have the given methods.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1785,4 +1785,4 @@
|
|||||||
✓ pass with dataset with ('my-datas-set-value')
|
✓ pass with dataset with ('my-datas-set-value')
|
||||||
✓ within describe → pass with dataset with ('my-datas-set-value')
|
✓ within describe → pass with dataset with ('my-datas-set-value')
|
||||||
|
|
||||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 39 todos, 35 skipped, 1189 passed (2815 assertions)
|
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 39 todos, 35 skipped, 1189 passed (2816 assertions)
|
||||||
@ -16,7 +16,7 @@ $run = function () {
|
|||||||
|
|
||||||
test('parallel', function () use ($run) {
|
test('parallel', function () use ($run) {
|
||||||
expect($run('--exclude-group=integration'))
|
expect($run('--exclude-group=integration'))
|
||||||
->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 39 todos, 26 skipped, 1179 passed (2791 assertions)')
|
->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 39 todos, 26 skipped, 1179 passed (2792 assertions)')
|
||||||
->toContain('Parallel: 3 processes');
|
->toContain('Parallel: 3 processes');
|
||||||
})->skipOnWindows();
|
})->skipOnWindows();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user