ion/tests/FriendTest.php

75 lines
1.8 KiB
PHP
Raw Permalink Normal View History

2017-03-24 16:18:02 -04:00
<?php declare(strict_types=1);
/**
* Ion
*
* Building blocks for web development
*
2019-12-05 15:39:02 -05:00
* PHP version 7.2
2017-03-24 16:18:02 -04:00
*
* @package Ion
* @author Timothy J. Warren <tim@timshomepage.net>
2019-12-05 15:39:02 -05:00
* @copyright 2015 - 2019 Timothy J. Warren
2017-03-24 16:18:02 -04:00
* @license http://www.opensource.org/licenses/mit-license.html MIT License
2019-12-05 15:39:02 -05:00
* @version 3.0.0
* @link https://git.timshomepage.net/aviat/ion
2017-03-24 16:18:02 -04:00
*/
2016-08-29 11:34:25 -04:00
namespace Aviat\Ion\Tests;
use Aviat\Ion\Friend;
2016-10-19 13:24:08 -04:00
use Aviat\Ion\Tests\FriendTestClass;
2016-10-19 13:24:08 -04:00
class FriendTest extends Ion_TestCase {
2019-12-05 15:25:47 -05:00
public function setUp(): void {
parent::setUp();
2016-10-19 13:24:08 -04:00
$obj = new FriendTestClass();
$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);
2016-08-29 11:34:25 -04:00
$this->assertNull($this->friend->foo); // Return NULL for non-existent properties
$this->assertEquals(47, $this->friend->parentProtected);
$this->assertEquals(84, $this->friend->grandParentProtected);
$this->assertNull($this->friend->parentPrivate); // Can't get a parent's privates
}
public function testSet()
{
$this->friend->private = 123;
$this->assertEquals(123, $this->friend->private);
$this->friend->foo = 32;
$this->assertNull($this->friend->foo);
}
public function testBadInvokation()
{
2016-08-29 11:34:25 -04:00
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Friend must be an object');
$friend = new Friend('foo');
}
public function testBadMethod()
{
2016-08-29 11:34:25 -04:00
$this->expectException('BadMethodCallException');
$this->expectExceptionMessage("Method 'foo' does not exist");
$this->friend->foo();
}
}