• Resolved Carl Gross

    (@carlgross)


    Hello. I’m trying to get started with PHP unit testing in WordPress. This page indicates,

    >> Lastly, sometimes the bash script fails to build WordPress because of how it uses tmp folders. If it fails, then you can manually install WordPress to a writeable directory, and then manually create wp-tests-config.php.

    What exactly does it mean to ‘manually create wp-tests-config.php?’ I know how to create a PHP file–but what should be its contents in this case?

    The reason I ask is because I think I am encountering that very same issue, with tmp folders in Windows. When I execute this command: bin/install-wp-tests.sh testphp root 'root' localhost latest it fails with:

    grep: /tmp/wp-latest.json: No such file or directory
    grep: /tmp/wp-latest.json: No such file or directory
    Latest WordPress version could not be found

    I am running Local by Flywheel on Windows 10.

    Thanks in advance.

    • This topic was modified 4 years, 11 months ago by Carl Gross.
Viewing 13 replies - 1 through 13 (of 13 total)
  • You would copy the standard wp-tests-config-sample.php and change the database credentials to a different database (one that can be trashed, because it will be, in the tests).
    But the config file doesn’t have anything to do with the /tmp folder used.

    Thread Starter Carl Gross

    (@carlgross)

    Thanks very much for the reply.

    >> You would copy the standard wp-tests-config-sample.php and change the database credentials to a different database (one that can be trashed, because it will be, in the tests).

    OK. But what is the standard wp-tests-config-sample.php? Are you saying I should start with the file wp-config-sample.php that is included with each WordPress installation, and re-name it to wp-tests-config-sample.php?

    >> But the config file doesn’t have anything to do with the /tmp folder used.

    OK got it. That might be consistent with the specific errors I’m seeing:

    grep: /tmp/wp-latest.json: No such file or directory
    grep: /tmp/wp-latest.json: No such file or directory
    Latest WordPress version could not be found

    Do you know how I can resolve those errors?

    I think the wp-tests-config-sample.php is likely the same as wp-config-sample.php, but I haven’t looked at that. If you look at the readme on wordpress-develop it says the same thing, but I’m not seeing the file (although I’ve seen it before since I ran the tests).

    For the /tmp problem, you’ll have to figure out your environment, and how to tell it where the temp folder is. I’ve never used Local by Flywheel or Windows 10(for dev).

    Thread Starter Carl Gross

    (@carlgross)

    >> For the /tmp problem, you’ll have to figure out your environment, and how to tell it where the temp folder is. I’ve never used Local by Flywheel or Windows 10(for dev).

    OK. But aren’t the /tmp problem and wp-tests-config.php issue related? Specifically, to workaround the /tmp problem, I need to manually install WordPress, and manually create wp-tests-config.php. This page seems to say so, doesn’t it? Specifically, “…sometimes the bash script fails to build WordPress because of how it uses tmp folders. If it fails, then you can manually install WordPress to a writeable directory, and then manually create wp-tests-config.php.” Wouldn’t you agree?

    That’s a good assumption, since it does say that. But I don’t know that there is any relation between the config file and the /tmp. It’s just that the script will use /tmp to try to delete stuff, and that is when installing, so if you do it manually then there’s no need to delete (or use /tmp).

    Thread Starter Carl Gross

    (@carlgross)

    OK thanks for the help.

    >> It’s just that the script will use /tmp to try to delete stuff, and that is when installing, so if you do it manually then there’s no need to delete (or use /tmp).

    OK. I know how to manually create a copy of WordPress. But I have a few questions:

    * In what directory should the copy of WordPress reside?

    * Will I need to I get this installation of WordPress to recognize a file wp-tests-config.php instead of wp-config.php? If so, how do I do that?

    * Once I create this copy of WordPress, should I then run the .sh script? Or should I completely omit that step?

    Thoughts?

    In the meantime, I will also reach out to Local by Flywheel to see if I can resolve the tmp issue. But from the sound of the WordPress documentation page, it could be something Local by Flywheel cannot resolve.

    I guess the answers would be in that script.

    Carl- did you make any progress with getting phpunit to work nicely with wordpress?
    I agree that the documentation is very poor. It seems that www.remarpro.com do not care as they can all just use their lovely imac pro laptops.
    I have read and searched to try and setup unit testing for my wordpress plugin – I installed cygwin and tried to run the install-wp-tests.sh script and ended up with the same uninformative messages
    grep: /tmp/wp-latest.json: No such file or directory
    grep: /tmp/wp-latest.json: No such file or directory
    Latest WordPress version could not be found

    Thread Starter Carl Gross

    (@carlgross)

    I was able to get it working in Windows. I setup a simple WordPress site in XAMPP, and used that site for my testing.

    grep: /tmp/wp-latest.json: No such file or directory
    grep: /tmp/wp-latest.json: No such file or directory

    I was getting those when I was using a WordPress site I had created using Local by Flywheel. When I started using the WordPress site I created with XAMPP, I no longer had that issue. I had several other issues using my Local by Flywheel for testing–could never get it to work.

    Let me know if you run into other specific issues, as I kept detailed notes. I know at one point I had to manually change a line in the .sh file.

    Thanks for the reply Carl. I sort of gave up following the wordpress method.
    I used cygwin to get a wordpress installation in my tmp folder, and used svn to install the contents of the wordpress-tests-lib folder.
    The file wp-tests-config.php was added to this folder but I had to manually install the folders data and includes here after studying what the install-wp-tests.sh was supposed to do. Maybe I got that right…
    In my temp folder I now have a wordpress folder and a wordpress-tests-lib folder . I also have an empty database for the wordpress installation.
    Unfortunately when I try to run the sample test in my plugin I get the response Class ‘WP_UnitTestCase’ not found.
    At this point I gave up.
    As I am trying to carry out unit tests on my plugin I do not need to test against wordpress itself (its not a theme). I am now studying Brain Monkey which allows mocking and testing of wordpress without reference to the official wordpress test setup .
    https://brain-wp.github.io/BrainMonkey/

    I have not succeeded yet but I have developed hate and resentment against the official wordpress testing documentation.

    btw I used to use Xampp as my local dev server but I am now using Laragon (https://laragon.org). it has great features like the ability to install multiple php versions and also to easily configure apache in order to use a custom site root (eg public dir rather than the project folder root)

    Thread Starter Carl Gross

    (@carlgross)

    >> Unfortunately when I try to run the sample test in my plugin I get the response Class ‘WP_UnitTestCase’ not found.

    I don’t have that particular error–or anything similar–in my notes. So sorry, I can’t be of too much help. I know that the cause of many of my frustrating errors were in the .sh file. I had to do some debugging of code in that file and even make some changes.

    >> I have not succeeded yet but I have developed hate and resentment against the official wordpress testing documentation.

    Yes I was pretty frustrated too for a bit. If WordPress wants to foster/encourage better plugin development, some accurate instructions for installing/running tests would be great. After I got mine working, I had grand plans to update the instructions and write down what worked for me. But alas I got busy with work, and my time shriveled up :-/

    One thing I was planning on doing as a very last resort was to login to the WordPress plugin development channel on Slack and see if anyone could give any tips. If you’re hard pressed, you might be able to try that.

    isMike()

    (@sleekdevigner)

    I also got frustrated trying to fix this error. For anyone who can’t run tests because your WordPress isn’t installing, I will advise you to try these steps. Hopefully it works for you.

    1. Using windows explorer (NOT COMMAND LINE), navigate to C:\Users\{your_username}\AppData\Local\Temp. Right in the Temp folder, check if there is a folder named wordpress-tests-lib. If this folder exists, then it means you are good to go (in fact you should see the wp-tests-config.php and two other folders within that directory). Now go to step 2.

    2. Navigate into the wordpress-test-lib folder, then create another folder called tmp.

    3. Download the latest WordPress zip file from www.remarpro.com. place the zip folder in the newly created tmp folder and extract the content of this zip file into this directory. (Note: if you are using the WINRAR windows app, please do not use the ?xtract to wordpress-version option. Instead use the Extract here option).

    4. Now, check to be sure your core WordPress folders(wp-admin, wp-include, e.t.c) and core wordpress files are now in C:\Users\{your_username}\AppData\Local\Temp\wordpress-tests-lib\tmp\wordpress.

    5. If 1 – 4 is in place, Now open your wp-tests-config.php file in an editor, and adjust the constant ABSPATH defined in line 7. change the line from define( 'ABSPATH', '/tmp/wordpress/' ); to define( 'ABSPATH', 'tmp/wordpress/' ); (i.e remove the first forward slash) and save the file.

    6. Everything should be okay now. Well…except you have not installed PHPUnit. You can use composer to install that and all should be good.

    I really hope this helps someone. Please feel free to ask any questions if any part of these steps is not clear to you. Thanks.

    isMike()

    (@sleekdevigner)

    Please let me know if anyone uses this and it works or if it throws any further error. Thanks!

    • This reply was modified 4 years, 8 months ago by isMike().
    • This reply was modified 4 years, 8 months ago by isMike().
    • This reply was modified 4 years, 8 months ago by isMike().
Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Testing with PHPUnit–what should be in the file ‘wp-tests-config.php?’’ is closed to new replies.