How to exchange documents between tests in PHPUnit
I am doing functional testing on WordPress, so I am reading HTML and using Mastermind / HTML5 to transform the test. However, tests are now slowing down because the HTML document takes about 1s to load per test. I would like to share the tool between tests, so I don't have to parse for each test. But I have one limitation, the method that gets the html from is in the parent class, which is a non-statistical method
https://core.trac.wordpress.org/browser/trunk/tests/phpunit/includes/testcase.php?rev=32953#L328
What choice do I need to share the device between tests.
Here is my sample code
class Testcase extends WP_UnitTestCase {
public function setUp() {
parent::setUp();
}
public function get_dom( $path ) {
$html = $this->go_to( $path ); // I cannot change this method
// do some html parsing and return DOM
}
}
Here's my sample test
class Testcase1 extends Testcase {
public setUp(){
$this->dom = $this->get_dom('/')
}
public test_1() {
}
public test_2() {
}
}
I was thinking about creating a get_dom
static method , so it will just be called once, but as far as I know, a static method cannot call a non-static method. I'm right? and if so, is there anyway I could share the tool between tests?
source to share