Created
February 25, 2012 17:17
-
-
Save freddiefujiwara/1909586 to your computer and use it in GitHub Desktop.
JavaScript Test using PHPUnit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ cat Cat.js | |
| var Cat; | |
| Cat = (function() { | |
| function Cat(name) { | |
| this.name = name; | |
| } | |
| Cat.prototype.mew = function() { | |
| return "I am " + this.name + " mew mew.."; | |
| }; | |
| Cat.prototype.changeName = function(name) { | |
| this.name = name; | |
| }; | |
| return Cat; | |
| })(); | |
| $ cat CatTest.php | |
| <?php | |
| /** | |
| * Test class for Cat. | |
| */ | |
| class CatTest extends PHPUnit_Framework_TestCase | |
| { | |
| /** | |
| * @var v8(JS Engine) | |
| */ | |
| protected $v8; | |
| protected function setUp(){ | |
| $this -> v8 = new V8Js(); | |
| $this -> v8 -> executeString(file_get_contents('Cat.js')); | |
| } | |
| public function testMew(){ | |
| $this -> v8 -> executeString("var cat = new Cat('tama');"); | |
| $this -> assertEquals("I am tama mew mew..",$this -> v8 -> executeString("cat.mew()")); | |
| } | |
| public function testChangeName(){ | |
| $this -> v8 -> executeString("var cat = new Cat('tama');"); | |
| $this -> v8 -> executeString("cat.changeName('pochi');"); | |
| $this -> assertEquals("I am pochi mew mew..",$this -> v8 -> executeString("cat.mew()")); | |
| } | |
| } | |
| $ phpunit CatTest.php | |
| PHPUnit 3.6.10 by Sebastian Bergmann. | |
| .. | |
| Time: 0 seconds, Memory: 3.25Mb | |
| OK (2 tests, 2 assertions) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment