AddAmazonButtonTest.php 2.3 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 Amazon\Payment\Block\Minicart\Button;
  18. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  19. use Magento\Catalog\Block\ShortcutButtons;
  20. use Magento\Framework\Event;
  21. use Magento\Framework\Event\Observer;
  22. use Amazon\Payment\Observer\AddAmazonButton;
  23. /**
  24. * Class AddAmazonButtonTest
  25. *
  26. * @see \Amazon\Payment\Observer\AddAmazonButton
  27. */
  28. class AddAmazonButtonTest extends \PHPUnit\Framework\TestCase
  29. {
  30. public function testExecute()
  31. {
  32. $objectManager = new ObjectManager($this);
  33. $data = $objectManager->getObject(\Amazon\Core\Helper\Data::class);
  34. $shortcutFactory = $objectManager->getObject(\Amazon\Payment\Helper\Shortcut\Factory::class);
  35. $addAmazonButton = new AddAmazonButton($data, $shortcutFactory);
  36. /** @var Observer|\PHPUnit_Framework_MockObject_MockObject $observerMock */
  37. $observerMock = $this->getMockBuilder(Observer::class)
  38. ->disableOriginalConstructor()
  39. ->getMock();
  40. /** @var Event|\PHPUnit_Framework_MockObject_MockObject $eventMock */
  41. $eventMock = $this->getMockBuilder(Event::class)
  42. ->setMethods(['getContainer'])
  43. ->disableOriginalConstructor()
  44. ->getMock();
  45. /** @var ShortcutButtons|\PHPUnit_Framework_MockObject_MockObject $shortcutButtonsMock */
  46. $shortcutButtonsMock = $this->getMockBuilder(ShortcutButtons::class)
  47. ->disableOriginalConstructor()
  48. ->getMock();
  49. $observerMock->expects(self::once())
  50. ->method('getEvent')
  51. ->willReturn($eventMock);
  52. $eventMock->expects(self::once())
  53. ->method('getContainer')
  54. ->willReturn($shortcutButtonsMock);
  55. $addAmazonButton->execute($observerMock);
  56. }
  57. }