From 3ca9ad0b7ba0335b0936dd66795877d3a85ea6b6 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 21 Jan 2018 10:36:43 +0530 Subject: [PATCH] Simplify code. --- src/Shell/Task/AssetsTask.php | 22 +++++------ tests/TestCase/Shell/Task/AssetsTaskTest.php | 41 ++++++++------------ 2 files changed, 26 insertions(+), 37 deletions(-) diff --git a/src/Shell/Task/AssetsTask.php b/src/Shell/Task/AssetsTask.php index 6de23bb05a6..ba5d6b0dd52 100644 --- a/src/Shell/Task/AssetsTask.php +++ b/src/Shell/Task/AssetsTask.php @@ -101,11 +101,10 @@ protected function _list($name = null) foreach ($pluginsList as $plugin) { $path = Plugin::path($plugin) . 'webroot'; if (!is_dir($path)) { - $this->out('', 1, Shell::VERBOSE); - $this->out( + $this->verbose('', 1); + $this->verbose( sprintf('Skipping plugin %s. It does not have webroot folder.', $plugin), - 2, - Shell::VERBOSE + 2 ); continue; } @@ -153,10 +152,9 @@ protected function _process($plugins, $copy = false) } if (file_exists($config['destDir'] . $config['link'])) { - $this->out( + $this->verbose( $config['destDir'] . $config['link'] . ' already exists', - 1, - Shell::VERBOSE + 1 ); continue; } @@ -190,10 +188,9 @@ protected function _process($plugins, $copy = false) protected function _remove($config) { if ($config['namespaced'] && !is_dir($config['destDir'])) { - $this->out( + $this->verbose( $config['destDir'] . $config['link'] . ' does not exist', - 1, - Shell::VERBOSE + 1 ); return; @@ -202,10 +199,9 @@ protected function _remove($config) $dest = $config['destDir'] . $config['link']; if (!file_exists($dest)) { - $this->out( + $this->verbose( $dest . ' does not exist', - 1, - Shell::VERBOSE + 1 ); return; diff --git a/tests/TestCase/Shell/Task/AssetsTaskTest.php b/tests/TestCase/Shell/Task/AssetsTaskTest.php index a643b34f70e..1483ba6220a 100644 --- a/tests/TestCase/Shell/Task/AssetsTaskTest.php +++ b/tests/TestCase/Shell/Task/AssetsTaskTest.php @@ -73,23 +73,21 @@ public function testSymlink() $this->Task->symlink(); $path = WWW_ROOT . 'test_plugin'; - $link = new \SplFileInfo($path); $this->assertFileExists($path . DS . 'root.js'); if (DS === '\\') { - $this->assertTrue($link->isDir()); + $this->assertDirectoryExists($path); $folder = new Folder($path); $folder->delete(); } else { - $this->assertTrue($link->isLink()); + $this->assertTrue(is_link($path)); unlink($path); } $path = WWW_ROOT . 'company' . DS . 'test_plugin_three'; - $link = new \SplFileInfo($path); // If "company" directory exists beforehand "test_plugin_three" would // be a link. But if the directory is created by the shell itself // symlinking fails and the assets folder is copied as fallback. - $this->assertTrue($link->isDir()); + $this->assertDirectoryExists($path); $this->assertFileExists($path . DS . 'css' . DS . 'company.css'); $folder = new Folder(WWW_ROOT . 'company'); $folder->delete(); @@ -108,11 +106,10 @@ public function testSymlinkWhenVendorDirectoryExits() $this->Task->symlink(); $path = WWW_ROOT . 'company' . DS . 'test_plugin_three'; - $link = new \SplFileInfo($path); if (DS === '\\') { - $this->assertTrue($link->isDir()); + $this->assertDirectoryExits($path); } else { - $this->assertTrue($link->isLink()); + $this->assertTrue(is_link($path)); } $this->assertFileExists($path . DS . 'css' . DS . 'company.css'); $folder = new Folder(WWW_ROOT . 'company'); @@ -171,9 +168,8 @@ public function testSymlinkingSpecifiedPlugin() unlink($path); $path = WWW_ROOT . 'company' . DS . 'test_plugin_three'; - $link = new \SplFileInfo($path); - $this->assertFalse($link->isDir()); - $this->assertFalse($link->isLink()); + $this->assertDirectoryNotExists($path); + $this->assertFalse(is_link($path)); } /** @@ -189,16 +185,14 @@ public function testCopy() $this->Task->copy(); $path = WWW_ROOT . 'test_plugin'; - $dir = new \SplFileInfo($path); - $this->assertTrue($dir->isDir()); + $this->assertDirectoryExists($path); $this->assertFileExists($path . DS . 'root.js'); $folder = new Folder($path); $folder->delete(); $path = WWW_ROOT . 'company' . DS . 'test_plugin_three'; - $link = new \SplFileInfo($path); - $this->assertTrue($link->isDir()); + $this->assertDirectoryExists($path); $this->assertFileExists($path . DS . 'css' . DS . 'company.css'); $folder = new Folder(WWW_ROOT . 'company'); @@ -226,17 +220,16 @@ public function testRemoveSymlink() $this->Task->symlink(); - $link = new \SplFileInfo(WWW_ROOT . 'test_plugin'); - $this->assertTrue($link->isLink()); + $this->assertTrue(is_link(WWW_ROOT . 'test_plugin')); - $link = new \SplFileInfo(WWW_ROOT . 'company' . DS . 'test_plugin_three'); - $this->assertTrue($link->isLink()); + $path = WWW_ROOT . 'company' . DS . 'test_plugin_three'; + $this->assertTrue(is_link($path)); $this->Task->remove(); $this->assertFalse(is_link(WWW_ROOT . 'test_plugin')); - $this->assertFalse(is_link(WWW_ROOT . 'company' . DS . 'test_plugin_three')); - $this->assertTrue(is_dir(WWW_ROOT . 'company'), 'Ensure namespace folder isn\'t removed'); + $this->assertFalse(is_link($path)); + $this->assertDirectoryExists(WWW_ROOT . 'company', 'Ensure namespace folder isn\'t removed'); rmdir(WWW_ROOT . 'company'); } @@ -259,9 +252,9 @@ public function testRemoveFolder() $this->Task->remove(); - $this->assertFalse(is_dir(WWW_ROOT . 'test_plugin')); - $this->assertFalse(is_dir(WWW_ROOT . 'company' . DS . 'test_plugin_three')); - $this->assertTrue(is_dir(WWW_ROOT . 'company'), 'Ensure namespace folder isn\'t removed'); + $this->assertDirectoryNotExists(WWW_ROOT . 'test_plugin'); + $this->assertDirectoryNotExists(WWW_ROOT . 'company' . DS . 'test_plugin_three'); + $this->assertDirectoryExists(WWW_ROOT . 'company', 'Ensure namespace folder isn\'t removed'); rmdir(WWW_ROOT . 'company'); }