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

Commit de5d84e

Browse files
committed
Merge branch 'hotfix/88' into develop
Forward port #88
2 parents 31687bb + 9606c3b commit de5d84e

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ All notable changes to this project will be documented in this file, in reverse
3838

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

4245
## 1.0.1 - 2016-03-17
4346

src/ExpressiveInstaller/OptionalPackages.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ public static function install(Event $event)
210210
self::removeDefaultMiddleware($io, $projectRoot);
211211
}
212212

213+
self::clearComposerLockFile($io, $projectRoot);
213214
self::cleanUp($io, $projectRoot);
214215
}
215216

@@ -383,6 +384,22 @@ public static function copyFile(IOInterface $io, $projectRoot, $source, $target,
383384
copy(__DIR__ . $source, $projectRoot . $target);
384385
}
385386

387+
/**
388+
* Remove line from string content.
389+
*
390+
* @param string $entry Entry to remove.
391+
* @param string $content String to remove entry from.
392+
* @return string
393+
*/
394+
public static function removeLineFromString($entry, $content)
395+
{
396+
return preg_replace(
397+
sprintf("/(\r?\n)%s\r?\n/s", preg_quote($entry, '/')),
398+
'$1',
399+
$content
400+
);
401+
}
402+
386403
/**
387404
* Ask if the user would like a minimal install.
388405
*
@@ -447,4 +464,18 @@ private static function recursiveRmdir($directory)
447464
}
448465
rmdir($directory);
449466
}
467+
468+
/**
469+
* @param IOInterface $io
470+
* @param string $projectRoot
471+
*/
472+
private static function clearComposerLockFile($io, $projectRoot)
473+
{
474+
$io->write("<info>Removing composer.lock from .gitignore</info>");
475+
476+
$ignoreFile = "$projectRoot/.gitignore";
477+
478+
$content = self::removeLineFromString('composer.lock', file_get_contents($ignoreFile));
479+
file_put_contents($ignoreFile, $content);
480+
}
450481
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @see https://github.com/zendframework/zend-expressive-skeleton for the canonical source repository
6+
* @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license https://github.com/zendframework/zend-expressive-skeleton/blob/master/LICENSE.md New BSD License
8+
*/
9+
10+
namespace ExpressiveInstallerTest;
11+
12+
use ExpressiveInstaller\OptionalPackages;
13+
use PHPUnit_Framework_TestCase as TestCase;
14+
15+
class RemoveComposerLockTest extends TestCase
16+
{
17+
public function testRemoveLineFromString()
18+
{
19+
$string = "foo\nbar\nbaz";
20+
21+
$actual = OptionalPackages::removeLineFromString('bar', $string);
22+
$expected = "foo\nbaz";
23+
24+
$this->assertEquals($expected, $actual);
25+
}
26+
}

0 commit comments

Comments
 (0)