CompositeTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Test\Unit\Model\Method\Specification;
  7. /**
  8. * Composite Test
  9. */
  10. class CompositeTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \Magento\Payment\Model\Method\Specification\Factory|\PHPUnit_Framework_MockObject_MockObject
  14. */
  15. protected $factoryMock;
  16. protected function setUp()
  17. {
  18. $this->factoryMock = $this->createMock(\Magento\Payment\Model\Method\Specification\Factory::class);
  19. }
  20. /**
  21. * @param array $specifications
  22. * @return \Magento\Payment\Model\Method\Specification\Composite
  23. */
  24. protected function createComposite($specifications = [])
  25. {
  26. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  27. return $objectManager->getObject(
  28. \Magento\Payment\Model\Method\Specification\Composite::class,
  29. ['factory' => $this->factoryMock, 'specifications' => $specifications]
  30. );
  31. }
  32. /**
  33. * @param bool $firstSpecificationResult
  34. * @param bool $secondSpecificationResult
  35. * @param bool $compositeResult
  36. * @dataProvider compositeDataProvider
  37. */
  38. public function testComposite($firstSpecificationResult, $secondSpecificationResult, $compositeResult)
  39. {
  40. $method = 'method-name';
  41. $specificationFirst = $this->createMock(\Magento\Payment\Model\Method\SpecificationInterface::class);
  42. $specificationFirst->expects(
  43. $this->once()
  44. )->method(
  45. 'isSatisfiedBy'
  46. )->with(
  47. $method
  48. )->will(
  49. $this->returnValue($firstSpecificationResult)
  50. );
  51. $specificationSecond = $this->createMock(\Magento\Payment\Model\Method\SpecificationInterface::class);
  52. $specificationSecond->expects(
  53. $this->any()
  54. )->method(
  55. 'isSatisfiedBy'
  56. )->with(
  57. $method
  58. )->will(
  59. $this->returnValue($secondSpecificationResult)
  60. );
  61. $this->factoryMock->expects(
  62. $this->at(0)
  63. )->method(
  64. 'create'
  65. )->with(
  66. 'SpecificationFirst'
  67. )->will(
  68. $this->returnValue($specificationFirst)
  69. );
  70. $this->factoryMock->expects(
  71. $this->at(1)
  72. )->method(
  73. 'create'
  74. )->with(
  75. 'SpecificationSecond'
  76. )->will(
  77. $this->returnValue($specificationSecond)
  78. );
  79. $composite = $this->createComposite(['SpecificationFirst', 'SpecificationSecond']);
  80. $this->assertEquals(
  81. $compositeResult,
  82. $composite->isSatisfiedBy($method),
  83. 'Composite specification is not satisfied by payment method'
  84. );
  85. }
  86. /**
  87. * @return array
  88. */
  89. public function compositeDataProvider()
  90. {
  91. return [
  92. [true, true, true],
  93. [true, false, false],
  94. [false, true, false],
  95. [false, false, false]
  96. ];
  97. }
  98. }