Skip to content

Commit

Permalink
DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
mallorydxw committed Apr 7, 2016
1 parent f62d346 commit d7f40d0
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 71 deletions.
6 changes: 6 additions & 0 deletions tests/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
26 changes: 9 additions & 17 deletions tests/dependencies/installer_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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(),
Expand All @@ -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'));
Expand All @@ -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');

Expand All @@ -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');

Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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');

Expand Down
17 changes: 6 additions & 11 deletions tests/dependencies/migration_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Dependencies_Migration_Test extends PHPUnit_Framework_TestCase
{
use Helpers;
use \Helpers;

private function getWhippetJsonExpectSavePath($path)
{
Expand All @@ -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/"',
Expand Down Expand Up @@ -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',
Expand All @@ -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=',
Expand All @@ -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(),
Expand All @@ -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", [
Expand Down
38 changes: 13 additions & 25 deletions tests/dependencies/updater_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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' => [
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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' => [
Expand Down Expand Up @@ -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' => [
Expand Down Expand Up @@ -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' => [
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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' => [
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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'));

Expand All @@ -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' => [
Expand Down Expand Up @@ -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' => [
Expand Down
2 changes: 2 additions & 0 deletions tests/files/whippet_json_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

class Files_WhippetJson_Test extends PHPUnit_Framework_TestCase
{
use \Helpers;

public function testGetDependenciesPlugins()
{
$whippetJson = new \Dxw\Whippet\Files\WhippetJson([
Expand Down
14 changes: 6 additions & 8 deletions tests/files/whippet_lock_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

class Files_WhippetLock_Test extends PHPUnit_Framework_TestCase
{
use \Helpers;

public function testGetDependencies()
{
$whippetLock = new \Dxw\Whippet\Files\WhippetLock([
Expand Down Expand Up @@ -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' => [
Expand Down Expand Up @@ -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',
Expand All @@ -132,8 +132,7 @@ public function testSaveToPath()

public function testSaveToPathPrettyPrinting()
{
$root = \org\bovigo\vfs\vfsStream::setup();
$dir = $root->url();
$dir = $this->getDir();

$data = [
'foo' => '/',
Expand Down Expand Up @@ -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');

Expand Down
17 changes: 7 additions & 10 deletions tests/project_directory_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand Down

0 comments on commit d7f40d0

Please sign in to comment.