Skip to content

Commit

Permalink
Merge pull request #81 from ray-di/revert
Browse files Browse the repository at this point in the history
 Revert "update ReflectionMethod from native class to package class"
  • Loading branch information
koriym authored Mar 1, 2018
2 parents 462c1c2 + a794200 commit f908124
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 48 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/MethodInvocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface MethodInvocation extends Invocation
*
* <p>This method is a friendly implementation of the {@link * Joinpoint#getStaticPart()} method (same result).
*
* @return ReflectionMethod method being called
* @return \ReflectionMethod|ReflectionMethod method being called
*/
public function getMethod() : ReflectionMethod;
public function getMethod() : \ReflectionMethod;
}
12 changes: 9 additions & 3 deletions src/ReflectiveMethodInvocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class ReflectiveMethodInvocation implements MethodInvocation
private $arguments;

/**
* @var ReflectionMethod
* @var \ReflectionMethod
*/
private $method;

Expand All @@ -30,9 +30,15 @@ final class ReflectiveMethodInvocation implements MethodInvocation
*/
private $interceptors;

/**
* @param object $object
* @param \ReflectionMethod $method
* @param Arguments $arguments
* @param MethodInterceptor[] $interceptors
*/
public function __construct(
$object,
ReflectionMethod $method,
\ReflectionMethod $method,
Arguments $arguments,
array $interceptors = []
) {
Expand All @@ -45,7 +51,7 @@ public function __construct(
/**
* {@inheritdoc}
*/
public function getMethod() : ReflectionMethod
public function getMethod() : \ReflectionMethod
{
if ($this->object instanceof WeavedInterface) {
$class = (new \ReflectionObject($this->object))->getParentClass();
Expand Down
2 changes: 1 addition & 1 deletion template/AopTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function returnSame($a)
$this->isIntercepting = false;
$invocationResult = (new \Ray\Aop\ReflectiveMethodInvocation(
$this,
new \Ray\Aop\ReflectionMethod($this, __FUNCTION__),
new \ReflectionMethod($this, __FUNCTION__),
new \Ray\Aop\Arguments(func_get_args()),
$this->bindings[__FUNCTION__]
))->proceed();
Expand Down
48 changes: 14 additions & 34 deletions tests/CompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class CompilerTest extends TestCase
{
/**
* @var Bind
* @var BindInterface
*/
private $bind;

Expand All @@ -19,13 +19,10 @@ class CompilerTest extends TestCase
protected function setUp()
{
parent::setUp();
$this->compiler = new Compiler(
$_ENV['TMP_DIR']
);
$this->bind = new Bind;
$this->compiler = new Compiler($_ENV['TMP_DIR']);
$matcher = new Matcher;
$pointcut = new Pointcut($matcher->any(), $matcher->startsWith('return'), [new FakeDoubleInterceptor]);
$this->bind->bind(FakeWeaved::class, [$pointcut]);
$this->bind = (new Bind)->bind(FakeWeaved::class, [$pointcut]);
}

public function testNewInstance()
Expand Down Expand Up @@ -105,9 +102,9 @@ public function testMethodReturnValue(FakeMock $weaved)

public function testGetPrivateVal()
{
$weaved = $this->getWeaved();
$val = $weaved->getPrivateVal();
/* @var FakeMock $weaved */
/** @var \Ray\Aop\FakeMock $mock */
$mock = $this->compiler->newInstance(FakeMock::class, [], $this->bind);
$val = $mock->getPrivateVal();
$this->assertSame($val, 1);
}

Expand All @@ -116,9 +113,10 @@ public function testCallAbortProceedInterceptorTwice()
$matcher = new Matcher;
$pointcut = new Pointcut($matcher->any(), $matcher->startsWith('return'), [new FakeAbortProceedInterceptor]);
$this->bind->bind(FakeWeaved::class, [$pointcut]);
$weaved = $this->getWeaved();
$this->assertSame(40, $weaved->returnSame(1));
$this->assertSame(40, $weaved->returnSame(1));
/** @var \Ray\Aop\FakeMock $mock */
$mock = $this->compiler->newInstance(FakeMock::class, [], $this->bind);
$this->assertSame(40, $mock->returnSame(1));
$this->assertSame(40, $mock->returnSame(1));
}

public function testClassDocComment()
Expand Down Expand Up @@ -222,8 +220,10 @@ public function testHasBound()

public function testMethodAnnotationReader()
{
$mock = $this->getAnnotated();
/* @var $mock FakeAnnotateClass */
$bind = (new Bind)->bindInterceptors('getDouble', [new FakeMethodAnnotationReaderInterceptor]);
$compiler = new Compiler($_ENV['TMP_DIR']);
/** @var \Ray\Aop\FakeAnnotateClass $mock */
$mock = $compiler->newInstance(FakeAnnotateClass::class, [], $bind);
$mock->getDouble(1);
$this->assertInstanceOf(FakeMarker::class, FakeMethodAnnotationReaderInterceptor::$methodAnnotation);
$this->assertCount(3, FakeMethodAnnotationReaderInterceptor::$methodAnnotations);
Expand Down Expand Up @@ -254,24 +254,4 @@ public function testMethodAnnotationReaderReturnNull()
$this->assertNull(FakeMethodAnnotationReaderInterceptor::$methodAnnotation);
$this->assertCount(0, FakeMethodAnnotationReaderInterceptor::$methodAnnotations);
}

private function getWeaved() : FakeMock
{
$mock = $this->compiler->newInstance(FakeMock::class, [], $this->bind);
if ($mock instanceof FakeMock) {
return $mock;
}
throw new \LogicException;
}

private function getAnnotated() : FakeAnnotateClass
{
$bind = (new Bind)->bindInterceptors('getDouble', [new FakeMethodAnnotationReaderInterceptor]);
$compiler = new Compiler($_ENV['TMP_DIR']);
$mock = $compiler->newInstance(FakeAnnotateClass::class, [], $bind);
if ($mock instanceof FakeAnnotateClass) {
return $mock;
}
throw new \LogicException;
}
}
10 changes: 6 additions & 4 deletions tests/Fake/FakeMethodAnnotationReaderInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ class FakeMethodAnnotationReaderInterceptor implements MethodInterceptor

public function invoke(MethodInvocation $invocation)
{
self::$methodAnnotations = $invocation->getMethod()->getAnnotations();
self::$methodAnnotation = $invocation->getMethod()->getAnnotation(FakeMarker::class);
self::$classAnnotations = $invocation->getMethod()->getDeclaringClass()->getAnnotations();
self::$classAnnotation = $invocation->getMethod()->getDeclaringClass()->getAnnotation(FakeClassAnnotation::class);
/** @var \Ray\Aop\ReflectionMethod $method */
$method = $invocation->getMethod();
self::$methodAnnotations = $method->getAnnotations();
self::$methodAnnotation = $method->getAnnotation(FakeMarker::class);
self::$classAnnotations = $method->getDeclaringClass()->getAnnotations();
self::$classAnnotation = $method->getDeclaringClass()->getAnnotation(FakeClassAnnotation::class);

return $invocation->proceed();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/FakeWeaved.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function returnSame($a)
$interceptors = $this->bind[__FUNCTION__];
$invocation = new ReflectiveMethodInvocation(
$this,
new ReflectionMethod($this, __FUNCTION__),
new \ReflectionMethod($this, __FUNCTION__),
new Arguments(func_get_args()),
$interceptors
);
Expand Down
6 changes: 3 additions & 3 deletions tests/ReflectiveMethodInvocationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected function setUp()
{
parent::setUp();
$this->fake = new FakeClass;
$this->invocation = new ReflectiveMethodInvocation($this->fake, new ReflectionMethod($this->fake, 'add'), new Arguments([1]));
$this->invocation = new ReflectiveMethodInvocation($this->fake, new \ReflectionMethod($this->fake, 'add'), new Arguments([1]));
}

public function testGetMethod()
Expand Down Expand Up @@ -63,7 +63,7 @@ public function testGetThis()
public function testGetParentMethod()
{
$fake = new FakeWeavedClass;
$invocation = new ReflectiveMethodInvocation($fake, new ReflectionMethod($fake, 'add'), new Arguments([1]));
$invocation = new ReflectiveMethodInvocation($fake, new \ReflectionMethod($fake, 'add'), new Arguments([1]));
$method = $invocation->getMethod();
$this->assertSame(FakeClass::class, $method->class);
$this->assertSame('add', $method->name);
Expand All @@ -72,7 +72,7 @@ public function testGetParentMethod()
public function testProceedMultipleInterceptors()
{
$fake = new FakeWeavedClass;
$invocation = new ReflectiveMethodInvocation($fake, new ReflectionMethod($fake, 'add'), new Arguments([1]), [new FakeInterceptor, new FakeInterceptor]);
$invocation = new ReflectiveMethodInvocation($fake, new \ReflectionMethod($fake, 'add'), new Arguments([1]), [new FakeInterceptor, new FakeInterceptor]);
$invocation->proceed();
$this->assertSame(1, $fake->a);
}
Expand Down

0 comments on commit f908124

Please sign in to comment.