TransactionTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Test\Unit\Model\Order\Payment;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  8. class TransactionTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /** @var \Magento\Sales\Model\Order\Payment\Transaction */
  11. protected $transaction;
  12. /** @var ObjectManagerHelper */
  13. protected $objectManagerHelper;
  14. /** @var \Magento\Framework\Model\Context|\PHPUnit_Framework_MockObject_MockObject */
  15. protected $contextMock;
  16. /** @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
  17. protected $eventManagerMock;
  18. protected function setUp()
  19. {
  20. $this->contextMock = $this->getMockBuilder(\Magento\Framework\Model\Context::class)
  21. ->setMethods(['getEventDispatcher'])
  22. ->disableOriginalConstructor()
  23. ->getMock();
  24. $this->eventManagerMock = $this->getMockBuilder(\Magento\Framework\Event\ManagerInterface::class)
  25. ->setMethods(['dispatch'])
  26. ->getMockForAbstractClass();
  27. $this->contextMock->expects($this->once())
  28. ->method('getEventDispatcher')
  29. ->willReturn($this->eventManagerMock);
  30. $this->objectManagerHelper = new ObjectManagerHelper($this);
  31. $this->transaction = $this->objectManagerHelper->getObject(
  32. \Magento\Sales\Model\Order\Payment\Transaction::class,
  33. [
  34. 'context' => $this->contextMock
  35. ]
  36. );
  37. }
  38. public function testGetHtmlTxnId()
  39. {
  40. $this->eventManagerMock->expects($this->once())
  41. ->method('dispatch');
  42. $this->transaction->setData('html_txn_id', 'test');
  43. $this->assertEquals('test', $this->transaction->getHtmlTxnId());
  44. }
  45. public function testGetHtmlTxnIdIsNull()
  46. {
  47. $this->eventManagerMock->expects($this->once())
  48. ->method('dispatch');
  49. $this->transaction->setData('txn_id', 'test');
  50. $this->assertEquals('test', $this->transaction->getHtmlTxnId());
  51. $this->assertEquals(null, $this->transaction->getData('html_txn_id'));
  52. }
  53. }