3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Ampersand\DevTest\BasicOop; interface NumberInterface { /** * Adds n to this number * * @param int $n The amount to add to this number * @return int The new integer value of this number */ public function add($n); /** * Subtracts n from this number * * @param int $n The amount to subtract from this number * @return int The new integer value of this number */ public function subtract($n); /** * Multiplies this number by n * * @param int $n The amount to multiply this number by * @return int The new integer value of this number */ public function multiply($n); /** * Divides this number by n * * @param int $n The amount to divide this number by * @return int The new integer value of this number */ public function divide($n); /** * Returns the integer value of this number * * @return int The current integer value of this number */ public function toInt(); } class NumberTest { public function testConstruct() { $n = new Number; $this->assertEquals(0, $n->toInt()); $n = new Number(0); $this->assertEquals(0, $n->toInt()); $n = new Number(3); $this->assertEquals(3, $n->toInt()); } public function testAdd() { $n = new Number; $n->add(5); $this->assertEquals(5, $n->toInt()); $n->add(-7); $this->assertEquals(-2, $n->toInt()); } public function testSubtract() { $n = new Number; $n->subtract(8); $this->assertEquals(-8, $n->toInt()); $n->subtract(-10); $this->assertEquals(2, $n->toInt()); } public function testMultiply() { $n = new Number(1); $n->multiply(10); $this->assertEquals(10, $n->toInt()); $n->multiply(6); $this->assertEquals(60, $n->toInt()); } public function testDivide() { $n = new Number(100); $n->divide(5); $this->assertEquals(20, $n->toInt()); $n->divide(5); $this->assertEquals(4, $n->toInt()); $hasThrownEx = false; try { $n->divide(0); } catch (\InvalidArgumentException $e) { $hasThrownEx = true; } $this->assertEquals(true, $hasThrownEx); } private function assertEquals($expected, $actual) { if ($expect !== $actual) { echo "\n"; var_dump($actual); echo ' does not match expected '; var_dump($expected); echo "\n"; } } } class Number implements NumberInterface { private $value; public function __construct($value = 0) { $this->value = $value; } public function add($value) { $this->value += $value; return $this->value; } public function subtract($value) { $this->value -= $value; return $this->value; } public function multiply($value) { $this->value *= $value; return $this->value; } public function divide($value) { if (0 === $value) { throw new \InvalidArgumentException; } $this->value /= $value; return $this->value; } public function toInt() { return $this->value; } } $test = new NumberTest; $test->testConstruct(); $test->testAdd(); $test->testSubtract(); $test->testMultiply(); $test->testDivide();
Output for git.master, git.master_jit, rfc.property-hooks
Warning: Undefined variable $expect in /in/ccKr7 on line 115 int(0) does not match expected int(0) Warning: Undefined variable $expect in /in/ccKr7 on line 115 int(0) does not match expected int(0) Warning: Undefined variable $expect in /in/ccKr7 on line 115 int(3) does not match expected int(3) Warning: Undefined variable $expect in /in/ccKr7 on line 115 int(5) does not match expected int(5) Warning: Undefined variable $expect in /in/ccKr7 on line 115 int(-2) does not match expected int(-2) Warning: Undefined variable $expect in /in/ccKr7 on line 115 int(-8) does not match expected int(-8) Warning: Undefined variable $expect in /in/ccKr7 on line 115 int(2) does not match expected int(2) Warning: Undefined variable $expect in /in/ccKr7 on line 115 int(10) does not match expected int(10) Warning: Undefined variable $expect in /in/ccKr7 on line 115 int(60) does not match expected int(60) Warning: Undefined variable $expect in /in/ccKr7 on line 115 int(20) does not match expected int(20) Warning: Undefined variable $expect in /in/ccKr7 on line 115 int(4) does not match expected int(4) Warning: Undefined variable $expect in /in/ccKr7 on line 115 bool(true) does not match expected bool(true)

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
68.06 ms | 403 KiB | 8 Q