diff --git a/tests/Helpers.php b/tests/Helpers.php index f2d8f61..70c31e9 100644 --- a/tests/Helpers.php +++ b/tests/Helpers.php @@ -110,4 +110,10 @@ private function getProjectDirectory($dir) { return new \Dxw\Whippet\ProjectDirectory($dir); } + + private function getDir() + { + $root = \org\bovigo\vfs\vfsStream::setup(); + return $root->url(); + } } diff --git a/tests/dependencies/installer_test.php b/tests/dependencies/installer_test.php index 9d84eea..222e30d 100644 --- a/tests/dependencies/installer_test.php +++ b/tests/dependencies/installer_test.php @@ -2,12 +2,11 @@ class Dependencies_Installer_Test extends PHPUnit_Framework_TestCase { - use Helpers; + use \Helpers; public function testInstall() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); file_put_contents($dir.'/whippet.json', 'foobar'); file_put_contents($dir.'/whippet.lock', 'foobar'); @@ -56,8 +55,7 @@ public function testInstall() public function testInstallThemeAlreadyCloned() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); file_put_contents($dir.'/whippet.json', 'foobar'); file_put_contents($dir.'/whippet.lock', 'foobar'); @@ -93,8 +91,7 @@ public function testInstallThemeAlreadyCloned() public function testInstallMissingWhippetJson() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); $dependencies = new \Dxw\Whippet\Dependencies\Installer( $this->getFactory(), @@ -112,8 +109,7 @@ public function testInstallMissingWhippetJson() public function testInstallMissingWhippetLock() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); file_put_contents($dir.'/whippet.json', 'foobar'); $this->addFactoryCallStatic('\\Dxw\\Whippet\\Files\\WhippetLock', 'fromFile', $dir.'/whippet.lock', \Result\Result::err('file not found')); @@ -134,8 +130,7 @@ public function testInstallMissingWhippetLock() public function testInstallWrongHash() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); file_put_contents($dir.'/whippet.json', 'foobar'); file_put_contents($dir.'/whippet.lock', 'foobar'); @@ -158,8 +153,7 @@ public function testInstallWrongHash() public function testInstallCloneFails() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); file_put_contents($dir.'/whippet.json', 'foobar'); file_put_contents($dir.'/whippet.lock', 'foobar'); @@ -194,8 +188,7 @@ public function testInstallCloneFails() public function testInstallCheckoutFails() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); file_put_contents($dir.'/whippet.json', 'foobar'); file_put_contents($dir.'/whippet.lock', 'foobar'); @@ -230,8 +223,7 @@ public function testInstallCheckoutFails() public function testInstallBlankLockfile() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); file_put_contents($dir.'/whippet.json', 'foobar'); file_put_contents($dir.'/whippet.lock', 'foobar'); diff --git a/tests/dependencies/migration_test.php b/tests/dependencies/migration_test.php index bb48ccb..bf73e2d 100644 --- a/tests/dependencies/migration_test.php +++ b/tests/dependencies/migration_test.php @@ -2,7 +2,7 @@ class Dependencies_Migration_Test extends PHPUnit_Framework_TestCase { - use Helpers; + use \Helpers; private function getWhippetJsonExpectSavePath($path) { @@ -19,8 +19,7 @@ private function getWhippetJsonExpectSavePath($path) public function testMigrate() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); file_put_contents($dir.'/plugins', implode("\n", [ 'source = "git@git.dxw.net:wordpress-plugins/"', @@ -99,8 +98,7 @@ public function testMigrate() public function testMigrateDeprecatedComment() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); file_put_contents($dir.'/plugins', implode("\n", [ '#bad comment', @@ -126,8 +124,7 @@ public function testMigrateDeprecatedComment() public function testMigrateMissingSource() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); file_put_contents($dir.'/plugins', implode("\n", [ 'source=', @@ -151,8 +148,7 @@ public function testMigrateMissingSource() public function testMigrateMissingPluginsFile() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); $migration = new \Dxw\Whippet\Dependencies\Migration( $this->getFactory(), @@ -172,8 +168,7 @@ public function testMigrateMissingPluginsFile() public function testMigratePreExistingWhippetJson() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); touch($dir.'/whippet.json'); file_put_contents($dir.'/plugins', implode("\n", [ diff --git a/tests/dependencies/updater_test.php b/tests/dependencies/updater_test.php index efaf586..d1803c1 100644 --- a/tests/dependencies/updater_test.php +++ b/tests/dependencies/updater_test.php @@ -2,7 +2,7 @@ class Dependencies_Updater_Test extends PHPUnit_Framework_TestCase { - use Helpers; + use \Helpers; private function getGitignore(array $get, array $save, /* bool */ $saveIgnores, /* bool */ $warnOnGet) { @@ -62,8 +62,7 @@ private function getWhippetLockWritable(array $addDependency, /* string */ $hash public function testUpdate() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); $whippetJson = $this->getWhippetJson([ 'src' => [ @@ -117,8 +116,7 @@ public function testUpdate() public function testUpdateWithExistingGitignore() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); touch($dir.'/.gitignore'); $whippetJson = $this->getWhippetJson([ @@ -170,8 +168,7 @@ public function testUpdateWithExistingGitignore() public function testUpdateWithExistingGitignoreNoDuplication() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); touch($dir.'/.gitignore'); $whippetJson = $this->getWhippetJson([ @@ -224,8 +221,7 @@ public function testUpdateWithExistingGitignoreNoDuplication() public function testUpdateFailedGitCommand() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); $whippetJson = $this->getWhippetJson([ 'src' => [ @@ -268,8 +264,7 @@ public function testUpdateFailedGitCommand() public function testUpdateWithExplicitSrc() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); $whippetJson = $this->getWhippetJson([ 'src' => [ @@ -314,8 +309,7 @@ public function testUpdateWithExplicitSrc() public function testUpdateWithoutRef() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); $whippetJson = $this->getWhippetJson([ 'src' => [ @@ -358,8 +352,7 @@ public function testUpdateWithoutRef() public function testUpdateBlankJsonfile() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); $whippetJson = $this->getWhippetJson([]); $this->addFactoryCallStatic('\\Dxw\\Whippet\\Files\\WhippetJson', 'fromFile', $dir.'/whippet.json', \Result\Result::ok($whippetJson)); @@ -387,8 +380,7 @@ public function testUpdateBlankJsonfile() public function testUpdateNoGitignore() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); $whippetJson = $this->getWhippetJson([ 'src' => [ @@ -442,8 +434,7 @@ public function testUpdateNoGitignore() public function testUpdateRemoveFromGitignore() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); touch($dir.'/.gitignore'); $whippetJson = $this->getWhippetJson([ @@ -499,8 +490,7 @@ public function testUpdateRemoveFromGitignore() public function testUpdateBubbleErrors() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); $this->addFactoryCallStatic('\\Dxw\\Whippet\\Files\\WhippetJson', 'fromFile', $dir.'/whippet.json', \Result\Result::err('a WhippetJson error')); @@ -520,8 +510,7 @@ public function testUpdateBubbleErrors() public function testUpdateNoExistingWhippetLock() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); $whippetJson = $this->getWhippetJson([ 'src' => [ @@ -576,8 +565,7 @@ public function testUpdateNoExistingWhippetLock() public function testUpdateWithBrokenJson() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); $whippetJson = $this->getWhippetJson([ 'src' => [ diff --git a/tests/files/whippet_json_test.php b/tests/files/whippet_json_test.php index 45870bd..715ba65 100644 --- a/tests/files/whippet_json_test.php +++ b/tests/files/whippet_json_test.php @@ -2,6 +2,8 @@ class Files_WhippetJson_Test extends PHPUnit_Framework_TestCase { + use \Helpers; + public function testGetDependenciesPlugins() { $whippetJson = new \Dxw\Whippet\Files\WhippetJson([ diff --git a/tests/files/whippet_lock_test.php b/tests/files/whippet_lock_test.php index 0b78f41..62180f9 100644 --- a/tests/files/whippet_lock_test.php +++ b/tests/files/whippet_lock_test.php @@ -2,6 +2,8 @@ class Files_WhippetLock_Test extends PHPUnit_Framework_TestCase { + use \Helpers; + public function testGetDependencies() { $whippetLock = new \Dxw\Whippet\Files\WhippetLock([ @@ -47,8 +49,7 @@ public function testFromStringGetDependencies() public function testFromFileGetDependencies() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); file_put_contents($dir.'/whippet.lock', json_encode([ 'themes' => [ @@ -115,8 +116,7 @@ public function testAddDependency() public function testSaveToPath() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); $data = [ 'foo' => 'bar', @@ -132,8 +132,7 @@ public function testSaveToPath() public function testSaveToPathPrettyPrinting() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); $data = [ 'foo' => '/', @@ -162,8 +161,7 @@ public function testFromStringInvalid() public function testFromFileNotFound() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); $output = \Dxw\Whippet\Files\WhippetLock::fromFile($dir.'/file-not-found.json'); diff --git a/tests/project_directory_test.php b/tests/project_directory_test.php index a771274..6a52e14 100644 --- a/tests/project_directory_test.php +++ b/tests/project_directory_test.php @@ -2,10 +2,11 @@ class ProjectDirectory_Test extends PHPUnit_Framework_TestCase { + use \Helpers; + public function testGetDirectorySuccess1() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); mkdir($dir.'/wp-content/themes/my-theme'); touch($dir.'/whippet.json'); @@ -25,8 +26,7 @@ public function testGetDirectorySuccess1() public function testGetDirectorySuccess2() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); mkdir($dir.'/projects'); mkdir($dir.'/projects/project1'); @@ -51,8 +51,7 @@ public function testGetDirectorySuccess2() public function testGetDirectoryFailure() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); mkdir($dir.'/projects'); mkdir($dir.'/projects/project1'); @@ -76,8 +75,7 @@ public function testGetDirectoryFailure() public function testGetDirectoryWhippetJson() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); mkdir($dir.'/wp-content/themes/my-theme'); touch($dir.'/whippet.json'); @@ -97,8 +95,7 @@ public function testGetDirectoryWhippetJson() public function testGetDirectoryAvoidPluginsDirectory() { - $root = \org\bovigo\vfs\vfsStream::setup(); - $dir = $root->url(); + $dir = $this->getDir(); mkdir($dir.'/wp-content'); mkdir($dir.'/wp-content/plugins');