Skip to main content
Share Your Experience: Take the 2024 Developer Survey
9 votes
Accepted

How can I use Xdebug with CiviCRM unit tests?

Xdebug configuration is a somewhat temperamental issue -- the details depend on the IDE, the PHP build, host OS, target application, test suite, etc. Providing a good answer to this is tricky -- e.g. ...
Tim Otten's user avatar
  • 5,684
4 votes

Does class autoloading not work in standalone phpunit testing?

This is an issue with intermediate base-classes for tests (like VolunteerTestAbstract). The most reliable solution I've found is to put a require_once to load the intermediate base-class. For example, ...
Tim Otten's user avatar
  • 5,684
4 votes
Accepted

How do I run CiviCRM PHPUnit tests from within Netbeans?

[This all assumes you have civicrm-buildkit already working and that you can run CiviCRM phpunit tests successfully from the command line.] 1. Tell Netbeans which phpunit executable you're using. Go ...
Jon G - Megaphone Tech's user avatar
3 votes
Accepted

private or protected class properties

I think submitting a PR to make this variable protected would be perfectly reasonable. Alternatively, there is a way to access private properties in PHP for the sake of unit testing via Reflection. ...
Coleman's user avatar
  • 18.7k
2 votes
Accepted

Does class autoloading not work in standalone phpunit testing?

Civi's autoloader does not load classes outside the CRM directory. In order for that to work, you'll have a few options: Implement your own autoloader capable of loading classes inside the test/...
Davi Alexandre's user avatar
2 votes
Accepted

How do I write unit tests that verify a hook is being fired?

So I figured this out. The specific hook engine for unit testing, very conveniently, comes with an injectable mock property. After grabbing the hook engine with $this->hookClass = \CRM_Utils_Hook::...
ErichBSchulz's user avatar
  • 1,571
2 votes

class Civi not found

Ok, so it turns out I was kinda doing something wrong... What I needed was a simple \ prefix: \Civi::log()->info('Hello, log!');
ErichBSchulz's user avatar
  • 1,571
1 vote

Working e2e UnitTests?

My problem was solved by using the command phpunit4 from inside the extension directory. Use --group e2e or --group headless as needed.
JohnFF's user avatar
  • 2,343
1 vote

How do I write unit tests for time based actions?

Totten, who is a complete legend, shared this pearl with me: there are some examples like: tests/phpunit/Civi/CCase/SequenceListenerTest.php: \CRM_Utils_Time::setTime('2013-11-30 01:00:00'); ...
ErichBSchulz's user avatar
  • 1,571

Only top scored, non community-wiki answers of a minimum length are eligible