So I want to test a function that uses the Advanced Custom Fields plugin.

Unit tests using PHPunit work just fine as long as the test function is called directly, or from the test class.

However the ACF get_field call fails to work (returns false) when the tests are run by calling the directory they’re stored in. It returns the correct value when called the other two ways.

Other tests are working fine; it’s definitely the interaction of ACF and PHPunit called on a directory that’s being weird.

Sure, I could mock ACF. I probably will. But I’d really like to know why it fails when PHPunit is called on the directory, and not in any other way.

Read more here: WordPress PHPunit testing Advanced Custom Fields works when running directly, but not always


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: