ValueHandlerPoolTest.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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\Config;
  7. use Magento\Payment\Gateway\Config\ValueHandlerInterface;
  8. use Magento\Payment\Gateway\Config\ValueHandlerPool;
  9. class ValueHandlerPoolTest extends \PHPUnit\Framework\TestCase
  10. {
  11. public function testConstructorException()
  12. {
  13. $this->expectException('LogicException');
  14. $tMapFactory = $this->getMockBuilder(\Magento\Framework\ObjectManager\TMapFactory::class)
  15. ->disableOriginalConstructor()
  16. ->setMethods(['create'])
  17. ->getMock();
  18. $tMapFactory->expects(static::never())
  19. ->method('create');
  20. new ValueHandlerPool($tMapFactory, []);
  21. }
  22. public function testGet()
  23. {
  24. $defaultHandler = $this->getMockBuilder(\Magento\Payment\Gateway\Config\ValueHandlerInterface::class)
  25. ->disableOriginalConstructor()
  26. ->getMockForAbstractClass();
  27. $someValueHandler = $this->getMockBuilder(\Magento\Payment\Gateway\Config\ValueHandlerInterface::class)
  28. ->disableOriginalConstructor()
  29. ->getMockForAbstractClass();
  30. $tMapFactory = $this->getMockBuilder(\Magento\Framework\ObjectManager\TMapFactory::class)
  31. ->disableOriginalConstructor()
  32. ->setMethods(['create'])
  33. ->getMock();
  34. $tMap = $this->getMockBuilder(\Magento\Framework\ObjectManager\TMap::class)
  35. ->disableOriginalConstructor()
  36. ->getMock();
  37. $tMapFactory->expects(static::once())
  38. ->method('create')
  39. ->with(
  40. [
  41. 'array' => [
  42. ValueHandlerPool::DEFAULT_HANDLER =>
  43. \Magento\Payment\Gateway\Config\ValueHandlerInterface::class,
  44. 'some_value' => \Magento\Payment\Gateway\Config\ValueHandlerInterface::class
  45. ],
  46. 'type' => ValueHandlerInterface::class
  47. ]
  48. )
  49. ->willReturn($tMap);
  50. $tMap->expects(static::exactly(3))
  51. ->method('offsetExists')
  52. ->willReturnMap(
  53. [
  54. [ValueHandlerPool::DEFAULT_HANDLER, true],
  55. ['some_value', true]
  56. ]
  57. );
  58. $tMap->expects(static::exactly(3))
  59. ->method('offsetGet')
  60. ->willReturnMap(
  61. [
  62. [ValueHandlerPool::DEFAULT_HANDLER, $defaultHandler],
  63. ['some_value', $someValueHandler]
  64. ]
  65. );
  66. $pool = new ValueHandlerPool(
  67. $tMapFactory,
  68. [
  69. ValueHandlerPool::DEFAULT_HANDLER => \Magento\Payment\Gateway\Config\ValueHandlerInterface::class,
  70. 'some_value' => \Magento\Payment\Gateway\Config\ValueHandlerInterface::class
  71. ]
  72. );
  73. static::assertSame($someValueHandler, $pool->get('some_value'));
  74. static::assertSame($defaultHandler, $pool->get(ValueHandlerPool::DEFAULT_HANDLER));
  75. static::assertSame($defaultHandler, $pool->get('no_custom_logic_required'));
  76. }
  77. }