55 */
66namespace Magento \Framework \App \Test \Unit ;
77
8+ use Magento \Framework \App \CacheInterface ;
89use Magento \Framework \App \ProductMetadata ;
910use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
1011
@@ -20,13 +21,20 @@ 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 );
29- $ this ->productMetadata = $ objectManager ->getObject (ProductMetadata::class);
37+ $ this ->productMetadata = $ objectManager ->getObject (ProductMetadata::class, [ ' cache ' => $ this -> cacheMock ] );
3038 $ reflectionProperty = new \ReflectionProperty ($ this ->productMetadata , 'composerInformation ' );
3139 $ reflectionProperty ->setAccessible (true );
3240 $ reflectionProperty ->setValue ($ this ->productMetadata , $ this ->composerInformationMock );
@@ -40,11 +48,22 @@ protected function setUp()
4048 public function testGetVersion ($ packageList , $ expectedVersion )
4149 {
4250 $ this ->composerInformationMock ->expects ($ this ->any ())->method ('getSystemPackages ' )->willReturn ($ packageList );
51+ $ this ->cacheMock ->expects ($ this ->once ())->method ('save ' )->with ($ expectedVersion );
4352 $ productVersion = $ this ->productMetadata ->getVersion ();
4453 $ this ->assertNotEmpty ($ productVersion , 'Empty product version ' );
4554 $ this ->assertEquals ($ expectedVersion , $ productVersion );
4655 }
4756
57+ public function testGetVersionCached ()
58+ {
59+ $ expectedVersion = '1.2.3 ' ;
60+ $ this ->composerInformationMock ->expects ($ this ->never ())->method ('getSystemPackages ' );
61+ $ this ->cacheMock ->expects ($ this ->once ())->method ('load ' )->willReturn ($ expectedVersion );
62+ $ this ->cacheMock ->expects ($ this ->never ())->method ('save ' );
63+ $ productVersion = $ this ->productMetadata ->getVersion ();
64+ $ this ->assertEquals ($ expectedVersion , $ productVersion );
65+ }
66+
4867 /**
4968 * @return array
5069 */
0 commit comments