2016-12-29 21:09:49 +01:00
|
|
|
<?php
|
2016-12-17 15:16:17 +01:00
|
|
|
|
|
|
|
namespace Amp\Test;
|
|
|
|
|
2018-06-18 20:00:01 +02:00
|
|
|
class CallableMaker
|
|
|
|
{
|
2016-12-17 15:16:17 +01:00
|
|
|
use \Amp\CallableMaker {
|
|
|
|
callableFromInstanceMethod as public;
|
|
|
|
callableFromStaticMethod as public;
|
|
|
|
}
|
2017-03-11 14:57:03 +01:00
|
|
|
|
2018-06-18 20:00:01 +02:00
|
|
|
public function instanceMethod()
|
|
|
|
{
|
2016-12-17 15:16:17 +01:00
|
|
|
return __METHOD__;
|
|
|
|
}
|
2017-03-11 14:57:03 +01:00
|
|
|
|
2018-06-18 20:00:01 +02:00
|
|
|
public static function staticMethod()
|
|
|
|
{
|
2016-12-17 15:16:17 +01:00
|
|
|
return __METHOD__;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-14 21:37:08 +02:00
|
|
|
class CallableMakerTest extends BaseTest
|
2018-06-18 20:00:01 +02:00
|
|
|
{
|
2016-12-17 15:16:17 +01:00
|
|
|
/** @var \Amp\Test\CallableMaker */
|
|
|
|
private $maker;
|
|
|
|
|
2018-06-18 20:00:01 +02:00
|
|
|
public function setUp()
|
|
|
|
{
|
2016-12-17 15:16:17 +01:00
|
|
|
$this->maker = new CallableMaker;
|
|
|
|
}
|
|
|
|
|
2018-06-18 20:00:01 +02:00
|
|
|
public function testCallableFromInstanceMethod()
|
|
|
|
{
|
2016-12-17 15:16:17 +01:00
|
|
|
$callable = $this->maker->callableFromInstanceMethod("instanceMethod");
|
|
|
|
$this->assertInternalType("callable", $callable);
|
|
|
|
$this->assertSame(\sprintf("%s::%s", CallableMaker::class, "instanceMethod"), $callable());
|
|
|
|
}
|
2017-03-11 14:57:03 +01:00
|
|
|
|
2018-06-18 20:00:01 +02:00
|
|
|
public function testCallableFromStaticMethod()
|
|
|
|
{
|
2016-12-17 15:16:17 +01:00
|
|
|
$callable = $this->maker->callableFromInstanceMethod("staticMethod");
|
|
|
|
$this->assertInternalType("callable", $callable);
|
|
|
|
$this->assertSame(\sprintf("%s::%s", CallableMaker::class, "staticMethod"), $callable());
|
|
|
|
}
|
|
|
|
}
|