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

Commit

Permalink
Merge branch 'hotfix/88' into develop
Browse files Browse the repository at this point in the history
Forward port #88
  • Loading branch information
weierophinney committed Apr 21, 2016
2 parents 31687bb + 9606c3b commit de5d84e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ All notable changes to this project will be documented in this file, in reverse

- [#85](https://github.com/zendframework/zend-expressive-skeleton/pull/85)
updates the Aura.Di dependency to stable 3.X versions.
- [#88](https://github.com/zendframework/zend-expressive-skeleton/pull/88)
modifies the installer to remove `composer.lock` from the `.gitignore` file
during initial installation.

## 1.0.1 - 2016-03-17

Expand Down
31 changes: 31 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,22 @@ public static function copyFile(IOInterface $io, $projectRoot, $source, $target,
copy(__DIR__ . $source, $projectRoot . $target);
}

/**
* Remove line from string content.
*
* @param string $entry Entry to remove.
* @param string $content String to remove entry from.
* @return string
*/
public static function removeLineFromString($entry, $content)
{
return preg_replace(
sprintf("/(\r?\n)%s\r?\n/s", preg_quote($entry, '/')),
'$1',
$content
);
}

/**
* Ask if the user would like a minimal install.
*
Expand Down Expand Up @@ -447,4 +464,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::removeLineFromString('composer.lock', file_get_contents($ignoreFile));
file_put_contents($ignoreFile, $content);
}
}
26 changes: 26 additions & 0 deletions test/ExpressiveInstallerTest/RemoveComposerLockTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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;
use PHPUnit_Framework_TestCase as TestCase;

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

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

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

0 comments on commit de5d84e

Please sign in to comment.