<?php
require("PublicWrap.php");
/**
* Test Case for PublicWrap
*
* Requires PHPUnit (developped using 3.6.12)
*/
class PublicWrapTest extends PHPUnit_Framework_TestCase
{
private $stuff;
public function setUp()
{
$this->stuff = new PublicWrap(new Something());
}
public function testAccessPublicProperty()
{
$this->stuff->a = 10;
$this->assertEquals(10, $this->stuff->a);
}
public function testAccessProtectedProperty()
{
$this->stuff->b = 19;
$this->assertEquals(19, $this->stuff->b);
}
public function testAccessPrivateProperty()
{
$this->stuff->c = 24;
$this->assertEquals(24, $this->stuff->c);
}
public function testAccessPublicStaticProperty()
{
$this->stuff->d = 31;
$this->assertEquals(31, $this->stuff->d);
}
public function testAccessProtectedStaticProperty()
{
$this->stuff->e = 42;
$this->assertEquals(42, $this->stuff->e);
}
public function testAccessPrivateStaticProperty()
{
$this->stuff->f = 5;
$this->assertEquals(5, $this->stuff->f);
}
public function testAccessPublicMethod()
{
$this->assertEquals("g...\n", $this->stuff->g());
}
public function testAccessProtectedMethod()
{
$this->assertEquals("h...\n", $this->stuff->h());
}
public function testAccessPrivateMethod()
{
$this->assertEquals("i...\n", $this->stuff->i());
}
public function testAccessPublicStaticMethod()
{
$this->assertEquals("j...\n", $this->stuff->j());
}
public function testAccessProtectedStaticMethod()
{
$this->assertEquals("k...\n", $this->stuff->k());
}
public function testAccessPrivateStaticMethod()
{
$this->assertEquals("l...\n", $this->stuff->l());
}
public function testBadConstructorArgument()
{
try
{
$this->stuff = new PublicWrap("Hello, world!");
}
catch (\Exception $e)
{
$expected = "PublicWrap::__construct: first argument expected to be an object.";
$this->assertEquals($expected, $e->getMessage());
return;
}
$this->fail("Expected exception, but never raised.");
}
public function testGetPropertyDoesNotExists()
{
try
{
$this->stuff->hello;
}
catch (\Exception $e)
{
$expected = "PublicWrap::__get: hello property does not exist in Something class.";
$this->assertEquals($expected, $e->getMessage());
return;
}
$this->fail("Expected exception, but never raised.");
}
public function testSetPropertyDoesNotExists()
{
try
{
$this->stuff->hello = 42;
}
catch (\Exception $e)
{
$expected = "PublicWrap::__set: hello property does not exist in Something class.";
$this->assertEquals($expected, $e->getMessage());
return;
}
$this->fail("Expected exception, but never raised.");
}
public function testMethodDoesNotExists()
{
try
{
$this->stuff->hello();
}
catch (\Exception $e)
{
$expected = "PublicWrap::__call: hello method does not exist in Something class.";
$this->assertEquals($expected, $e->getMessage());
return;
}
$this->fail("Expected exception, but never raised.");
}
}
class Something
{
public $a = "a...\n";
protected $b = "b...\n";
private $c = "c...\n";
static public $d = "d...\n";
static protected $e = "e...\n";
static private $f = "f...\n";
public function g()
{
return "g...\n";
}
protected function h()
{
return "h...\n";
}
private function i()
{
return "i...\n";
}
static public function j()
{
return "j...\n";
}
static protected function k()
{
return "k...\n";
}
static private function l()
{
return "l...\n";
}
}
|