DataAssignObserverTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License").
  6. * You may not use this file except in compliance with the License.
  7. * A copy of the License is located at
  8. *
  9. * http://aws.amazon.com/apache2.0
  10. *
  11. * or in the "license" file accompanying this file. This file is distributed
  12. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  13. * express or implied. See the License for the specific language governing
  14. * permissions and limitations under the License.
  15. */
  16. namespace Amazon\Payment\Test\Unit\Observer;
  17. use Magento\Framework\DataObject;
  18. use Magento\Framework\Event;
  19. use Magento\Payment\Model\InfoInterface;
  20. use Magento\Payment\Observer\AbstractDataAssignObserver;
  21. use Amazon\Payment\Observer\DataAssignObserver;
  22. use Magento\Quote\Api\Data\PaymentInterface;
  23. /**
  24. * Class DataAssignObserverTest
  25. */
  26. class DataAssignObserverTest extends \PHPUnit\Framework\TestCase
  27. {
  28. const KEY_SANDBOX_SIMULATION_REFERENCE = 'sandbox_simulation_reference';
  29. public function testExecute()
  30. {
  31. $observerContainer = $this->getMockBuilder(Event\Observer::class)
  32. ->disableOriginalConstructor()
  33. ->getMock();
  34. $event = $this->getMockBuilder(Event::class)
  35. ->disableOriginalConstructor()
  36. ->getMock();
  37. $paymentInfoModel = $this->createMock(InfoInterface::class);
  38. $dataObject = new DataObject(
  39. [
  40. PaymentInterface::KEY_ADDITIONAL_DATA => [
  41. 'sandbox_simulation_reference' => self::KEY_SANDBOX_SIMULATION_REFERENCE
  42. ]
  43. ]
  44. );
  45. $observerContainer->expects(static::atLeastOnce())
  46. ->method('getEvent')
  47. ->willReturn($event);
  48. $event->expects(static::exactly(2))
  49. ->method('getDataByKey')
  50. ->willReturnMap(
  51. [
  52. [AbstractDataAssignObserver::MODEL_CODE, $paymentInfoModel],
  53. [AbstractDataAssignObserver::DATA_CODE, $dataObject]
  54. ]
  55. );
  56. $paymentInfoModel->expects(static::at(0))
  57. ->method('setAdditionalInformation')
  58. ->with('sandbox_simulation_reference', self::KEY_SANDBOX_SIMULATION_REFERENCE);
  59. $observer = new DataAssignObserver();
  60. $observer->execute($observerContainer);
  61. }
  62. }