Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/Expectation.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Pest\Arch\Expectations\ToUse;
use Pest\Arch\Expectations\ToUseNothing;
use Pest\Arch\PendingArchExpectation;
use Pest\Arch\Support\Composer;
use Pest\Arch\Support\FileLineFinder;
use Pest\Concerns\Extendable;
use Pest\Concerns\Pipeable;
Expand Down Expand Up @@ -667,6 +668,41 @@ public function toHavePrivateMethods(): void
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.
*/
Expand Down