public function matchesTakesTheVisibilityModifierIntoAccountIfOneWasSpecified()
{
$className = 'TestClass' . md5(uniqid(mt_rand(), true));
eval('
class ' . $className . ' {
public function somePublicMethod() {}
protected function someProtectedMethod() {}
private function somePrivateMethod() {}
}');
$mockReflectionService = $this->createMock(ReflectionService::class);
$mockReflectionService->expects($this->atLeastOnce())->method('isMethodPublic')->will($this->onConsecutiveCalls(true, false, false, true));
$mockReflectionService->expects($this->atLeastOnce())->method('isMethodProtected')->will($this->onConsecutiveCalls(false, true, false, false));
$mockReflectionService->expects($this->atLeastOnce())->method('isMethodFinal')->will($this->returnValue(false));
$mockReflectionService->expects($this->atLeastOnce())->method('getMethodParameters')->will($this->returnValue([]));
$methodNameFilter = new Aop\Pointcut\PointcutMethodNameFilter('some.*', 'public');
$methodNameFilter->injectReflectionService($mockReflectionService);
$this->assertTrue($methodNameFilter->matches(__CLASS__, 'somePublicMethod', $className, 1));
$this->assertFalse($methodNameFilter->matches(__CLASS__, 'someProtectedMethod', $className, 1));
$this->assertFalse($methodNameFilter->matches(__CLASS__, 'somePrivateMethod', $className, 1));
$this->assertFalse($methodNameFilter->matches(__CLASS__, 'somePublicMethod', null, 1));
$methodNameFilter = new Aop\Pointcut\PointcutMethodNameFilter('some.*', 'protected');
$methodNameFilter->injectReflectionService($mockReflectionService);
$this->assertFalse($methodNameFilter->matches(__CLASS__, 'somePublicMethod', $className, 1));
$this->assertTrue($methodNameFilter->matches(__CLASS__, 'someProtectedMethod', $className, 1));
$this->assertFalse($methodNameFilter->matches(__CLASS__, 'somePrivateMethod', $className, 1));
$this->assertFalse($methodNameFilter->matches(__CLASS__, 'someProtectedMethod', null, 1));
}