Skip to content

Instantly share code, notes, and snippets.

@totten
Last active February 2, 2016 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save totten/f95ae11b87ae7a602864 to your computer and use it in GitHub Desktop.
Save totten/f95ae11b87ae7a602864 to your computer and use it in GitHub Desktop.
Pseudocode for a PHPUnit test in an extension. Noe that CiviTester and CRM_Core_Transaction are not tied to PHPUnit in any way.
<?php
class EndToEndExampleTeset extends PHPUnit_Framework_TestCase {
public function setUp() {
// Ensure that we are running an end-to-end test on a real site
// where the extension has been enabled. If the expectations
// aren't met, generate an error.
CiviTester::e2e()->extension(‘org.civicrm.foo’)->apply();
}
public function testFoo() {
// Send requests to the website.
// Use $_CV['ADMIN_USER'], $_CV['ADMIN_PASS'], $_CV['DEMO_USER'], etc
}
}
<?php
class HeadlessExampleTest extends PHPUnit_Framework_TestCase {
public function setUp() {
// Ensure the headless DB has the Civi schema along with the extension.
// If necessary, wipe/reset headless DB.
CiviTester::headless()->extension(‘org.civicrm.foo’)->apply();
// Wrap the test in a transaction so that we don't have to do any data cleanup.
$this->tx = new CRM_Core_Transaction();
}
public function tearDown() {
$this->tx->rollback();
unset($this->tx);
}
public function testFoo() {
// do stuff with the extension
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment