PoolTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Pricing\Test\Unit\Price;
  7. use \Magento\Framework\Pricing\Price\Pool;
  8. /**
  9. * Test for Pool
  10. */
  11. class PoolTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var \Magento\Framework\Pricing\Price\Pool
  15. */
  16. protected $pool;
  17. /**
  18. * @var array
  19. */
  20. protected $prices;
  21. /**
  22. * @var array
  23. */
  24. protected $target;
  25. /**
  26. * \Iterator
  27. */
  28. protected $targetPool;
  29. /**
  30. * Test setUp
  31. */
  32. protected function setUp()
  33. {
  34. $this->prices = [
  35. 'regular_price' => 'RegularPrice',
  36. 'special_price' => 'SpecialPrice',
  37. ];
  38. $this->target = [
  39. 'regular_price' => 'TargetRegularPrice',
  40. ];
  41. $this->targetPool = new Pool($this->target);
  42. $this->pool = new Pool($this->prices, $this->targetPool);
  43. }
  44. /**
  45. * test mergedConfiguration
  46. */
  47. public function testMergedConfiguration()
  48. {
  49. $expected = new Pool([
  50. 'regular_price' => 'RegularPrice',
  51. 'special_price' => 'SpecialPrice',
  52. ]);
  53. $this->assertEquals($expected, $this->pool);
  54. }
  55. /**
  56. * Test get method
  57. */
  58. public function testGet()
  59. {
  60. $this->assertEquals('RegularPrice', $this->pool->get('regular_price'));
  61. $this->assertEquals('SpecialPrice', $this->pool->get('special_price'));
  62. }
  63. /**
  64. * Test abilities of ArrayAccess interface
  65. */
  66. public function testArrayAccess()
  67. {
  68. $this->assertEquals('RegularPrice', $this->pool['regular_price']);
  69. $this->assertEquals('SpecialPrice', $this->pool['special_price']);
  70. $this->pool['fake_price'] = 'FakePrice';
  71. $this->assertEquals('FakePrice', $this->pool['fake_price']);
  72. $this->assertTrue(isset($this->pool['fake_price']));
  73. unset($this->pool['fake_price']);
  74. $this->assertFalse(isset($this->pool['fake_price']));
  75. $this->assertNull($this->pool['fake_price']);
  76. }
  77. /**
  78. * Test abilities of Iterator interface
  79. */
  80. public function testIterator()
  81. {
  82. foreach ($this->pool as $code => $class) {
  83. $this->assertEquals($this->pool[$code], $class);
  84. }
  85. }
  86. }