0
class TestCase
{
    public function multiply($a,$b)
    {
        return $a*$b;
    }
}

I need to use test cases in PHP. Some websites suggests that to use TDD in PHP, we need to install PHPUnit. For now, I need only knowledge of test cases and using them in PHP to test a program. Is that possible for above PHP code(without installing PHPUnit)? I have WAMPP to run php.

4
  • 3
    Just write code that calls the class method and say "Yay" or "Nay" based on the expected result. Of course you can write tests without PHPUnit. PHPUnit is just a lot of PHP code itself. But to write proper tests in a well structured way, PHPUnit already brings a lot to the table that you don't have to reinvent yourself. And it's a really good library, something to be recommended without hesitating. Commented Nov 7, 2012 at 9:49
  • What prevents you from just testing it? And apart from that, what prevents you from installing PHPUnit? It runs well on the WAMP platform. Commented Nov 7, 2012 at 10:01
  • I have tried to download PHPUnit from net.tutsplus.com/tutorials/php/…. But couldn't. please give me the link to download PHPUnit framework and help me to using it for implementing TDD(using test cases to test programs)!!! Commented Nov 7, 2012 at 10:17
  • 2
    Please don't be a Help Vampire!. Type PHPUnit into Google. Find the main website and follow the installation instructions. Commented Nov 7, 2012 at 10:28

2 Answers 2

3

Read this article written by authors of PHPUnit: http://www.phpunit.de/manual/current/en/automating-tests.html

One of the examples from there:

For a newly created array we expect the count() function to return 0. After we add an element, count() should return 1

<?php
    $fixture = array();
    assertTrue(count($fixture) == 0);

    $fixture[] = 'element';
    assertTrue(count($fixture) == 1);

    function assertTrue($condition)
    {
        if (!$condition) {
            throw new Exception('Assertion failed.');
        }
    }
?>

You can reinvent the wheel, but why do you need it?

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

Comments

0

You can try simple test, it's a lightweight TDD framework for PHP projects. In order to test it you just need to include one single file in your PHP script.

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.