mirror of
https://github.com/pestphp/pest.git
synced 2026-03-05 23:37:22 +01:00
feat: adds fixture
This commit is contained in:
@ -278,3 +278,28 @@ if (! function_exists('mutates')) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('fixture')) {
|
||||
/**
|
||||
* Returns the absolute path to a fixture file.
|
||||
*/
|
||||
function fixture(string $file): string
|
||||
{
|
||||
$file = implode(DIRECTORY_SEPARATOR, [
|
||||
TestSuite::getInstance()->rootPath,
|
||||
TestSuite::getInstance()->testPath,
|
||||
'Fixtures',
|
||||
str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $file),
|
||||
]);
|
||||
|
||||
$fileRealPath = realpath($file);
|
||||
|
||||
if ($fileRealPath === false) {
|
||||
throw new InvalidArgumentException(
|
||||
'The fixture file ['.$file.'] does not exist.',
|
||||
);
|
||||
}
|
||||
|
||||
return $fileRealPath;
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ namespace Pest;
|
||||
|
||||
function version(): string
|
||||
{
|
||||
return '4.0.0-alpha.2';
|
||||
return '4.0.0-alpha.3';
|
||||
}
|
||||
|
||||
function testDirectory(string $file = ''): string
|
||||
|
||||
11
tests/Features/Fixture.php
Normal file
11
tests/Features/Fixture.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
it('may return a file path', function () {
|
||||
$file = fixture('phpunit-in-isolation.xml');
|
||||
|
||||
expect($file)->toBeString()
|
||||
->toBeFile();
|
||||
});
|
||||
|
||||
it('may throw an exception if the file does not exist', function () {
|
||||
fixture('file-that-does-not-exist.php');
|
||||
Reference in New Issue
Block a user