57 lines
1.1 KiB
PHP
57 lines
1.1 KiB
PHP
<?php
|
|
|
|
use function Kadet\Functional\apply;
|
|
use function Kadet\Functional\ref;
|
|
|
|
/**
|
|
* Copyright 2018 Kacper Donat
|
|
*
|
|
* @author Kacper "Kadet" Donat <kacper@kadet.net>
|
|
*
|
|
* Full license available in separate LICENSE file
|
|
*/
|
|
|
|
class TestObject
|
|
{
|
|
public function identity($x)
|
|
{
|
|
return $x;
|
|
}
|
|
|
|
private function priv()
|
|
{
|
|
return 'foo';
|
|
}
|
|
|
|
public function test()
|
|
{
|
|
return ref([$this, 'priv']);
|
|
}
|
|
}
|
|
|
|
class RandomTest extends \PHPUnit\Framework\TestCase
|
|
{
|
|
public function testApplicationOfArrayNotation()
|
|
{
|
|
$object = new TestObject();
|
|
$this->assertSame(10, apply([$object, 'identity'], 10));
|
|
}
|
|
|
|
public function testReferencingPrivateFunctionsFromInsideOfObject()
|
|
{
|
|
$object = new TestObject();
|
|
$reference = $object->test();
|
|
|
|
$this->assertSame('foo', $reference());
|
|
}
|
|
|
|
/**
|
|
* @expectedException \Kadet\Functional\Exception\NoAccessException
|
|
*/
|
|
public function testReferencingPrivateFunctionsFromOutsideOfObject()
|
|
{
|
|
$object = new TestObject();
|
|
|
|
ref([$object, 'priv']);
|
|
}
|
|
} |