9 use \Magento\Setup\Model\PackagesAuth;
29 private $packagesAuth;
32 private $serializerMock;
36 $zendServiceLocator = $this->createMock(\
Zend\ServiceManager\ServiceLocatorInterface::class);
38 ->expects($this->any())
43 'check_credentials_url' =>
'some_url' 46 $this->curl = $this->createMock(\
Magento\Framework\HTTP\Client\Curl::class, [], [],
'',
false);
47 $this->filesystem = $this->createMock(\
Magento\Framework\Filesystem::class, [], [],
'',
false);
48 $this->serializerMock = $this->getMockBuilder(\
Magento\Framework\
Serialize\Serializer\Json::class)
50 $this->serializerMock->expects($this->any())
53 function ($serializedData) {
54 return json_encode($serializedData);
67 $this->curl->expects($this->once())->method(
'setCredentials')->with(
'username',
'password');
68 $this->curl->expects($this->once())->method(
'getStatus');
69 $expectedValue =
'{"success":false,"message":"Bad credentials"}';
70 $returnValue = $this->packagesAuth->checkCredentials(
'username',
'password');
71 $this->assertSame($expectedValue, $returnValue);
76 $this->curl->expects($this->once())->method(
'setCredentials')->with(
'username',
'password');
77 $this->curl->expects($this->once())->method(
'getStatus')->willReturn(200);
78 $this->curl->expects($this->once())->method(
'getBody')->willReturn(
"{'someJson'}");
79 $directory = $this->getMockForAbstractClass(\
Magento\Framework\
Filesystem\Directory\WriteInterface::class);
80 $this->filesystem->expects($this->once())->method(
'getDirectoryWrite')->will($this->returnValue($directory));
81 $directory->expects($this->once())
84 $expectedValue =
'{"success":true}';
85 $returnValue = $this->packagesAuth->checkCredentials(
'username',
'password');
86 $this->assertSame($expectedValue, $returnValue);
91 $this->curl->expects($this->once())->method(
'setCredentials')->with(
'username',
'password');
92 $this->curl->expects($this->once())
94 ->will($this->throwException(
new \
Exception(
"Test error")));
95 $this->curl->expects($this->never())->method(
'getBody')->willReturn(
"{'someJson}");
97 $expectedValue =
'{"success":false,"message":"Test error"}';
98 $returnValue = $this->packagesAuth->checkCredentials(
'username',
'password');
99 $this->assertSame($expectedValue, $returnValue);
104 $directoryWrite = $this->getMockForAbstractClass(\
Magento\Framework\
Filesystem\Directory\WriteInterface::class);
105 $directoryRead = $this->getMockForAbstractClass(\
Magento\Framework\
Filesystem\Directory\ReadInterface::class);
106 $this->filesystem->expects($this->once())->method(
'getDirectoryRead')->will($this->returnValue($directoryRead));
107 $this->filesystem->expects($this->once())
108 ->method(
'getDirectoryWrite')
109 ->will($this->returnValue($directoryWrite));
110 $directoryWrite->expects($this->once())->method(
'isExist')->willReturn(
true);
111 $directoryWrite->expects($this->once())->method(
'isReadable')->willReturn(
true);
112 $directoryWrite->expects($this->once())->method(
'delete')->willReturn(
true);
113 $directoryRead->expects($this->once())->method(
'isExist')->willReturn(
true);
114 $directoryRead->expects($this->once())->method(
'isReadable')->willReturn(
true);
115 $directoryRead->expects($this->once())
117 ->willReturn(
'{"http-basic":{"some_url":{"username":"somename","password":"somepassword"}}}');
119 $this->assertTrue($this->packagesAuth->removeCredentials());
124 $directoryWrite = $this->getMockForAbstractClass(\
Magento\Framework\
Filesystem\Directory\WriteInterface::class);
125 $this->filesystem->expects($this->once())
126 ->method(
'getDirectoryWrite')
127 ->will($this->returnValue($directoryWrite));
128 $directoryWrite->expects($this->once())->method(
'writeFile')->willReturn(
true);
130 $this->assertTrue($this->packagesAuth->saveAuthJson(
"testusername",
"testpassword"));
const PATH_TO_PACKAGES_FILE
testCheckCredentialsActionBadCredentials()
testCheckCredentialsActionWithException()