ddev / ddev

Docker-based local PHP+Node.js web development environments
https://ddev.com
Apache License 2.0
2.71k stars 595 forks source link

Running phpunit with WordPress (and testing a plugin) #4383

Closed Ebeldev closed 1 year ago

Ebeldev commented 1 year ago

Is there an existing issue for this?

Run a Diagnostic and Paste Link Here

I wanted to know if there is a way to setup or guide on how to setup a WordPress plugin to use the phpunit with DDEV ?

So far my reasearch and tests have not been successfull.

Thank you for your help,

Expected Behavior

I want to use the wp cli scaffold command with the use of their script to install and use phpunit.

But it does not work.

Actual Behavior

I want to setup a WordPress plugin to include phpunit tests.

Steps To Reproduce

No response

Anything else?

I wanted to know if there is a way to setup or guide on how to setup a WordPress plugin to use the phpunit with DDEV ?

So far my reasearch and tests have not been successfull.

Thank you for your help,

rfay commented 1 year ago

Do you already have the phpunit tests in there? Have you composer-installed phpunit?

Ebeldev commented 1 year ago

Hi @rfay ,

Yes, I have installed phpunit on my machine with homebrew. And I also installed it, locally in the plugin.

Ebeldev commented 1 year ago

Screen Shot 2022-11-15 at 1 18 28 PM

rfay commented 1 year ago

You need phpunit in your code's vendor directory. Install it with composer. Having it on your computer is not relevant. The code in the container cannot access anything on your computer.

Please use ddev ssh to start learning about this. When you can use phpunit in there, then you are ready to start.

rfay commented 1 year ago

phpunit when installed is usually in vendor/bin/phpunit, for example. see https://github.com/weitzman/ddev-selenium-standalone-chrome and its readme.

rfay commented 1 year ago

@mandrasch can you offer any help here? (@mandrasch is an expert with WP and DDEV)

Ebeldev commented 1 year ago

@rfay I forgot to mentionned it, I also did try it in ssh in the container.

Here is the error when I then start my unit tests.

mac-dw-eti@rabaischocs-web:/var/www/html/wp-content/plugins/rc-reports$ ./vendor/bin/phpunit Could not find /tmp/wordpress-tests-lib/includes/functions.php, have you run bin/install-wp-tests.sh ?

I did follow the setup instruction : https://pippinsplugins.com/unit-tests-wordpress-plugins-setting-up-testing-suite/. you set up wordpress with phpunit, with the wp cli it uses a bash script. After the script has been run. And then try to do any unit test I get the error mentionned.

From our understanding the error would be in the bash script. The script seems to not know it's in a container.

Ebeldev commented 1 year ago

@rfay By the way, I really like working with ddev.

rfay commented 1 year ago

Have you run bin/install-wp-tests.sh?

It seems to install something in /tmp/wordpress-tests-lib, and /tmp is a volatile directory in ddev (it gets recreated on every start)

Ebeldev commented 1 year ago

Yes I did run bin/install-wp-tests.sh command.

rfay commented 1 year ago

You'll need to run it each time you restart, since /tmp/ goes away on restart.

You need to look in /tmp/wordpress-tests-lib and see what's there or not there.

Make sure everything you're doing right now is inside the container (ddev ssh)

Lots of other people have had this problem before you, https://www.google.com/search?q=Could+not+find+%2Ftmp%2Fwordpress-tests-lib%2Fincludes%2Ffunctions.php%2C+have+you+run+bin%2Finstall-wp-tests.sh&oq=Could+not+find+%2Ftmp%2Fwordpress-tests-lib%2Fincludes%2Ffunctions.php%2C+have+you+run+bin%2Finstall-wp-tests.sh&aqs=chrome..69i57j0i512.239j0j9&sourceid=chrome&ie=UTF-8

rfay commented 1 year ago

No response after quite some time, I'll convert this to a discussion.