9

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. I could describe my configuration (Mac OS X, PHPStorm 2016.2, MAMP 3.4, PHP 5.4, buildkit/dmaster), but the odds are that most people reading it will need ...


4

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, this is what I used in uk.co.vedaconsulting.mosaico: require_once __DIR__ . '/TestCase.php'; class CRM_Mosaico_MosaicoTemplateTest extends ...


4

[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 to Tools » Options, then PHP tab, PHPUnit subtab. Set the path of your PHPUnit script. See screenshot: 2. Create a shell script with your environment ...


3

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. It's slightly cludgy but it does work.


2

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/phpunit dir Use require to include the class Put the VolunteerTestAbstract class inside your CRM dir I usually use the second option for that and include/require ...


2

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::singleton() you just need to inject a mock object that has a magic __call() method with somthing like: $this->hookClass->setMock($this); The hook ...


2

Ok, so it turns out I was kinda doing something wrong... What I needed was a simple \ prefix: \Civi::log()->info('Hello, log!');


1

My problem was solved by using the command phpunit4 from inside the extension directory. Use --group e2e or --group headless as needed.


1

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'); however, these are the exception rather than the rule. there are lots of places where someone called time() or strtotime() without reading CRM_Utils_Time to ...


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