7
7
namespace Magento \Setup \Test \Unit \Model ;
8
8
9
9
use \Magento \Setup \Model \PathBuilder ;
10
- use \Magento \Setup \Model \Cron \ReadinessCheck ;
11
10
12
11
class PathBuilderTest extends \PHPUnit_Framework_TestCase
13
12
{
@@ -41,18 +40,15 @@ public function setup()
41
40
'' ,
42
41
false
43
42
);
44
- $ objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
45
43
$ this ->readFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->readerMock );
46
- $ this ->pathBuilder = $ objectManager ->getObject (
47
- 'Magento\Setup\Model\PathBuilder ' ,
48
- ['readFactory ' => $ this ->readFactoryMock ]
49
- );
44
+ $ this ->pathBuilder = new PathBuilder ($ this ->readFactoryMock );
50
45
}
51
46
52
- // Error scenario ( magento/magento2-base/composer.json not found)
53
- public function testBuildNoComposerJsonFile ()
47
+ // Error scenario: magento/magento2-base/composer.json not found
48
+ public function testBuildComposerJsonFileNotFound ()
54
49
{
55
50
$ this ->readerMock ->expects ($ this ->once ())->method ('isExist ' )->willReturn (false );
51
+ $ this ->readerMock ->expects ($ this ->never ())->method ('isReadable ' );
56
52
$ this ->readerMock ->expects ($ this ->never ())->method ('readFile ' );
57
53
$ this ->setExpectedException (
58
54
'Magento\Setup\Exception ' ,
@@ -61,10 +57,49 @@ public function testBuildNoComposerJsonFile()
61
57
$ this ->pathBuilder ->build ();
62
58
}
63
59
60
+ // Error scenario: magento/magento2-base/composer.json file could not be read
61
+ public function testBuildComposerJsonFileNotReadable ()
62
+ {
63
+ $ this ->readerMock ->expects ($ this ->once ())->method ('isExist ' )->willReturn (true );
64
+ $ this ->readerMock ->expects ($ this ->once ())->method ('isReadable ' )->willReturn (false );
65
+ $ this ->readerMock ->expects ($ this ->never ())->method ('readFile ' );
66
+ $ this ->setExpectedException (
67
+ 'Magento\Setup\Exception ' ,
68
+ sprintf ('Could not read %s file. ' , PathBuilder::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE )
69
+ );
70
+ $ this ->pathBuilder ->build ();
71
+ }
72
+
73
+ // Error scenario: ["extra"]["map"] is absent within magento/magento2-base/composer.json file
74
+ public function testBuildNoExtraMapSectionInComposerJsonFile ()
75
+ {
76
+ $ this ->readerMock ->expects ($ this ->once ())->method ('isExist ' )->willReturn (true );
77
+ $ this ->readerMock ->expects ($ this ->once ())->method ('isReadable ' )->willReturn (true );
78
+ $ jsonData = json_encode (
79
+ [
80
+ PathBuilder::COMPOSER_KEY_EXTRA =>
81
+ [
82
+ __FILE__ ,
83
+ __FILE__
84
+ ]
85
+ ]
86
+ );
87
+ $ this ->readerMock ->expects ($ this ->once ())->method ('readFile ' )->willReturn ($ jsonData );
88
+ $ this ->setExpectedException (
89
+ 'Magento\Setup\Exception ' ,
90
+ sprintf (
91
+ 'Could not find "extra" => "map" section within %s file. ' ,
92
+ PathBuilder::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE
93
+ )
94
+ );
95
+ $ this ->pathBuilder ->build ();
96
+ }
97
+
64
98
// Success scenario
65
99
public function testBuild ()
66
100
{
67
101
$ this ->readerMock ->expects ($ this ->once ())->method ('isExist ' )->willReturn (true );
102
+ $ this ->readerMock ->expects ($ this ->once ())->method ('isReadable ' )->willReturn (true );
68
103
$ jsonData = json_encode (
69
104
[
70
105
PathBuilder::COMPOSER_KEY_EXTRA =>
@@ -88,5 +123,4 @@ public function testBuild()
88
123
$ actualList = $ this ->pathBuilder ->build ();
89
124
$ this ->assertEquals ($ expectedList , $ actualList );
90
125
}
91
-
92
126
}
0 commit comments