Closed normykinz closed 1 year ago
Can you elaborate a little more, and share more detail? Environment used, etc.
Might have something related to this also in our env, upgrading to Pest 2 gives this error:
A facade root has not been set.
which would seem to be Laravel not being bootstrapped
Here's my phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./app</directory>
</include>
</coverage>
<php>
<env name="APP_ENV" value="testing"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
<env name="MAIL_MAILER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="TELESCOPE_ENABLED" value="false"/>
</php>
</phpunit>
It's also ignoring any custom functions in Pest.php.
I have the same problem. Also, I can't access to variables I declared in beforeEach and custom functions in file Pest.php.
Hi guys, same here, cant seem to use my custom helper functions #707.
Seems to be related to the usage of Windows. We are checking...
I'm experiencing this problem in Docker on MacOS
@ConnySjoblom We are checking, thanks!
@ConnySjoblom Can you share more details? Like full pwd of your application, how are you running Pest on docker, etc?
Code located in /Users/connysjoblom/Code/<app name>
Running pest with sail bin pest
We're using beforeEach quite heavily, and CreateApplication.php is standard except some usage of Http::fake()
Any other specifics you would need?
What's your tests directory structure? Can I see your Pest.php file?
Bridge
CreatesApplication.php
Feature
Pest.php
TestCase.php
Unit
Utilities
No subfolders within those folders
@ConnySjoblom So, if you declare a custom helper, within Pest.php, you can't use it in your Feature tests?
Using the example toBeOne()
in a new empty testfile I get this:
Call to a member function toBeOne() on int
at tests/Feature/Asd.php:4
1▕ <?php
2▕
3▕ it('works', function () {
➜ 4▕ expect(1)->toBeOne();
5▕ });
6▕
Hope is not asking too much. But can you try to understand, what within this file is not working for your environment? https://github.com/pestphp/pest/blob/2.x/src/Bootstrappers/BootFiles.php#L43
I can have a look at it, takes a minute before I can begin though
^ "/var/www/html/tests/Unit//Expectations"
^ "/var/www/html/tests/Unit//Expectations.php"
^ "/var/www/html/tests/Unit//Helpers"
^ "/var/www/html/tests/Unit//Helpers.php"
^ "/var/www/html/tests/Unit//Pest.php"
all hit line 46
On the Pest\ConfigLoader file, can you put this code on the line 63, and let me know how it goes?
$basePath = str_contains($directory, DIRECTORY_SEPARATOR)
? Str::beforeLast($directory, DIRECTORY_SEPARATOR)
: Str::beforeLast($directory, '/');
return is_dir($basePath) ? $basePath : self::DEFAULT_TESTS_PATH;
Hope is not asking too much. But can you try to understand, what within this file is not working for your environment? https://github.com/pestphp/pest/blob/2.x/src/Bootstrappers/BootFiles.php#L43
I dumped whether file exists and what the file names is
foreach (self::STRUCTURE as $filename) {
$filename = sprintf('%s%s%s', $testsPath, DIRECTORY_SEPARATOR, $filename);
dump($filename);
dump(file_exists($filename));
if (! file_exists($filename)) {
continue;
}
and my output is this:
^ "C:\OSPanel\domains\pest2./tests/Unit/\Expectations"
^ false
^ "C:\OSPanel\domains\pest2./tests/Unit/\Expectations.php"
^ false
^ "C:\OSPanel\domains\pest2./tests/Unit/\Helpers"
^ false
^ "C:\OSPanel\domains\pest2./tests/Unit/\Helpers.php"
^ false
^ "C:\OSPanel\domains\pest2./tests/Unit/\Pest.php"
^ false
seems like it fails to find the files
$basePath = str_contains($directory, DIRECTORY_SEPARATOR) ? Str::beforeLast($directory, DIRECTORY_SEPARATOR) : Str::beforeLast($directory, '/'); return is_dir($basePath) ? $basePath : self::DEFAULT_TESTS_PATH;
Same error with this here, but noticed we have two testsuites defined in phpunit.xml like this:
<testsuite name="Unit">
<directory>tests/Unit</directory>
<directory>tests/Utilities</directory>
</testsuite>
<testsuite name="Feature">
<directory>tests/Feature</directory>
</testsuite>
Removing these and creating one new like this
<testsuite name="Unit">
<directory>tests</directory>
</testsuite>
Seems to make everything load as it should
Fixed found. Releasing Pest with that fix.
Pest v2.0.2 released, and it fixes this issue. Please update and let me know how it goes.
Brilliant thanks for all your great work, Nuno. It's woking like a champion now!
I'm a bit late to the show, but I can also confirm it working after the update, thanks for the quick debugging @nunomaduro !
In a fresh Laravel project with the Laravel plugin installed generated tests seem to be ignoring the uses statment in Pest.php
Doesn't work but using the same uses call in the test itself does work.