Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BasePackageInfoTest.php
Go to the documentation of this file.
1 <?php
8 
9 use \Magento\Setup\Model\BasePackageInfo;
10 
15 class BasePackageInfoTest extends \PHPUnit\Framework\TestCase
16 {
20  private $readFactoryMock;
21 
25  private $readerMock;
26 
30  private $basePackageInfo;
31 
32  public function setup()
33  {
34  $this->readFactoryMock = $this->createMock(\Magento\Framework\Filesystem\Directory\ReadFactory::class);
35  $this->readerMock = $this->getMockForAbstractClass(
36  \Magento\Framework\Filesystem\Directory\ReadInterface::class,
37  [],
38  '',
39  false
40  );
41  $this->readFactoryMock->expects($this->once())->method('create')->willReturn($this->readerMock);
42  $this->basePackageInfo = new BasePackageInfo($this->readFactoryMock);
43  }
44 
45  // Error scenario: magento/magento2-base/composer.json not found
47  {
48  $this->readerMock->expects($this->once())->method('isExist')->willReturn(false);
49  $this->readerMock->expects($this->never())->method('isReadable');
50  $this->readerMock->expects($this->never())->method('readFile');
51  $this->expectException(\Magento\Setup\Exception::class);
52  $this->expectExceptionMessage(
53  sprintf('Could not locate %s file.', BasePackageInfo::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE)
54  );
55  $this->basePackageInfo->getPaths();
56  }
57 
58  // Error scenario: magento/magento2-base/composer.json file could not be read
60  {
61  $this->readerMock->expects($this->once())->method('isExist')->willReturn(true);
62  $this->readerMock->expects($this->once())->method('isReadable')->willReturn(false);
63  $this->readerMock->expects($this->never())->method('readFile');
64  $this->expectException(\Magento\Setup\Exception::class);
65  $this->expectExceptionMessage(
66  sprintf('Could not read %s file.', BasePackageInfo::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE)
67  );
68  $this->basePackageInfo->getPaths();
69  }
70 
71  // Scenario: ["extra"]["map"] is absent within magento/magento2-base/composer.json file
73  {
74  $this->readerMock->expects($this->once())->method('isExist')->willReturn(true);
75  $this->readerMock->expects($this->once())->method('isReadable')->willReturn(true);
76  $jsonData = json_encode(
77  [
79  [
80  __FILE__,
81  __FILE__
82  ]
83  ]
84  );
85  $this->readerMock->expects($this->once())->method('readFile')->willReturn($jsonData);
86  $expectedList = [];
87  $actualList = $this->basePackageInfo->getPaths();
88  $this->assertEquals($expectedList, $actualList);
89  }
90 
91  // Success scenario
92  public function testBasePackageInfo()
93  {
94  $this->readerMock->expects($this->once())->method('isExist')->willReturn(true);
95  $this->readerMock->expects($this->once())->method('isReadable')->willReturn(true);
96  $jsonData = json_encode(
97  [
99  [
101  [
102  [
103  __FILE__,
104  __FILE__
105  ],
106  [
107  __DIR__,
108  __DIR__
109  ]
110  ]
111  ]
112  ]
113  );
114  $this->readerMock->expects($this->once())->method('readFile')->willReturn($jsonData);
115  $expectedList = [__FILE__, __DIR__];
116  $actualList = $this->basePackageInfo->getPaths();
117  $this->assertEquals($expectedList, $actualList);
118  }
119 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
defined('MTF_BOOT_FILE')||define('MTF_BOOT_FILE' __FILE__
Definition: bootstrap.php:7