6

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?

1 Answer 1

10

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.