mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
feat: adds toHaveFileSystemPermissions expectation
This commit is contained in:
@ -20,7 +20,7 @@ final class Base extends AbstractPreset
|
||||
'debug_print_backtrace',
|
||||
'dump',
|
||||
'ray',
|
||||
'ds',
|
||||
'ds',
|
||||
'die',
|
||||
'goto',
|
||||
'global',
|
||||
|
||||
@ -37,5 +37,11 @@ final class Security extends AbstractPreset
|
||||
'dl',
|
||||
'assert',
|
||||
])->not->toBeUsed();
|
||||
|
||||
foreach ($this->userNamespaces as $namespace) {
|
||||
$this->expectations[] = expect($namespace)
|
||||
->not
|
||||
->toHaveFileSystemPermissions('0777');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -434,6 +434,19 @@ final class Expectation
|
||||
return ToUse::make($this, $targets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given expectation target does have the given permissions
|
||||
*/
|
||||
public function toHaveFileSystemPermissions(string $permissions): ArchExpectation
|
||||
{
|
||||
return Targeted::make(
|
||||
$this,
|
||||
fn (ObjectDescription $object): bool => substr(sprintf('%o', fileperms($object->path)), -4) === $permissions,
|
||||
sprintf('permissions to be [%s]', $permissions),
|
||||
FileLineFinder::where(fn (string $line): bool => str_contains($line, '<?php')),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given expectation target use the "declare(strict_types=1)" declaration.
|
||||
*/
|
||||
|
||||
@ -75,6 +75,19 @@ final class OppositeExpectation
|
||||
), is_string($targets) ? [$targets] : $targets));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given expectation target does not have the given permissions
|
||||
*/
|
||||
public function toHaveFileSystemPermissions(string $permissions): ArchExpectation
|
||||
{
|
||||
return Targeted::make(
|
||||
$this->original,
|
||||
fn (ObjectDescription $object): bool => substr(sprintf('%o', fileperms($object->path)), -4) !== $permissions,
|
||||
sprintf('permissions not to be [%s]', $permissions),
|
||||
FileLineFinder::where(fn (string $line): bool => str_contains($line, '<?php')),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given expectation target does not use the "declare(strict_types=1)" declaration.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user