Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductMetadataTest.php
Go to the documentation of this file.
1 <?php
7 
10 
11 class ProductMetadataTest extends \PHPUnit\Framework\TestCase
12 {
16  private $productMetadata;
17 
21  private $composerInformationMock;
22 
23  protected function setUp()
24  {
25  $this->composerInformationMock = $this->getMockBuilder(\Magento\Framework\Composer\ComposerInformation::class)
26  ->disableOriginalConstructor()->getMock();
27 
28  $objectManager = new ObjectManager($this);
29  $this->productMetadata = $objectManager->getObject(ProductMetadata::class);
30  $reflectionProperty = new \ReflectionProperty($this->productMetadata, 'composerInformation');
31  $reflectionProperty->setAccessible(true);
32  $reflectionProperty->setValue($this->productMetadata, $this->composerInformationMock);
33  }
34 
40  public function testGetVersion($packageList, $expectedVersion)
41  {
42  $this->composerInformationMock->expects($this->any())->method('getSystemPackages')->willReturn($packageList);
43  $productVersion = $this->productMetadata->getVersion();
44  $this->assertNotEmpty($productVersion, 'Empty product version');
45  $this->assertEquals($expectedVersion, $productVersion);
46  }
47 
52  {
53  return [
54  [
55  [
56  0 => [
57  'name' => 'magento/product-community-edition',
58  'version' => '123.456.789'
59  ],
60  1 => [
61  'name' => 'magento/product-other-edition',
62  'version' => '987.654.321'
63  ],
64  ],
65  '123.456.789'
66  ],
67  [
68  [],
69  'UNKNOWN'
70  ]
71  ];
72  }
73 
74  public function testGetEdition()
75  {
76  $productEdition = $this->productMetadata->getEdition();
77  $this->assertNotEmpty($productEdition, 'Empty product edition');
78  }
79 
80  public function testGetName()
81  {
82  $productName = $this->productMetadata->getName();
83  $this->assertNotEmpty($productName, 'Empty product name');
84  }
85 }
$objectManager
Definition: bootstrap.php:17