コード例 #1
0
 /**
  * @test
  * @return void
  */
 public function invokeDoesNotInvokeTheAdviceIfTheRuntimeEvaluatorReturnsFalse()
 {
     $mockAdviceChain = $this->getMock(\TYPO3\Flow\Aop\Advice\AdviceChain::class, array(), array(), '', FALSE);
     $mockAdviceChain->expects($this->once())->method('proceed')->will($this->returnValue('result'));
     $mockJoinPoint = $this->getMock(\TYPO3\Flow\Aop\JoinPointInterface::class, array(), array(), '', FALSE);
     $mockJoinPoint->expects($this->any())->method('getAdviceChain')->will($this->returnValue($mockAdviceChain));
     $mockAspect = $this->getMock('MockClass' . md5(uniqid(mt_rand(), TRUE)), array('someMethod'));
     $mockAspect->expects($this->never())->method('someMethod');
     $mockObjectManager = $this->getMock(\TYPO3\Flow\Object\ObjectManagerInterface::class, array(), array(), '', FALSE);
     $mockObjectManager->expects($this->any())->method('get')->will($this->returnValue($mockAspect));
     $advice = new \TYPO3\Flow\Aop\Advice\AroundAdvice('aspectObjectName', 'someMethod', $mockObjectManager, function (\TYPO3\Flow\Aop\JoinPointInterface $joinPoint) {
         if ($joinPoint !== NULL) {
             return FALSE;
         }
     });
     $result = $advice->invoke($mockJoinPoint);
     $this->assertEquals($result, 'result', 'The around advice did not return the result value as expected.');
 }
コード例 #2
0
 /**
  * @test
  * @return void
  */
 public function invokeDoesNotInvokeTheAdviceIfTheRuntimeEvaluatorReturnsFalse()
 {
     $mockAdviceChain = $this->getMockBuilder(\TYPO3\Flow\Aop\Advice\AdviceChain::class)->disableOriginalConstructor()->getMock();
     $mockAdviceChain->expects($this->once())->method('proceed')->will($this->returnValue('result'));
     $mockJoinPoint = $this->createMock(\TYPO3\Flow\Aop\JoinPointInterface::class);
     $mockJoinPoint->expects($this->any())->method('getAdviceChain')->will($this->returnValue($mockAdviceChain));
     $mockAspect = $this->getMockBuilder('MockClass' . md5(uniqid(mt_rand(), true)))->setMethods(array('someMethod'))->getMock();
     $mockAspect->expects($this->never())->method('someMethod');
     $mockObjectManager = $this->createMock(\TYPO3\Flow\Object\ObjectManagerInterface::class);
     $mockObjectManager->expects($this->any())->method('get')->will($this->returnValue($mockAspect));
     $advice = new \TYPO3\Flow\Aop\Advice\AroundAdvice('aspectObjectName', 'someMethod', $mockObjectManager, function (\TYPO3\Flow\Aop\JoinPointInterface $joinPoint) {
         if ($joinPoint !== null) {
             return false;
         }
     });
     $result = $advice->invoke($mockJoinPoint);
     $this->assertEquals($result, 'result', 'The around advice did not return the result value as expected.');
 }