2015-09-25 13:41:12 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Aviat\Ion\Friend;
|
|
|
|
|
|
|
|
class GrandParentTestClass {
|
|
|
|
protected $grandParentProtected = 84;
|
|
|
|
}
|
|
|
|
|
|
|
|
class ParentTestClass extends GrandParentTestClass {
|
|
|
|
protected $parentProtected = 47;
|
2015-10-01 16:02:51 -04:00
|
|
|
private $parentPrivate = 654;
|
2015-09-25 13:41:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
class TestClass extends ParentTestClass {
|
|
|
|
protected $protected = 356;
|
|
|
|
private $private = 486;
|
|
|
|
|
|
|
|
protected function getProtected()
|
|
|
|
{
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getPrivate()
|
|
|
|
{
|
|
|
|
return 23;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class FriendTest extends AnimeClient_TestCase {
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
$obj = new TestClass();
|
|
|
|
$this->friend = new Friend($obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPrivateMethod()
|
|
|
|
{
|
|
|
|
$actual = $this->friend->getPrivate();
|
|
|
|
$this->assertEquals(23, $actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testProtectedMethod()
|
|
|
|
{
|
|
|
|
$actual = $this->friend->getProtected();
|
|
|
|
$this->assertEquals(4, $actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGet()
|
|
|
|
{
|
|
|
|
$this->assertEquals(356, $this->friend->protected);
|
2015-10-01 16:02:51 -04:00
|
|
|
$this->assertNull($this->friend->foo); // Return NULL for non-existend properties
|
2015-09-25 13:41:12 -04:00
|
|
|
$this->assertEquals(47, $this->friend->parentProtected);
|
|
|
|
$this->assertEquals(84, $this->friend->grandParentProtected);
|
2015-10-01 16:02:51 -04:00
|
|
|
$this->assertNull($this->friend->parentPrivate); // Can't get a parent's privates
|
2015-09-25 13:41:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSet()
|
|
|
|
{
|
|
|
|
$this->friend->private = 123;
|
|
|
|
$this->assertEquals(123, $this->friend->private);
|
2015-10-01 16:02:51 -04:00
|
|
|
|
|
|
|
$this->friend->foo = 32;
|
|
|
|
$this->assertNull($this->friend->foo);
|
2015-09-25 13:41:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testBadInvokation()
|
|
|
|
{
|
|
|
|
$this->setExpectedException('InvalidArgumentException', 'Friend must be an object');
|
|
|
|
|
|
|
|
$friend = new Friend('foo');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testBadMethod()
|
|
|
|
{
|
|
|
|
$this->setExpectedException('BadMethodCallException', "Method 'foo' does not exist");
|
|
|
|
$this->friend->foo();
|
|
|
|
}
|
|
|
|
}
|