mirror of
https://github.com/pestphp/pest.git
synced 2026-04-21 06:27:28 +02:00
feat: add toBeCasedCorrectly arch test assertion
This commit is contained in:
@ -18,6 +18,7 @@ use Pest\Arch\Expectations\ToOnlyUse;
|
|||||||
use Pest\Arch\Expectations\ToUse;
|
use Pest\Arch\Expectations\ToUse;
|
||||||
use Pest\Arch\Expectations\ToUseNothing;
|
use Pest\Arch\Expectations\ToUseNothing;
|
||||||
use Pest\Arch\PendingArchExpectation;
|
use Pest\Arch\PendingArchExpectation;
|
||||||
|
use Pest\Arch\Support\Composer;
|
||||||
use Pest\Arch\Support\FileLineFinder;
|
use Pest\Arch\Support\FileLineFinder;
|
||||||
use Pest\Concerns\Extendable;
|
use Pest\Concerns\Extendable;
|
||||||
use Pest\Concerns\Pipeable;
|
use Pest\Concerns\Pipeable;
|
||||||
@ -669,6 +670,41 @@ final class Expectation
|
|||||||
throw InvalidExpectation::fromMethods(['toHavePrivateMethods']);
|
throw InvalidExpectation::fromMethods(['toHavePrivateMethods']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the given expectation target is cased correctly.
|
||||||
|
*/
|
||||||
|
public function toBeCasedCorrectly(): ArchExpectation
|
||||||
|
{
|
||||||
|
return Targeted::make(
|
||||||
|
$this,
|
||||||
|
function (ObjectDescription $object): bool {
|
||||||
|
if (! isset($object->reflectionClass)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$realPath = realpath($object->path);
|
||||||
|
|
||||||
|
foreach (Composer::userNamespaces() as $directory => $namespace) {
|
||||||
|
if (str_starts_with($realPath, $directory)) {
|
||||||
|
$relativePath = substr($realPath, strlen($directory) + 1);
|
||||||
|
$relativePath = explode('.', $relativePath)[0];
|
||||||
|
$classFromPath = $namespace . '\\' . str_replace(DIRECTORY_SEPARATOR, '\\', $relativePath);
|
||||||
|
|
||||||
|
if ($classFromPath === $object->reflectionClass->getName()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
"to be cased correctly",
|
||||||
|
FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that the given expectation target is enum.
|
* Asserts that the given expectation target is enum.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user