AggregateInvokerTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\App\Test\Unit\Utility;
  7. use \Magento\Framework\App\Utility\AggregateInvoker;
  8. class AggregateInvokerTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \Magento\Framework\App\Utility\AggregateInvoker
  12. */
  13. protected $_invoker;
  14. /**
  15. * @var \PHPUnit\Framework\TestCase|\PHPUnit_Framework_MockObject_MockObject
  16. */
  17. protected $_testCase;
  18. protected function setUp()
  19. {
  20. $this->_testCase = $this->createPartialMock(
  21. \PHPUnit\Framework\Test::class,
  22. ['run', 'count', 'fail', 'markTestIncomplete', 'markTestSkipped']
  23. );
  24. $this->_invoker = new AggregateInvoker($this->_testCase, []);
  25. }
  26. /**
  27. * @dataProvider callbackDataProvider
  28. *
  29. * @param string $expectedMessage
  30. * @param string $expectedMethod
  31. * @param string $exceptionClass
  32. * @throws
  33. */
  34. public function testMainFlow($expectedMessage, $expectedMethod, $exceptionClass)
  35. {
  36. $this->_testCase->expects(
  37. $this->any()
  38. )->method(
  39. $expectedMethod
  40. )->with(
  41. $this->stringStartsWith($expectedMessage)
  42. );
  43. $this->_invoker->__invoke(
  44. function () use ($exceptionClass) {
  45. throw new $exceptionClass('Some meaningful message.');
  46. },
  47. [[0]]
  48. );
  49. }
  50. /**
  51. * @return array
  52. */
  53. public function callbackDataProvider()
  54. {
  55. return [
  56. [
  57. 'Passed: 0, Failed: 1, Incomplete: 0, Skipped: 0.',
  58. 'fail',
  59. \PHPUnit\Framework\AssertionFailedError::class,
  60. ],
  61. ['Passed: 0, Failed: 1, Incomplete: 0, Skipped: 0.', 'fail', \PHPUnit\Framework\OutputError::class],
  62. [
  63. 'Passed: 0, Failed: 1, Incomplete: 0, Skipped: 0.',
  64. 'fail',
  65. \PHPUnit\Framework\ExpectationFailedException::class
  66. ],
  67. [
  68. 'Passed: 0, Failed: 0, Incomplete: 1, Skipped: 0.',
  69. 'markTestIncomplete',
  70. \PHPUnit\Framework\IncompleteTestError::class
  71. ],
  72. [
  73. 'Passed: 0, Failed: 0, Incomplete: 0, Skipped: 1.',
  74. 'markTestSkipped',
  75. \PHPUnit\Framework\SkippedTestError::class
  76. ]
  77. ];
  78. }
  79. }