5
5
*/
6
6
namespace Magento \Framework \App \Test \Unit ;
7
7
8
+ use Magento \Framework \App \CacheInterface ;
8
9
use Magento \Framework \App \ProductMetadata ;
9
10
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
10
11
@@ -20,13 +21,20 @@ class ProductMetadataTest extends \PHPUnit\Framework\TestCase
20
21
*/
21
22
private $ composerInformationMock ;
22
23
24
+ /**
25
+ * @var CacheInterface|\PHPUnit_Framework_MockObject_MockObject
26
+ */
27
+ private $ cacheMock ;
28
+
23
29
protected function setUp ()
24
30
{
25
31
$ this ->composerInformationMock = $ this ->getMockBuilder (\Magento \Framework \Composer \ComposerInformation::class)
26
32
->disableOriginalConstructor ()->getMock ();
27
33
34
+ $ this ->cacheMock = $ this ->getMockBuilder (CacheInterface::class)->getMock ();
35
+
28
36
$ objectManager = new ObjectManager ($ this );
29
- $ this ->productMetadata = $ objectManager ->getObject (ProductMetadata::class);
37
+ $ this ->productMetadata = $ objectManager ->getObject (ProductMetadata::class, [ ' cache ' => $ this -> cacheMock ] );
30
38
$ reflectionProperty = new \ReflectionProperty ($ this ->productMetadata , 'composerInformation ' );
31
39
$ reflectionProperty ->setAccessible (true );
32
40
$ reflectionProperty ->setValue ($ this ->productMetadata , $ this ->composerInformationMock );
@@ -40,11 +48,22 @@ protected function setUp()
40
48
public function testGetVersion ($ packageList , $ expectedVersion )
41
49
{
42
50
$ this ->composerInformationMock ->expects ($ this ->any ())->method ('getSystemPackages ' )->willReturn ($ packageList );
51
+ $ this ->cacheMock ->expects ($ this ->once ())->method ('save ' )->with ($ expectedVersion );
43
52
$ productVersion = $ this ->productMetadata ->getVersion ();
44
53
$ this ->assertNotEmpty ($ productVersion , 'Empty product version ' );
45
54
$ this ->assertEquals ($ expectedVersion , $ productVersion );
46
55
}
47
56
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
+
48
67
/**
49
68
* @return array
50
69
*/
0 commit comments