PageRenderTime 44ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/Tests/Unit/Aop/Advice/AbstractAdviceTest.php

https://github.com/christianjul/FLOW3-Composer
PHP | 83 lines | 39 code | 22 blank | 22 comment | 2 complexity | 065e03968c4121bf1cfa160d207d458f MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0
  1. <?php
  2. namespace TYPO3\FLOW3\Tests\Unit\Aop\Advice;
  3. /* *
  4. * This script belongs to the FLOW3 framework. *
  5. * *
  6. * It is free software; you can redistribute it and/or modify it under *
  7. * the terms of the GNU Lesser General Public License, either version 3 *
  8. * of the License, or (at your option) any later version. *
  9. * *
  10. * The TYPO3 project - inspiring people to share! *
  11. * */
  12. /**
  13. * Testcase for the Abstract Method Interceptor Builder
  14. *
  15. */
  16. class AbstractAdviceTest extends \TYPO3\FLOW3\Tests\UnitTestCase {
  17. /**
  18. * @test
  19. */
  20. public function invokeInvokesTheAdviceIfTheRuntimeEvaluatorReturnsTrue() {
  21. $mockJoinPoint = $this->getMock('TYPO3\FLOW3\Aop\JoinPointInterface', array(), array(), '', FALSE);
  22. $mockAspect = $this->getMock('MockClass' . md5(uniqid(mt_rand(), TRUE)), array('someMethod'));
  23. $mockAspect->expects($this->once())->method('someMethod')->with($mockJoinPoint);
  24. $mockObjectManager = $this->getMock('TYPO3\FLOW3\Object\ObjectManagerInterface', array(), array(), '', FALSE);
  25. $mockObjectManager->expects($this->once())->method('get')->with('aspectObjectName')->will($this->returnValue($mockAspect));
  26. $mockDispatcher = $this->getMock('TYPO3\FLOW3\SignalSlot\Dispatcher');
  27. $advice = new \TYPO3\FLOW3\Aop\Advice\AbstractAdvice('aspectObjectName', 'someMethod', $mockObjectManager, function(\TYPO3\FLOW3\Aop\JoinPointInterface $joinPoint) { if ($joinPoint !== NULL) return TRUE; });
  28. $this->inject($advice, 'dispatcher', $mockDispatcher);
  29. $advice->invoke($mockJoinPoint);
  30. }
  31. /**
  32. * @test
  33. */
  34. public function invokeDoesNotInvokeTheAdviceIfTheRuntimeEvaluatorReturnsFalse() {
  35. $mockJoinPoint = $this->getMock('TYPO3\FLOW3\Aop\JoinPointInterface', array(), array(), '', FALSE);
  36. $mockAspect = $this->getMock('MockClass' . md5(uniqid(mt_rand(), TRUE)), array('someMethod'));
  37. $mockAspect->expects($this->never())->method('someMethod');
  38. $mockObjectManager = $this->getMock('TYPO3\FLOW3\Object\ObjectManagerInterface', array(), array(), '', FALSE);
  39. $mockObjectManager->expects($this->any())->method('get')->will($this->returnValue($mockAspect));
  40. $mockDispatcher = $this->getMock('TYPO3\FLOW3\SignalSlot\Dispatcher');
  41. $advice = new \TYPO3\FLOW3\Aop\Advice\AbstractAdvice('aspectObjectName', 'someMethod', $mockObjectManager, function(\TYPO3\FLOW3\Aop\JoinPointInterface $joinPoint) { if ($joinPoint !== NULL) return FALSE; });
  42. $this->inject($advice, 'dispatcher', $mockDispatcher);
  43. $advice->invoke($mockJoinPoint);
  44. }
  45. /**
  46. * @test
  47. */
  48. public function invokeEmitsSignalWithAdviceAndJoinPoint() {
  49. $mockJoinPoint = $this->getMock('TYPO3\FLOW3\Aop\JoinPointInterface', array(), array(), '', FALSE);
  50. $mockAspect = $this->getMock('MockClass' . md5(uniqid(mt_rand(), TRUE)), array('someMethod'));
  51. $mockAspect->expects($this->once())->method('someMethod')->with($mockJoinPoint);
  52. $mockObjectManager = $this->getMock('TYPO3\FLOW3\Object\ObjectManagerInterface', array(), array(), '', FALSE);
  53. $mockObjectManager->expects($this->once())->method('get')->with('aspectObjectName')->will($this->returnValue($mockAspect));
  54. $advice = new \TYPO3\FLOW3\Aop\Advice\AbstractAdvice('aspectObjectName', 'someMethod', $mockObjectManager);
  55. $mockDispatcher = $this->getMock('TYPO3\FLOW3\SignalSlot\Dispatcher');
  56. $mockDispatcher->expects($this->once())->method('dispatch')->with('TYPO3\FLOW3\Aop\Advice\AbstractAdvice', 'adviceInvoked', array($mockAspect, 'someMethod', $mockJoinPoint));
  57. $this->inject($advice, 'dispatcher', $mockDispatcher);
  58. $advice->invoke($mockJoinPoint);
  59. }
  60. }
  61. ?>