-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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