CollectionTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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\Collection;
  8. use \Magento\Framework\Pricing\Price\Pool;
  9. /**
  10. * Test for class Collection
  11. */
  12. class CollectionTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @var \Magento\Framework\Pricing\Price\Collection
  16. */
  17. protected $collection;
  18. /**
  19. * @var \Magento\Framework\Pricing\Price\Pool
  20. */
  21. protected $pool;
  22. /**
  23. * @var \Magento\Framework\Pricing\Price\PriceInterface|\PHPUnit_Framework_MockObject_MockObject
  24. */
  25. protected $priceMock;
  26. /**
  27. * @var \Magento\Framework\Pricing\SaleableInterface|\PHPUnit_Framework_MockObject_MockObject
  28. */
  29. protected $saleableItemMock;
  30. /**
  31. * @var \Magento\Framework\Pricing\Price\Factory|\PHPUnit_Framework_MockObject_MockObject
  32. */
  33. protected $factoryMock;
  34. /**
  35. * @var float
  36. */
  37. protected $quantity;
  38. /**
  39. * Test setUp
  40. */
  41. protected function setUp()
  42. {
  43. $this->pool = new Pool(
  44. [
  45. 'regular_price' => 'RegularPrice',
  46. 'special_price' => 'SpecialPrice',
  47. ]
  48. );
  49. $this->saleableItemMock = $this->getMockForAbstractClass(\Magento\Framework\Pricing\SaleableInterface::class);
  50. $this->priceMock = $this->getMockForAbstractClass(\Magento\Framework\Pricing\Price\PriceInterface::class);
  51. $this->factoryMock = $this->createMock(\Magento\Framework\Pricing\Price\Factory::class);
  52. $this->collection = new Collection(
  53. $this->saleableItemMock,
  54. $this->factoryMock,
  55. $this->pool,
  56. $this->quantity
  57. );
  58. }
  59. /**
  60. * Test get method
  61. */
  62. public function testGet()
  63. {
  64. $this->factoryMock->expects($this->once())
  65. ->method('create')
  66. ->with(
  67. $this->equalTo($this->saleableItemMock),
  68. $this->equalTo('RegularPrice'),
  69. $this->quantity
  70. )
  71. ->will($this->returnValue($this->priceMock));
  72. $this->assertEquals($this->priceMock, $this->collection->get('regular_price'));
  73. //Calling the get method again with the same code, cached copy should be used
  74. $this->assertEquals($this->priceMock, $this->collection->get('regular_price'));
  75. }
  76. /**
  77. * Test current method
  78. */
  79. public function testCurrent()
  80. {
  81. $this->factoryMock->expects($this->once())
  82. ->method('create')
  83. ->with(
  84. $this->equalTo($this->saleableItemMock),
  85. $this->equalTo($this->pool->current()),
  86. $this->quantity
  87. )
  88. ->will($this->returnValue($this->priceMock));
  89. $this->assertEquals($this->priceMock, $this->collection->current());
  90. }
  91. }