From ef76c04dbe907c65ea2f372630ab8a1327e79d43 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Fri, 27 Jun 2025 02:15:28 +0100 Subject: [PATCH] feat: adds `fixture` --- src/Functions.php | 25 +++++++++++++++++++++++++ src/Pest.php | 2 +- tests/Features/Fixture.php | 11 +++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 tests/Features/Fixture.php diff --git a/src/Functions.php b/src/Functions.php index 1e12fe7e..f17ea15c 100644 --- a/src/Functions.php +++ b/src/Functions.php @@ -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; + } +} diff --git a/src/Pest.php b/src/Pest.php index 865c18d0..47af9ee1 100644 --- a/src/Pest.php +++ b/src/Pest.php @@ -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 diff --git a/tests/Features/Fixture.php b/tests/Features/Fixture.php new file mode 100644 index 00000000..49b4c76a --- /dev/null +++ b/tests/Features/Fixture.php @@ -0,0 +1,11 @@ +toBeString() + ->toBeFile(); +}); + +it('may throw an exception if the file does not exist', function () { + fixture('file-that-does-not-exist.php');