Skip to content

Commit ab6cabd

Browse files
committed
Add tests for cached getVersion and update class description
1 parent 16ab63b commit ab6cabd

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

lib/internal/Magento/Framework/App/ProductMetadata.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
use Magento\Framework\Composer\ComposerInformation;
1414

1515
/**
16-
* Class ProductMetadata
17-
*
18-
* @package Magento\Framework\App
16+
* Magento application product metadata
1917
*/
2018
class ProductMetadata implements ProductMetadataInterface
2119
{

lib/internal/Magento/Framework/App/Test/Unit/ProductMetadataTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Framework\App\Test\Unit;
77

8+
use Magento\Framework\App\CacheInterface;
89
use Magento\Framework\App\ProductMetadata;
910
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1011

@@ -20,16 +21,27 @@ class ProductMetadataTest extends \PHPUnit\Framework\TestCase
2021
*/
2122
private $composerInformationMock;
2223

24+
/**
25+
* @var CacheInterface|\PHPUnit_Framework_MockObject_MockObject
26+
*/
27+
private $cacheMock;
28+
2329
protected function setUp()
2430
{
2531
$this->composerInformationMock = $this->getMockBuilder(\Magento\Framework\Composer\ComposerInformation::class)
2632
->disableOriginalConstructor()->getMock();
2733

34+
$this->cacheMock = $this->getMockBuilder(CacheInterface::class)->getMock();
35+
2836
$objectManager = new ObjectManager($this);
2937
$this->productMetadata = $objectManager->getObject(ProductMetadata::class);
3038
$reflectionProperty = new \ReflectionProperty($this->productMetadata, 'composerInformation');
3139
$reflectionProperty->setAccessible(true);
3240
$reflectionProperty->setValue($this->productMetadata, $this->composerInformationMock);
41+
42+
$reflectionProperty = new \ReflectionProperty($this->productMetadata, 'cache');
43+
$reflectionProperty->setAccessible(true);
44+
$reflectionProperty->setValue($this->productMetadata, $this->cacheMock);
3345
}
3446

3547
/**
@@ -40,11 +52,21 @@ protected function setUp()
4052
public function testGetVersion($packageList, $expectedVersion)
4153
{
4254
$this->composerInformationMock->expects($this->any())->method('getSystemPackages')->willReturn($packageList);
55+
$this->cacheMock->expects($this->once())->method('save')->with($expectedVersion);
4356
$productVersion = $this->productMetadata->getVersion();
4457
$this->assertNotEmpty($productVersion, 'Empty product version');
4558
$this->assertEquals($expectedVersion, $productVersion);
4659
}
4760

61+
public function testGetVersionCached()
62+
{
63+
$expectedVersion = '1.2.3';
64+
$this->composerInformationMock->expects($this->never())->method('getSystemPackages');
65+
$this->cacheMock->expects($this->once())->method('load')->willReturn($expectedVersion);
66+
$productVersion = $this->productMetadata->getVersion();
67+
$this->assertEquals($expectedVersion, $productVersion);
68+
}
69+
4870
/**
4971
* @return array
5072
*/

0 commit comments

Comments
 (0)