Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Merge pull request #88 from jonsa/feature/remove-composer-lock-from-g…
Browse files Browse the repository at this point in the history
…itignore

Added installer option to remove composer.lock file from .gitignore file
  • Loading branch information
weierophinney committed Apr 21, 2016
2 parents b7fdaf8 + e31c53f commit 20b7377
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/ExpressiveInstaller/OptionalPackages.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public static function install(Event $event)
self::removeDefaultMiddleware($io, $projectRoot);
}

self::clearComposerLockFile($io, $projectRoot);
self::cleanUp($io, $projectRoot);
}

Expand Down Expand Up @@ -383,6 +384,20 @@ public static function copyFile(IOInterface $io, $projectRoot, $source, $target,
copy(__DIR__ . $source, $projectRoot . $target);
}

/**
* Remove line from content.
*
* @param string $entry Entry to remove.
* @param string $content String to remove entry from.
* @return string
*/
public static function removeLine($entry, $content)
{
$entry = preg_quote($entry, '/');

return preg_replace("/$entry\\W*/", '', $content);
}

/**
* Ask if the user would like a minimal install.
*
Expand Down Expand Up @@ -447,4 +462,18 @@ private static function recursiveRmdir($directory)
}
rmdir($directory);
}

/**
* @param IOInterface $io
* @param string $projectRoot
*/
private static function clearComposerLockFile($io, $projectRoot)
{
$io->write("<info>Removing composer.lock from .gitignore</info>");

$ignoreFile = "$projectRoot/.gitignore";

$content = self::removeLine('composer.lock', file_get_contents($ignoreFile));
file_put_contents($ignoreFile, $content);
}
}
25 changes: 25 additions & 0 deletions test/ExpressiveInstallerTest/RemoveComposerLockTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @see https://github.com/zendframework/zend-expressive-skeleton for the canonical source repository
* @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-expressive-skeleton/blob/master/LICENSE.md New BSD License
*/

namespace ExpressiveInstallerTest;

use ExpressiveInstaller\OptionalPackages;

class RemoveComposerLockTest extends \PHPUnit_Framework_TestCase
{
public function testRemoveLine()
{
$string = "foo\nbar\nbaz";

$actual = OptionalPackages::removeLine('bar', $string);
$expected = "foo\nbaz";

$this->assertEquals($expected, $actual);
}
}

0 comments on commit 20b7377

Please sign in to comment.