João Paulo Cercal

Staff Security Engineer at LastPass

  • PHP

Installing PHPUnit on Windows

  • Share on Facebook
  • Share on Twitter
  • Share on LinkedIn

Read this article in

Hello person(s), today I’ll present a step-by-step guide to installing PHPUnit on Uncle Bil Gates’ famous operating system, Microsoft Windows 7 (Seven), before continuing with the tutorial I wanted to talk a little about unit tests and test-driven development (the famous TDD – Test Driven Development).

So, what is TDD?

TDD is a method for building software, not just testing it. Through the “Red”, “Green”, “Refactoring” process, you notice that the code becomes clean, organized and best of all, working!

1
phpunit --version

Now open a text editor and type the following source code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
<?php

class HelloWorld
{
    public function msg( $message )
    {
        return $message;
    }
}

class HelloWorldTest extends PHPUnit_Framework_TestCase
{
    public function testHelloWorld()
    {
        $obj = new HelloWorld();

        $this->assertEquals( $obj->msg('Olá') , 'Olá' );
    }
}

Save the file as: HelloWorldTest.php

I saved the file in the directory: C:\teste

24 - Installing PHPUnit on Windows

Now everything is working! Be a new developer from today onward and use unit tests, if you have questions, leave us a comment.