Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dist file support #135

Merged
merged 7 commits into from
Apr 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ bin
!bin/grumphp
vendor
composer.lock
grumphp.yml
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,16 @@ Having trouble installing GrumPHP? Find out how to:

## Configuration

Some things in GrumPHP can be configured in a `grumphp.yml` or `grumphp.yml.dist` file in the root of your project (the directory where you run the grumphp command).
You can specify a custom config filename and location in `composer.json` or in the `--config` option of the console commands.

```yaml
# grumphp.yml
parameters:
bin_dir: "./vendor/bin"
git_dir: "."
stop_on_failure: false
ignore_unstaged_changes: true
ignore_unstaged_changes: false
ascii:
failed: grumphp-grumpy.txt
succeeded: grumphp-happy.txt
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"require": {
"php": ">=5.3.6",
"composer-plugin-api": "~1.0",
"composer/composer": "^1.0-beta2",
"doctrine/collections": "~1.2",
"gitonomy/gitlib": "~0.1.7",
"seld/jsonlint": "~1.1",
Expand All @@ -21,8 +22,8 @@
"monolog/monolog": "~1.17"
},
"require-dev": {
"composer/composer": "^1.0-alpha11",
"phpspec/phpspec": "~2.4",
"phpspec/phpspec": "~2.5",
"phpspec/prophecy": "~1.6",
"squizlabs/php_codesniffer": "~2.3",
"fabpot/php-cs-fixer": "~1.0",
"phpunit/phpunit": "^4.8",
Expand Down
5 changes: 3 additions & 2 deletions doc/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ parameters:
bin_dir: ./vendor/bin
git_dir: .
stop_on_failure: false
ignore_unstaged_changes: true
ignore_unstaged_changes: false
ascii:
failed: resource/grumphp-grumpy.txt
succeeded: resource/grumphp-happy.txt
Expand Down Expand Up @@ -35,11 +35,12 @@ By default GrumPHP will continue running the configured tasks.

**ignore_unstaged_changes**

*Default: true*
*Default: false*

By enabling this option, GrumPHP will stash your unstaged changes in git before running the tasks.
This way the tasks will run with the code that is actually committed without the unstaged changes.
Note that during the commit, the unstaged changes will be stored in git stash.
This may mess with your working copy and result in unexpected merge conflicts.

**ascii**

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion resources/config/parameters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ parameters:
git_dir: .
tasks: []
stop_on_failure: false
ignore_unstaged_changes: true
ignore_unstaged_changes: false
extensions: []
ascii:
failed: grumphp-grumpy.txt
Expand Down
5 changes: 5 additions & 0 deletions resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ services:
- '%bin_dir%'
- '@executable_finder'

locator.configuration_file:
class: GrumPHP\Locator\ConfigurationFile
arguments:
- '@filesystem'

locator.changed_files:
class: GrumPHP\Locator\ChangedFiles
arguments:
Expand Down
3 changes: 3 additions & 0 deletions resources/config/util.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
services:
grumphp.util.composer:
class: GrumPHP\Util\Composer
48 changes: 48 additions & 0 deletions spec/GrumPHP/Console/Helper/ComposerHelperSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace spec\GrumPHP\Console\Helper;

use Composer\Config;
use Composer\Package\RootPackage;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class ComposerHelperSpec extends ObjectBehavior
{

function let(Config $config, RootPackage $rootPackage)
{
$this->beConstructedWith($config, $rootPackage);
}

function it_is_initializable()
{
$this->shouldHaveType('GrumPHP\Console\Helper\ComposerHelper');
}

function it_is_a_console_helper()
{
$this->shouldHaveType('Symfony\Component\Console\Helper\Helper');
}

function it_knows_if_the_composer_configuration_is_available()
{
$this->hasConfiguration()->shouldBe(true);
}

function it_has_composer_configuration(Config $config)
{
$this->getConfiguration()->shouldBe($config);
}

function it_knows_if_the_composer_root_package_is_available()
{
$this->hasRootPackage()->shouldBe(true);
}

function it_has_composer_root_package(RootPackage $rootPackage)
{
$this->getRootPackage()->shouldBe($rootPackage);
}

}
12 changes: 11 additions & 1 deletion spec/GrumPHP/Console/Helper/PathsHelperSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,22 @@ class PathsHelperSpec extends ObjectBehavior
{
function let(GrumPHP $config, Filesystem $fileSystem)
{
$this->beConstructedWith($config, $fileSystem);
$this->beConstructedWith($config, $fileSystem, '/grumphp.yml');
}

function it_is_a_console_helper()
{
$this->shouldHaveType('Symfony\Component\Console\Helper\Helper');
}

function it_throws_exception_during_get_relative_path_when_file_is_not_found()
{
$path = '/non/existent/path/config.yml';
$this->shouldThrow('GrumPHP\Exception\FileNotFoundException')->duringGetRelativePath($path);
}

function it_knows_the_default_configuration_file()
{
$this->getDefaultConfigPath()->shouldBe('/grumphp.yml');
}
}
5 changes: 5 additions & 0 deletions spec/GrumPHP/Console/Helper/TaskRunnerHelperSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ function let(TaskRunner $taskRunner, EventDispatcherInterface $eventDispatcher,
$this->setHelperSet($helperSet);
}

function it_is_a_console_helper()
{
$this->shouldHaveType('Symfony\Component\Console\Helper\Helper');
}

function it_should_return_error_code_during_exceptions(OutputInterface $output, TaskRunner $taskRunner, ContextInterface $context)
{
$taskRunner->run($context)->willThrow(new FailureException());
Expand Down
108 changes: 108 additions & 0 deletions spec/GrumPHP/Locator/ConfigurationFileSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php

namespace spec\GrumPHP\Locator;

use Composer\Package\PackageInterface;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Symfony\Component\Filesystem\Filesystem;

class ConfigurationFileSpec extends ObjectBehavior
{
function let(Filesystem $filesystem)
{
$this->beConstructedWith($filesystem);
}

function it_is_initializable()
{
$this->shouldHaveType('GrumPHP\Locator\ConfigurationFile');
}

function it_should_locate_config_file(Filesystem $filesystem)
{
$filesystem->exists($this->pathArgument('/composer/grumphp.yml'))->willReturn(true);
$filesystem->isAbsolutePath($this->pathArgument('/composer/grumphp.yml'))->willReturn(true);

$this->locate('/composer', null)->shouldMatch($this->pathRegex('/composer/grumphp.yml'));
}

function it_should_fall_back_on_dist_file(Filesystem $filesystem)
{
$filesystem->exists($this->pathArgument('/composer/grumphp.yml'))->willReturn(false);
$filesystem->exists($this->pathArgument('/composer/grumphp.yml.dist'))->willReturn(true);
$filesystem->isAbsolutePath($this->pathArgument('/composer/grumphp.yml.dist'))->willReturn(true);

$this->locate('/composer', null)->shouldMatch($this->pathRegex('/composer/grumphp.yml.dist'));
}

function it_should_use_the_config_file_configured_in_the_composer_file(Filesystem $filesystem, PackageInterface $package)
{
$package->getExtra()->willReturn(array(
'grumphp' => array(
'config-default-path' => '/composer/exotic/path/grumphp.yml'
)
));

$filesystem->exists($this->pathArgument('/composer/grumphp.yml'))->willReturn(true);
$filesystem->exists('/composer/exotic/path/grumphp.yml')->willReturn(true);
$filesystem->isAbsolutePath('/composer/exotic/path/grumphp.yml')->willReturn(true);

$this->locate('/composer', $package)->shouldBe('/composer/exotic/path/grumphp.yml');
}

function it_should_use_the_config_file_configured_in_the_composer_file_and_fall_back_on_dist(Filesystem $filesystem, PackageInterface $package)
{
$package->getExtra()->willReturn(array(
'grumphp' => array(
'config-default-path' => '/composer/exotic/path/grumphp.yml'
)
));

$filesystem->exists($this->pathArgument('/composer/grumphp.yml'))->willReturn(true);
$filesystem->exists('/composer/exotic/path/grumphp.yml')->willReturn(false);
$filesystem->exists('/composer/exotic/path/grumphp.yml.dist')->willReturn(true);
$filesystem->isAbsolutePath('/composer/exotic/path/grumphp.yml.dist')->willReturn(true);

$this->locate('/composer', $package)->shouldBe('/composer/exotic/path/grumphp.yml.dist');
}

function it_should_always_return_absolute_paths(Filesystem $filesystem, PackageInterface $package)
{
$package->getExtra()->willReturn(array(
'grumphp' => array(
'config-default-path' => 'exotic/path/grumphp.yml'
)
));

$filesystem->exists($this->pathArgument('/composer/grumphp.yml'))->willReturn(true);
$filesystem->exists($this->pathArgument('exotic/path/grumphp.yml'))->willReturn(true);
$filesystem->isAbsolutePath($this->pathArgument('exotic/path/grumphp.yml'))->willReturn(false);

$this->locate('/composer', $package)->shouldMatch($this->pathRegex('/composer/exotic/path/grumphp.yml'));
}

function it_should_locate_config_file_on_empty_composer_configuration(Filesystem $filesystem, PackageInterface $package)
{
$package->getExtra()->willReturn(array());

$filesystem->exists($this->pathArgument('/composer/grumphp.yml'))->willReturn(true);
$filesystem->isAbsolutePath($this->pathArgument('/composer/grumphp.yml'))->willReturn(true);

$this->locate('/composer', $package)->shouldMatch($this->pathRegex('/composer/grumphp.yml'));
}

private function pathRegex($expected)
{
return '#^' . str_replace(array('.', '/'), array('\.', '[\\\/]{1}'), $expected) . '$#i';
}

private function pathArgument($expected)
{
$regex = $this->pathRegex($expected);

return Argument::that(function($path) use ($regex) {
return preg_match($regex, $path);
});
}
}
1 change: 1 addition & 0 deletions src/GrumPHP/Configuration/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static function buildFromConfiguration($path)
$loader->load('services.yml');
$loader->load('subscribers.yml');
$loader->load('tasks.yml');
$loader->load('util.yml');

// Load grumphp.yml file:
$filesystem = new Filesystem();
Expand Down
Loading