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

Add an option to disable parameter handler in composer production mode #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ public function __construct(IOInterface $io)
$this->io = $io;
}

public function processFile(array $config)
public function processFile(array $config, $devMode = true)
{
$config = $this->processConfig($config);

$realFile = $config['file'];
$parameterKey = $config['parameter-key'];

if ($devMode !== true && !empty($config['dev-only']) && true === $config['dev-only']) {
$this->io->write(sprintf('<info>Skipping the "%s" file</info>', $realFile));
return;
}

$exists = is_file($realFile);

$yamlParser = new Parser();
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,24 @@ If the old parameter is no longer present (maybe because it has been renamed and
removed already), no parameters are overwritten. You don't need to remove obsolete
parameters from the rename map once they have been renamed.

### Skipping file in production mode

You can enable the parameter handler only in development mode:

```json
{
"extra": {
"incenteev-parameters": {
"dev-only": true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does does not correspond to the implementation.

}
}
}

```

Doing that, calling composer with `--no-dev` flag will disable the parameter
handler.

### Managing multiple ignored files

The parameter handler can manage multiple ignored files. To use this feature,
Expand Down
2 changes: 1 addition & 1 deletion ScriptHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static function buildParameters(Event $event)
throw new \InvalidArgumentException('The extra.incenteev-parameters setting must be an array of configuration objects.');
}

$processor->processFile($config);
$processor->processFile($config, $event->isDevMode());
}
}
}
30 changes: 30 additions & 0 deletions Tests/ProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,34 @@ public function provideParameterHandlingTestCases()

return $tests;
}

public function testNoDev()
{
$dataDir = __DIR__.'/fixtures/dev_only';

$testCase = array_replace_recursive(
array(
'title' => 'unknown test',
'config' => array(
'file' => 'parameters.yml',
),
'dist-file' => 'parameters.yml.dist',
'environment' => array(),
'interactive' => false,
),
(array) Yaml::parse(file_get_contents($dataDir.'/setup.yml'))
);

$workingDir = sys_get_temp_dir() . '/incenteev_parameter_handler';
$this->initializeTestCase($testCase, $dataDir, $workingDir);

$message = sprintf('<info>Skipping the "%s" file</info>', $testCase['config']['file']);
$this->io->write($message)->shouldBeCalled();

$this->setInteractionExpectations($testCase);

$this->processor->processFile($testCase['config'], false);

$this->assertFileEquals($dataDir.'/expected.yml', $workingDir.'/'.$testCase['config']['file'], $testCase['title']);
}
}
1 change: 1 addition & 0 deletions Tests/ScriptHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ protected function setUp()
$composer->getPackage()->willReturn($this->package);
$this->event->getComposer()->willReturn($composer);
$this->event->getIO()->willReturn($this->io);
$this->event->isDevMode()->willReturn(true);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions Tests/fixtures/dev_only/dist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
parameters:
foo: bar
foo2: bar2
3 changes: 3 additions & 0 deletions Tests/fixtures/dev_only/existing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This file is auto-generated during the composer install
parameters:
foo: bar
3 changes: 3 additions & 0 deletions Tests/fixtures/dev_only/expected.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This file is auto-generated during the composer install
parameters:
foo: bar
4 changes: 4 additions & 0 deletions Tests/fixtures/dev_only/setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
title: Skip file in production mode

config:
dev-only: true