Permalink
Browse files

Added presentation and sample day two

  • Loading branch information...
Ludo van den Boom
Ludo van den Boom committed Dec 15, 2010
1 parent 732d8a1 commit 9d897e3f5ba4abddf9d564f7caa3522b575aa337
Submodule standalone-cucumber added at d5d8f4
@@ -0,0 +1,14 @@
+<?php
+
+
+
+class Calculator {
+ public function divide($arg1, $arg2) {
+ // if($arg2 == 0) {
+ // throw new Exception("DivideByZeroException");
+ // }
+ return $arg1 / $arg2;
+ }
+}
+
+?>
@@ -0,0 +1,33 @@
+<?php
+
+require_once("calculator.php");
+
+class CalculatorTest extends PHPUnit_Framework_TestCase {
+ public function setUp()
+ {
+ $this->calculator = new Calculator();
+ }
+
+ public function testDivideByZero()
+ {
+ $this->setExpectedException('Exception');
+ $this->calculator->divide(2, 0);
+ }
+
+ public function testDivideByNegativeNumber()
+ {
+ $value = $this->calculator->divide(2, -10);
+
+ $this->assertEquals($value, -0.2, "Dit ging niet goed");
+ }
+
+ // testDivideByPositiveNumber
+ // testDivideByString
+
+ public function testDivideByString()
+ {
+ $this->setExpectedException('Exception');
+ $value = $this->calculator->divide(2, "foo");
+ }
+}
+?>
@@ -0,0 +1,42 @@
+<?php
+
+class Subject {
+ protected $observers = array();
+
+ public function attach(Observer $observer) {
+ $this->observers[] = $observer;
+ }
+
+ public function doSomething() {
+ $this->notify('something');
+ }
+
+ protected function notify($argument) {
+ foreach ($this->observers as $observer) {
+ $observer->update($argument);
+ }
+ }
+}
+
+class Observer {
+ public function update($argument) {
+ // Do something.
+ }
+}
+
+class SubjectTest extends PHPUnit_Framework_TestCase {
+ public function testObserversAreUpdated() {
+ $observer = $this->getMock('Observer', array('update'));
+
+ $observer->expects($this->once())
+ ->method('update')
+ ->with($this->equalTo('something'));
+
+ $subject = new Subject;
+ $subject->attach($observer);
+
+ $subject->doSomething();
+ }
+}
+
+?>
@@ -0,0 +1,26 @@
+<?php
+
+class SomeClass {
+ public function doSomething() {
+ return 'bar';
+ }
+}
+
+class StubTest extends PHPUnit_Framework_TestCase {
+ public function testStub() {
+ // Create a stub for the SomeClass class.
+ $stub = $this->getMock('SomeClass');
+ // $stub = new SomeClass;
+
+ // Configure the stub.
+ // $stub->expects($this->any())
+ // ->method('doSomething')
+ // ->will($this->returnValue('foo'));
+
+ // Calling $stub->doSomething() will now return
+ // 'foo'.
+ $this->assertEquals('foo', $stub->doSomething());
+ }
+}
+
+?>
View
Binary file not shown.
@@ -0,0 +1,25 @@
+<?php
+
+require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
+
+class Example extends PHPUnit_Extensions_SeleniumTestCase
+{
+ protected function setUp()
+ {
+ $this->setBrowser("*chrome");
+ $this->setBrowserUrl("http://www.eduhub.nl/");
+ }
+
+ public function testMyTestCase()
+ {
+ $this->open("/");
+ $this->click("link=Over Eduhub");
+ $this->waitForPageToLoad("30000");
+ try {
+ $this->assertTrue($this->isTextPresent("Rokin 75"));
+ } catch (PHPUnit_Framework_AssertionFailedError $e) {
+ array_push($this->verificationErrors, $e->toString());
+ }
+ }
+}
+?>

0 comments on commit 9d897e3

Please sign in to comment.