Question

I am creating a custom testing application using PHPUnit and Goutte. I would like to load the Goutte library (plus any files required for the tests) within my own bootstrap file and then start the PHPUnit test runner once it is all bootstrapped.

I'm not sure how to do this without calling the phpunit script externally (Which would be a seperate process, and won't be able to see my bootstrapped libraries). Has anyone done anything like this before? What is the best way to do it?

Was it helpful?

Solution

If you reference the fixtures chapter in the PHPUnit documentation, it tells you about setup() and teardown().

PHPUnit supports sharing the setup code. Before a test method is run, a template method called setUp() is invoked. setUp() is where you create the objects against which you will test. Once the test method has finished running, whether it succeeded or failed, another template method called tearDown() is invoked. tearDown() is where you clean up the objects against which you tested.

This is basically a way of bootstrapping your application prior to running the tests in the test class.

class testMyScript
{
    private $myapp = null;

    public function setup()
    {
       $this->myapp = new My_Application;
       $this->myapp->bootstrap();
    }

    public function testIsMyAppInitialized()
    {
       $this->assertNotNull($this->myapp);      
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top