BaseTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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\PriceInfo;
  7. use \Magento\Framework\Pricing\PriceInfo\Base;
  8. /**
  9. * Test class for \Magento\Framework\Pricing\PriceInfo\Base
  10. */
  11. class BaseTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Pricing\Price\Collection
  15. */
  16. protected $priceCollection;
  17. /**
  18. * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Pricing\Adjustment\Collection
  19. */
  20. protected $adjustmentCollection;
  21. /**
  22. * @var Base
  23. */
  24. protected $model;
  25. protected function setUp()
  26. {
  27. $this->priceCollection = $this->createMock(\Magento\Framework\Pricing\Price\Collection::class);
  28. $this->adjustmentCollection = $this->createMock(\Magento\Framework\Pricing\Adjustment\Collection::class);
  29. $this->model = new Base($this->priceCollection, $this->adjustmentCollection);
  30. }
  31. /**
  32. * test method getPrices()
  33. */
  34. public function testGetPrices()
  35. {
  36. $this->assertEquals($this->priceCollection, $this->model->getPrices());
  37. }
  38. /**
  39. * @param $entryParams
  40. * @param $createCount
  41. * @dataProvider providerGetPrice
  42. */
  43. public function testGetPrice($entryParams, $createCount)
  44. {
  45. $priceCode = current(array_values(reset($entryParams)));
  46. $this->priceCollection
  47. ->expects($this->exactly($createCount))
  48. ->method('get')
  49. ->with($this->equalTo($priceCode))
  50. ->will($this->returnValue('basePrice'));
  51. foreach ($entryParams as $params) {
  52. list($priceCode) = array_values($params);
  53. $this->assertEquals('basePrice', $this->model->getPrice($priceCode));
  54. }
  55. }
  56. /**
  57. * Data provider for testGetPrice
  58. *
  59. * @return array
  60. */
  61. public function providerGetPrice()
  62. {
  63. return [
  64. 'case with empty quantity' => [
  65. 'entryParams' => [
  66. ['priceCode' => 'testCode'],
  67. ],
  68. 'createCount' => 1,
  69. ],
  70. 'case with existing price' => [
  71. 'entryParams' => [
  72. ['priceCode' => 'testCode'],
  73. ['priceCode' => 'testCode'],
  74. ],
  75. 'createCount' => 2,
  76. ],
  77. 'case with quantity' => [
  78. 'entryParams' => [
  79. ['priceCode' => 'testCode'],
  80. ],
  81. 'createCount' => 1,
  82. ],
  83. ];
  84. }
  85. /**
  86. * @covers \Magento\Framework\Pricing\PriceInfo\Base::getAdjustments
  87. */
  88. public function testGetAdjustments()
  89. {
  90. $this->adjustmentCollection->expects($this->once())->method('getItems')->will($this->returnValue('result'));
  91. $this->assertEquals('result', $this->model->getAdjustments());
  92. }
  93. /**
  94. * @covers \Magento\Framework\Pricing\PriceInfo\Base::getAdjustment
  95. */
  96. public function testGetAdjustment()
  97. {
  98. $this->adjustmentCollection->expects($this->any())->method('getItemByCode')
  99. ->with('test1')
  100. ->will($this->returnValue('adjustment'));
  101. $this->assertEquals('adjustment', $this->model->getAdjustment('test1'));
  102. }
  103. }