OrdersUpdaterTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Test\Unit\Model\Billing\Agreement;
  7. class OrdersUpdaterTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var OrdersUpdater
  11. */
  12. protected $_model;
  13. /**
  14. * @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $_registry;
  17. /**
  18. * @var \Magento\Paypal\Model\ResourceModel\Billing\Agreement|\PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $_agreementResource;
  21. protected function setUp()
  22. {
  23. $this->_registry = $this->createMock(\Magento\Framework\Registry::class);
  24. $this->_agreementResource = $this->createMock(\Magento\Paypal\Model\ResourceModel\Billing\Agreement::class);
  25. $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  26. $this->_model = $helper->getObject(
  27. \Magento\Paypal\Model\Billing\Agreement\OrdersUpdater::class,
  28. ['coreRegistry' => $this->_registry, 'agreementResource' => $this->_agreementResource]
  29. );
  30. }
  31. public function testUpdate()
  32. {
  33. $agreement = $this->createMock(\Magento\Paypal\Model\Billing\Agreement::class);
  34. $argument = $this->createMock(\Magento\Sales\Model\ResourceModel\Order\Collection::class);
  35. $this->_registry->expects(
  36. $this->once()
  37. )->method(
  38. 'registry'
  39. )->with(
  40. 'current_billing_agreement'
  41. )->will(
  42. $this->returnValue($agreement)
  43. );
  44. $agreement->expects($this->once())->method('getId')->will($this->returnValue('agreement id'));
  45. $this->_agreementResource->expects(
  46. $this->once()
  47. )->method(
  48. 'addOrdersFilter'
  49. )->with(
  50. $this->identicalTo($argument),
  51. 'agreement id'
  52. );
  53. $this->assertSame($argument, $this->_model->update($argument));
  54. }
  55. /**
  56. * @expectedException \DomainException
  57. */
  58. public function testUpdateWhenBillingAgreementIsNotSet()
  59. {
  60. $this->_registry->expects(
  61. $this->once()
  62. )->method(
  63. 'registry'
  64. )->with(
  65. 'current_billing_agreement'
  66. )->will(
  67. $this->returnValue(null)
  68. );
  69. $this->_model->update('any argument');
  70. }
  71. }