mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
feat: adds toHaveFileSystemPermissions expectation
This commit is contained in:
@ -3,4 +3,5 @@
|
|||||||
3. `pest()->`
|
3. `pest()->`
|
||||||
4. `->notes()`, `->issue`, `->pr`, etc
|
4. `->notes()`, `->issue`, `->pr`, etc
|
||||||
5. `arch()->preset`
|
5. `arch()->preset`
|
||||||
|
6. `toHaveFileSystemPermissions`
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
"nunomaduro/termwind": "^2.0.1",
|
"nunomaduro/termwind": "^2.0.1",
|
||||||
"pestphp/pest-plugin": "^3.0.0",
|
"pestphp/pest-plugin": "^3.0.0",
|
||||||
"pestphp/pest-plugin-arch": "^3.0.0",
|
"pestphp/pest-plugin-arch": "^3.0.0",
|
||||||
"phpunit/phpunit": "^11.2.6"
|
"phpunit/phpunit": "^11.2.7"
|
||||||
},
|
},
|
||||||
"conflict": {
|
"conflict": {
|
||||||
"sebastian/exporter": "<6.0.0",
|
"sebastian/exporter": "<6.0.0",
|
||||||
|
|||||||
@ -37,5 +37,11 @@ final class Security extends AbstractPreset
|
|||||||
'dl',
|
'dl',
|
||||||
'assert',
|
'assert',
|
||||||
])->not->toBeUsed();
|
])->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);
|
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.
|
* 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));
|
), 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.
|
* Asserts that the given expectation target does not use the "declare(strict_types=1)" declaration.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -741,6 +741,11 @@
|
|||||||
✓ class has destructor
|
✓ class has destructor
|
||||||
✓ class has no destructor
|
✓ class has no destructor
|
||||||
|
|
||||||
|
PASS Tests\Features\Expect\toHaveFileSystemPermissions
|
||||||
|
✓ pass
|
||||||
|
✓ failures
|
||||||
|
✓ not failures
|
||||||
|
|
||||||
PASS Tests\Features\Expect\toHaveKebabCaseKeys
|
PASS Tests\Features\Expect\toHaveKebabCaseKeys
|
||||||
✓ pass
|
✓ pass
|
||||||
✓ failures
|
✓ failures
|
||||||
@ -1516,4 +1521,4 @@
|
|||||||
WARN Tests\Visual\Version
|
WARN Tests\Visual\Version
|
||||||
- visual snapshot of help command output
|
- visual snapshot of help command output
|
||||||
|
|
||||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 24 skipped, 1063 passed (2602 assertions)
|
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 24 skipped, 1066 passed (2611 assertions)
|
||||||
16
tests/Features/Expect/toHaveFileSystemPermissions.php
Normal file
16
tests/Features/Expect/toHaveFileSystemPermissions.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Pest\Arch\Exceptions\ArchExpectationFailedException;
|
||||||
|
|
||||||
|
test('pass', function () {
|
||||||
|
expect(Pest\Preset::class)->toHaveFileSystemPermissions('0644')
|
||||||
|
->and('Pest')->not->toHaveFileSystemPermissions('0777');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('failures', function () {
|
||||||
|
expect(Pest\Preset::class)->toHaveFileSystemPermissions('0755');
|
||||||
|
})->throws(ArchExpectationFailedException::class, "Expecting 'src/Preset.php' permissions to be [0755].");
|
||||||
|
|
||||||
|
test('not failures', function () {
|
||||||
|
expect(Pest\Preset::class)->not->toHaveFileSystemPermissions('0644');
|
||||||
|
})->throws(ArchExpectationFailedException::class, "Expecting 'src/Preset.php' permissions not to be [0644].");
|
||||||
@ -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, 13 todos, 19 skipped, 1049 passed (2570 assertions)')
|
->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 1052 passed (2579 assertions)')
|
||||||
->toContain('Parallel: 3 processes');
|
->toContain('Parallel: 3 processes');
|
||||||
})->skipOnWindows();
|
})->skipOnWindows();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user