diff --git a/setup/src/Magento/Setup/Model/MarketplaceManager.php b/setup/src/Magento/Setup/Model/MarketplaceManager.php
index 707f31ac827a606f8bdf7580a8999d0f0fa903e0..cf80db1f0d0abb183e284a72caba98ac5c2e7d9a 100644
--- a/setup/src/Magento/Setup/Model/MarketplaceManager.php
+++ b/setup/src/Magento/Setup/Model/MarketplaceManager.php
@@ -269,17 +269,14 @@ class MarketplaceManager
         if ($directory->isExist($this->pathToAuthFile) && $directory->isReadable($this->pathToAuthFile)) {
             try {
                 $authJsonData = $this->getAuthJson();
-                if (!empty($authJsonData) && isset($authJsonData['http-basic'][$serviceUrl])) {
+                if (isset($authJsonData['http-basic'][$serviceUrl])) {
                     unset($authJsonData['http-basic'][$serviceUrl]);
-                    if (empty($authJsonData['http-basic'])) {
-                        return unlink(getenv('COMPOSER_HOME') . DIRECTORY_SEPARATOR . $this->pathToAuthFile);
+                    $path = DirectoryList::COMPOSER_HOME . DIRECTORY_SEPARATOR . $this->pathToAuthFile;
+                    if ($authJsonData === ['http-basic' => []]) {
+                        return $this->getDirectory()->delete($path);
                     } else {
                         $data = json_encode($authJsonData, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
-                        $this->getDirectory()->writeFile(
-                            DirectoryList::COMPOSER_HOME . DIRECTORY_SEPARATOR . $this->pathToAuthFile,
-                            $data
-                        );
-                        return true;
+                        return $data !== false && $this->getDirectory()->writeFile($path, $data);
                     }
                 }
             } catch (\Exception $e) {
diff --git a/setup/src/Magento/Setup/Test/Unit/Model/MarketplaceManagerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/MarketplaceManagerTest.php
index e8a292f49841b1146d4a4b6110b15d06a0649244..c7ab397d7fffb41aa219f79d23fa01705493ffd6 100644
--- a/setup/src/Magento/Setup/Test/Unit/Model/MarketplaceManagerTest.php
+++ b/setup/src/Magento/Setup/Test/Unit/Model/MarketplaceManagerTest.php
@@ -486,9 +486,12 @@ class MarketplaceManagerTest extends \PHPUnit_Framework_TestCase
             ->method('getCredentialBaseUrl')
             ->will($this->returnValue($this->checkingCredentialsUrl));
         $marketplaceManager
-            ->expects($this->never())
+            ->expects($this->once())
             ->method('getDirectory')
             ->will($this->returnValue($directory));
+        $directory
+            ->expects($this->once())
+            ->method('delete');
         $directory
             ->expects($this->never())
             ->method('writeFile');