I have a sum.php
file which has the following function:
# Adds two integers
function sum(
int $a,
int $b
): int
{
return $a + $b;
}
In the file SumTest.php
, I’m testing sum()
like this:
it('sums two integers', function () {
$result = sum(1, 2);
expect($result)->toBe(3);
});
After running ./vendor/bin/pest
I get this result:
FAIL TestsUnitSumTest
⨯ it sums two integers 0.02s
────────────────────────────────────────────────────────────────
FAILED TestsUnitSumTest > it sums two integers Error
Call to undefined function sum()
at testsUnitSumTest.php:4
1▕ <?php
2▕
3▕ it('sums two integers', function () {
➜ 4▕ $result = sum(1, 2);
5▕
6▕ expect($result)->toBe(3);
7▕ });
8▕
1 testsUnitSumTest.php:4
Why isn’t it recognizing the sum()
function?