CommandPoolTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Test\Unit\Gateway\Command;
  7. use Magento\Payment\Gateway\Command\CommandPool;
  8. use Magento\Payment\Gateway\CommandInterface;
  9. class CommandPoolTest extends \PHPUnit\Framework\TestCase
  10. {
  11. public function testGet()
  12. {
  13. $commandI = $this->getMockBuilder(\Magento\Payment\Gateway\CommandInterface::class)
  14. ->getMockForAbstractClass();
  15. $tMapFactory = $this->getMockBuilder(\Magento\Framework\ObjectManager\TMapFactory::class)
  16. ->disableOriginalConstructor()
  17. ->setMethods(['create'])
  18. ->getMock();
  19. $tMap = $this->getMockBuilder(\Magento\Framework\ObjectManager\TMap::class)
  20. ->disableOriginalConstructor()
  21. ->getMock();
  22. $tMapFactory->expects(static::once())
  23. ->method('create')
  24. ->with(
  25. [
  26. 'array' => [\Magento\Payment\Gateway\CommandInterface::class],
  27. 'type' => CommandInterface::class
  28. ]
  29. )
  30. ->willReturn($tMap);
  31. $tMap->expects(static::once())
  32. ->method('offsetExists')
  33. ->with('command')
  34. ->willReturn(true);
  35. $tMap->expects(static::once())
  36. ->method('offsetGet')
  37. ->with('command')
  38. ->willReturn($commandI);
  39. $pool = new CommandPool($tMapFactory, [\Magento\Payment\Gateway\CommandInterface::class]);
  40. static::assertSame($commandI, $pool->get('command'));
  41. }
  42. public function testGetException()
  43. {
  44. $this->expectException(\Magento\Framework\Exception\NotFoundException::class);
  45. $tMapFactory = $this->getMockBuilder(\Magento\Framework\ObjectManager\TMapFactory::class)
  46. ->disableOriginalConstructor()
  47. ->setMethods(['create'])
  48. ->getMock();
  49. $tMap = $this->getMockBuilder(\Magento\Framework\ObjectManager\TMap::class)
  50. ->disableOriginalConstructor()
  51. ->getMock();
  52. $tMapFactory->expects(static::once())
  53. ->method('create')
  54. ->with(
  55. [
  56. 'array' => [],
  57. 'type' => CommandInterface::class
  58. ]
  59. )
  60. ->willReturn($tMap);
  61. $tMap->expects(static::once())
  62. ->method('offsetExists')
  63. ->with('command')
  64. ->willReturn(false);
  65. $pool = new CommandPool($tMapFactory, []);
  66. $pool->get('command');
  67. }
  68. }