Jump to content

bootstrapping PW kills PHPUnit outputs?

Recommended Posts

Hey guys,

I am recently migrated my whole setup to a newer environment, using Vagrant, webpack and the latest version of PHPUnit. Everything works fine except the tests are driving me crazy. It worked long time ago already but nowadays I have some trouble with the test output and I hope that someone has an idea. 

If I run a single test via my Eclipse IDE it works perfectly and the output as shown as expected. I see all tests in a nice overview including all passed and failed tests. But as soon as I include the index.php from the root directory to utilize the PW API the output is killed completely. 

Something must cause interferences between PHPUnit and including the PW API. 

I am using PW 3.0.62 and tried with PHPUnit 6.5.14, 7.5.8, 8.1.2 and PHP 7.1.28, 7.2.16. Regardless which configuration - it all ends when PW is included 😕


Any ideas where I might dig into are really appreciated. 


Share this post

Link to post
Share on other sites

Sorry for pushing this but I still hope that someone has an idea. Maybe you are using a different IDE? Or you are not testing as all?

Share this post

Link to post
Share on other sites

Have you seen this thread? https://processwire.com/talk/topic/12723-bootstrapping-processwire-in-phpunit/

I'm getting into test-driven development with the Nette Tester module, and am learning how to bootstrap PW.

If the PW instance you're bootstrapping has Tracy Debugger installed, "Tracy Logs" give meaningful realtime feedback (after page reload) on bootstrap (and other) errors. This helped me "trace" 🤑 a tricky bug that didn't appear in Tracy "Processwire Logs", or Windows, mysql, or Apache logs.

My error was caused by the fact that:

  • While I was logged as Superuser into the admin of the PW instance I was bootstrapping
  • AND the PHP script I bootstrapped from was in a subdirectory of that site

by default PW runs bootstrapped scripts as "guest" user, and couldn't access what I wanted - a custom per-user field from the Admin "Profile" section. PW forum searching revealed that Ryan Cramer chose this sane default for security. Ryan's code in this thread solved my problem:

$users = wire('users'); 
$superuser = $users->get("YOUR_PW_USERNAME"); 

Also be aware, as this page states:


You can access all of the same API variables that you can from a template, except that there is no default $page variable accessible from the API since ProcessWire is not handling the web request. Of course, you are welcome to retrieve any page you want from the $pages API variable. Likewise you can modify, save, and delete pages as usual.


  • Like 1

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...