DataTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Mview\Test\Unit\Config;
  7. class DataTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Framework\Mview\Config\Data
  11. */
  12. private $config;
  13. /**
  14. * @var \Magento\Framework\Mview\Config\Reader|\PHPUnit_Framework_MockObject_MockObject
  15. */
  16. private $reader;
  17. /**
  18. * @var \Magento\Framework\Config\CacheInterface|\PHPUnit_Framework_MockObject_MockObject
  19. */
  20. private $cache;
  21. /**
  22. * @var \Magento\Framework\Mview\View\State\CollectionInterface|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. private $stateCollection;
  25. /**
  26. * @var string
  27. */
  28. private $cacheId = 'mview_config';
  29. /**
  30. * @var string
  31. */
  32. private $views = ['view1' => [], 'view3' => []];
  33. /**
  34. * @var \Magento\Framework\Serialize\SerializerInterface|\PHPUnit_Framework_MockObject_MockObject
  35. */
  36. private $serializerMock;
  37. protected function setUp()
  38. {
  39. $this->reader = $this->createPartialMock(\Magento\Framework\Mview\Config\Reader::class, ['read']);
  40. $this->cache = $this->getMockForAbstractClass(
  41. \Magento\Framework\Config\CacheInterface::class,
  42. [],
  43. '',
  44. false,
  45. false,
  46. true,
  47. ['test', 'load', 'save']
  48. );
  49. $this->stateCollection = $this->getMockForAbstractClass(
  50. \Magento\Framework\Mview\View\State\CollectionInterface::class,
  51. [],
  52. '',
  53. false,
  54. false,
  55. true,
  56. ['getItems']
  57. );
  58. $this->serializerMock = $this->createMock(\Magento\Framework\Serialize\SerializerInterface::class);
  59. }
  60. public function testConstructorWithCache()
  61. {
  62. $this->cache->expects($this->once())->method('test')->with($this->cacheId)->will($this->returnValue(true));
  63. $this->cache->expects($this->once())
  64. ->method('load')
  65. ->with($this->cacheId);
  66. $this->stateCollection->expects($this->never())->method('getItems');
  67. $this->serializerMock->expects($this->once())
  68. ->method('unserialize')
  69. ->willReturn($this->views);
  70. $this->config = new \Magento\Framework\Mview\Config\Data(
  71. $this->reader,
  72. $this->cache,
  73. $this->stateCollection,
  74. $this->cacheId,
  75. $this->serializerMock
  76. );
  77. }
  78. public function testConstructorWithoutCache()
  79. {
  80. $this->cache->expects($this->once())->method('test')->with($this->cacheId)->will($this->returnValue(false));
  81. $this->cache->expects($this->once())->method('load')->with($this->cacheId)->will($this->returnValue(false));
  82. $this->reader->expects($this->once())->method('read')->will($this->returnValue($this->views));
  83. $stateExistent = $this->getMockBuilder(\Magento\Framework\Mview\View\StateInterface::class)
  84. ->setMethods(['getViewId', '__wakeup', 'delete'])
  85. ->getMockForAbstractClass();
  86. $stateExistent->expects($this->once())->method('getViewId')->will($this->returnValue('view1'));
  87. $stateExistent->expects($this->never())->method('delete');
  88. $stateNonexistent = $this->getMockBuilder(\Magento\Framework\Mview\View\StateInterface::class)
  89. ->setMethods(['getViewId', '__wakeup', 'delete'])
  90. ->getMockForAbstractClass();
  91. $stateNonexistent->expects($this->once())->method('getViewId')->will($this->returnValue('view2'));
  92. $stateNonexistent->expects($this->once())->method('delete');
  93. $states = [$stateExistent, $stateNonexistent];
  94. $this->stateCollection->expects($this->once())->method('getItems')->will($this->returnValue($states));
  95. $this->config = new \Magento\Framework\Mview\Config\Data(
  96. $this->reader,
  97. $this->cache,
  98. $this->stateCollection,
  99. $this->cacheId,
  100. $this->serializerMock
  101. );
  102. }
  103. }