swapnil mandavkar swapnil mandavkar - 2 years ago 152
PHP Question

Is it possible to unit test, php files other than class file using PHPUnit?

I'm new to PHPUnit. I have php files that don't have any classes in them. What I came to understand from reading documentation, PHPUnit considers a class as a single unit.
So Does PHPUnit considers a class as a unit?
Is it possible to test php files that don't have any class in them?

Answer Source

Sure, you can absolutely test other PHP scripts.

class MyScriptTest extends PHPUnit_Framework_TestCase {
    public function testMyFunction() {
        include_once 'path/to/script.php';
        $result = someFunction();

        $this->assertEquals('expected result', $result);
    }
}

So write PHPUnit test classes, and inside a test run whatever code you wish to test and make assertions against it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download