Payal Patel
Payal Patel

Reputation: 11

WordPress phpunit test not found WP_UnitTestCase

I have wordpress project running on my local. I use docker. I install phpunit using composer require phpunit/phpunit command. (Version is 8.5) Then I use scaffold command to create plugin test files. docker-compose exec wp my-project-name wp scaffold plugin-tests sample-plugin (I have all files)

Then I run following command but it didn't create tmp/ directory in my project. Instead it made directory here: C:\Users\Unknown\AppData\Local\Temp. bin/install-wp-tests.sh wordpress_my root 'mypassword' localhost latest

Now when I run following command, it gives following error. vendor/bin/phpunit --bootstrap ./vendor/autoload.php wp-content/plugins/sample-plugin/tests/test-sample.php

Fatal error: Uncaught Error: Class 'WP_UnitTestCase' not found in C:\git\my-project\wp-content\plugins\sample-plugin\tests\test-sample.php:11 Stack trace:

I also followed first 4 steps from https://make.wordpress.org/core/handbook/testing/automated-testing/phpunit/ but no luck.

Also https://www.smashingmagazine.com/2017/12/automated-testing-wordpress-plugins-phpunit/ but no luck

Please help me!

Upvotes: 1

Views: 697

Answers (1)

clockw0rk
clockw0rk

Reputation: 568

I just had a similar problem where PHPUnit would not find WP_UnitTestCase, turned out the problem was I somehow yiked up my namespaces and imports.

After I used composer dumpautoload and removed the namespaces I falsely believed to be right, it worked again. The confusion began when I tried to fiddle the testcases into composer.json's autoload configuration - I came to the conclusion to just don't touch it.

Upvotes: 0

Related Questions