Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find TestCase object on call stack, related to issue 5403 #902

Closed
vsko-dev opened this issue Aug 8, 2023 · 3 comments
Closed

Cannot find TestCase object on call stack, related to issue 5403 #902

vsko-dev opened this issue Aug 8, 2023 · 3 comments

Comments

@vsko-dev
Copy link

vsko-dev commented Aug 8, 2023

Hello I have an issue related to 5403

Use this versions:
"phpunit/phpunit": "10.3.1",
"pestphp/pest": "2.12.2",
"pestphp/pest-plugin-laravel": "2.10"

I have a standard tests from Laravel pure installation: Tests\Feature\ExampleTest and Tests\Unit\ExampleTest
Try to run them from container 'laravel.test' from Laravel Sail:

root@f13964da5b4b:/var/www/html# php artisan test --env=testing

   PASS  Tests\Unit\ExampleTest
  ✓ that true is true                                                                                                                             0.01s  

   PASS  Tests\Feature\ExampleTest
  ✓ the application returns a successful response                                                                                                 0.15s  

  Tests:    2 passed (2 assertions)
  Duration: 0.26s

When I tried to run them from local machine, got an error:

user@devtel:/var/www/service$ ./vendor/bin/sail artisan test --env=testing

   PASS  Tests\Unit\ExampleTest
  ✓ that true is true

   ERROR  Cannot find TestCase object on call stack

Location: /var/www/html/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:68

#0 /var/www/html/vendor/phpunit/phpunit/src/TextUI/Application.php(176): PHPUnit\TextUI\TestRunner->run()
#1 /var/www/html/vendor/pestphp/pest/src/Kernel.php(91): PHPUnit\TextUI\Application->run()
#2 /var/www/html/vendor/pestphp/pest/bin/pest(91): Pest\Kernel->handle()
#3 /var/www/html/vendor/pestphp/pest/bin/pest(99): {closure}()
#4 {main}

Caused by: /var/www/html/vendor/phpunit/phpunit/src/Event/Value/Test/TestMethodBuilder.php:62

#0 /var/www/html/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php(76): PHPUnit\Event\Code\TestMethodBuilder::fromCallStack()
#1 [internal function]: PHPUnit\Runner\ErrorHandler->__invoke()
#2 /var/www/html/vendor/pestphp/pest/overrides/Runner/ResultCache/DefaultResultCache.php(181): file_put_contents()
#3 /var/www/html/vendor/phpunit/phpunit/src/Runner/ResultCache/ResultCacheHandler.php(58): PHPUnit\Runner\ResultCache\DefaultResultCache->persist()
#4 /var/www/html/vendor/phpunit/phpunit/src/Runner/ResultCache/Subscriber/TestSuiteFinishedSubscriber.php(22): PHPUnit\Runner\ResultCache\ResultCacheHandler->testSuiteFinished()
#5 /var/www/html/vendor/phpunit/phpunit/src/Event/Dispatcher/DirectDispatcher.php(115): PHPUnit\Runner\ResultCache\TestSuiteFinishedSubscriber->notify()
#6 /var/www/html/vendor/phpunit/phpunit/src/Event/Dispatcher/DeferringDispatcher.php(53): PHPUnit\Event\DirectDispatcher->dispatch()
#7 /var/www/html/vendor/phpunit/phpunit/src/Event/Emitter/DispatchingEmitter.php(1046): PHPUnit\Event\DeferringDispatcher->dispatch()
#8 /var/www/html/vendor/phpunit/phpunit/src/Framework/TestSuite.php(345): PHPUnit\Event\DispatchingEmitter->testSuiteFinished()
#9 /var/www/html/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(63): PHPUnit\Framework\TestSuite->run()
#10 /var/www/html/vendor/phpunit/phpunit/src/TextUI/Application.php(176): PHPUnit\TextUI\TestRunner->run()
#11 /var/www/html/vendor/pestphp/pest/src/Kernel.php(91): PHPUnit\TextUI\Application->run()
#12 /var/www/html/vendor/pestphp/pest/bin/pest(91): Pest\Kernel->handle()
#13 /var/www/html/vendor/pestphp/pest/bin/pest(99): {closure}()
#14 {main}.

Would you happen to have any suggestions? Forward thanks.

@devajmeireles
Copy link
Member

Hello I have an issue related to 5403

Use this versions: "phpunit/phpunit": "10.3.1", "pestphp/pest": "2.12.2", "pestphp/pest-plugin-laravel": "2.10"

I have a standard tests from Laravel pure installation: Tests\Feature\ExampleTest and Tests\Unit\ExampleTest Try to run them from container 'laravel.test' from Laravel Sail:

root@f13964da5b4b:/var/www/html# php artisan test --env=testing

   PASS  Tests\Unit\ExampleTest
  ✓ that true is true                                                                                                                             0.01s  

   PASS  Tests\Feature\ExampleTest
  ✓ the application returns a successful response                                                                                                 0.15s  

  Tests:    2 passed (2 assertions)
  Duration: 0.26s

When I tried to run them from local machine, got an error:

user@devtel:/var/www/service$ ./vendor/bin/sail artisan test --env=testing

   PASS  Tests\Unit\ExampleTest
  ✓ that true is true

   ERROR  Cannot find TestCase object on call stack

Location: /var/www/html/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:68

#0 /var/www/html/vendor/phpunit/phpunit/src/TextUI/Application.php(176): PHPUnit\TextUI\TestRunner->run()
#1 /var/www/html/vendor/pestphp/pest/src/Kernel.php(91): PHPUnit\TextUI\Application->run()
#2 /var/www/html/vendor/pestphp/pest/bin/pest(91): Pest\Kernel->handle()
#3 /var/www/html/vendor/pestphp/pest/bin/pest(99): {closure}()
#4 {main}

Caused by: /var/www/html/vendor/phpunit/phpunit/src/Event/Value/Test/TestMethodBuilder.php:62

#0 /var/www/html/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php(76): PHPUnit\Event\Code\TestMethodBuilder::fromCallStack()
#1 [internal function]: PHPUnit\Runner\ErrorHandler->__invoke()
#2 /var/www/html/vendor/pestphp/pest/overrides/Runner/ResultCache/DefaultResultCache.php(181): file_put_contents()
#3 /var/www/html/vendor/phpunit/phpunit/src/Runner/ResultCache/ResultCacheHandler.php(58): PHPUnit\Runner\ResultCache\DefaultResultCache->persist()
#4 /var/www/html/vendor/phpunit/phpunit/src/Runner/ResultCache/Subscriber/TestSuiteFinishedSubscriber.php(22): PHPUnit\Runner\ResultCache\ResultCacheHandler->testSuiteFinished()
#5 /var/www/html/vendor/phpunit/phpunit/src/Event/Dispatcher/DirectDispatcher.php(115): PHPUnit\Runner\ResultCache\TestSuiteFinishedSubscriber->notify()
#6 /var/www/html/vendor/phpunit/phpunit/src/Event/Dispatcher/DeferringDispatcher.php(53): PHPUnit\Event\DirectDispatcher->dispatch()
#7 /var/www/html/vendor/phpunit/phpunit/src/Event/Emitter/DispatchingEmitter.php(1046): PHPUnit\Event\DeferringDispatcher->dispatch()
#8 /var/www/html/vendor/phpunit/phpunit/src/Framework/TestSuite.php(345): PHPUnit\Event\DispatchingEmitter->testSuiteFinished()
#9 /var/www/html/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(63): PHPUnit\Framework\TestSuite->run()
#10 /var/www/html/vendor/phpunit/phpunit/src/TextUI/Application.php(176): PHPUnit\TextUI\TestRunner->run()
#11 /var/www/html/vendor/pestphp/pest/src/Kernel.php(91): PHPUnit\TextUI\Application->run()
#12 /var/www/html/vendor/pestphp/pest/bin/pest(91): Pest\Kernel->handle()
#13 /var/www/html/vendor/pestphp/pest/bin/pest(99): {closure}()
#14 {main}.

Would you happen to have any suggestions? Forward thanks.

Hey, @vsko-dev . Thank you for your report.

I was not able to reproduce the bug by following the same steps you have mentioned:

CleanShot 2023-08-17 at 2 32 58

I will close this issue in order to preserve our organization. Feel free to open a new issue whenever you need.

@rooselle
Copy link

rooselle commented Jan 3, 2024

In case someone still has the problem and wanders here, this worked for me: sudo rm vendor/pestphp/pest/.temp/test-results

@christian-thomas
Copy link

Further to @rooselle's comment - This didn't resolve my issue with Github actions unfortunately.

The problem for me seems to be because composer in my Github Action runs as root, and therefore the vendor directory is owned by root.

The only way I've found to address this, is by either running php artisan test as sudo, or changing the permissions on the vendor directory. Example below:

      - name: Install Dependencies
        uses: php-actions/composer@v6
        with:
          php_version: '${{ matrix.php-version }}'
          php_extensions: intl gd pcntl zip bcmath http exif

      - name: Update Composer 'vendor' Directory Permissions
        run: sudo chown runner:docker -R vendor

      - name: Execute tests
        run: php artisan test

It should be possible to set the --cache-directory to something outside of the vendor directory as per the documentation, but setting the option didn't seem to update anything (Possible related issue). I ran:

./vendor/bin/pest --cache-directory="./storage"

I checked the ./vendor/pestphp/pest/.temp before running this, which showed just a .gitkeep file. After running the above command, I then see the test-results file re-populated in that same directory, where as I would expect it to appear within ./storage.

My issue is resolved by updating the permissions above, but hopefully this helps someone else out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants