Skip to content

Instantly share code, notes, and snippets.

@dbazile
Last active September 12, 2015 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbazile/cee4da0d856c77b363eb to your computer and use it in GitHub Desktop.
Save dbazile/cee4da0d856c77b363eb to your computer and use it in GitHub Desktop.
Example phpunit test

Here I wrote a quick example test and I removed that junk from the run script. Please make sure your phpunit.bat looks like the one on this page.

Then, you should be able to run it with the command:

\php\phpunit\phpunit.bat name_of_test_file.php

For more information, here's a link to much better documentation than I could provide: https://phpunit.de/manual/current/en/writing-tests-for-phpunit.html

Good luck and sorry about the bad info!

<?php
class Apple {
public function getColor() {
return 'green';
}
}
class AppleTest extends PHPUnit_Framework_TestCase {
public function testIsGreen() {
$apple = new Apple();
$this->assertEquals($apple->getColor(), 'green', 'The best apples are green');
}
}
@echo off
set PHPBIN=C:\PHP\php.exe
"%PHPBIN%" -d safe_mode=Off "C:\PHP\PHPUnit\phpunit.phar" %*
@MinxianLi
Copy link

In "apple_test.php", does this file needs to be separated into two files?

I use command line: C:\PHP\phpunit\phpunit.bat apple_test.php

It give me: Parse error, unexpected '->' (T_OBJECT_OPERATOR) in C:\PHP\phpunit\apple_test.php on line 11?

Any suggestion

@dbazile
Copy link
Author

dbazile commented Sep 11, 2015

I've been doing too much JavaScript development lately. I forgot the $ before this.

@dbazile
Copy link
Author

dbazile commented Sep 11, 2015

Updated. Try it now.

@MinxianLi
Copy link

Hi Sir,

I just saw your reply in here.
Thanks so much.

It can run the test.

Thank you again for your answer and reply.

I think I will always follow your blog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment