Skip to content

Commit

Permalink
Issue #2: Fix parser and test.
Browse files Browse the repository at this point in the history
  • Loading branch information
ademarco committed Dec 24, 2017
1 parent 626a755 commit 3aa1c2b
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ phpunit.xml
composer.lock
behat.yml
RoboFile.php
/tests/sandbox/*.yml
/tests/sandbox/*
4 changes: 2 additions & 2 deletions src/Commands/SetupCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function setupBehat(array $options = [
'destination' => InputOption::VALUE_REQUIRED,
])
{
return $this->taskReplaceConfigTokens($options['source'], $options['destination']);
return $this->setupReplace($options);
}

/**
Expand Down Expand Up @@ -75,7 +75,7 @@ public function setupPhpunit(array $options = [
'destination' => InputOption::VALUE_REQUIRED,
])
{
return $this->taskReplaceConfigTokens($options['source'], $options['destination']);
return $this->setupReplace($options);
}


Expand Down
2 changes: 1 addition & 1 deletion src/Tasks/ReplaceConfigTokens/ReplaceConfigTokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ReplaceConfigTokens extends BaseTask implements BuilderAwareInterface
{
use BuilderAwareTrait;

const TOKEN_REGEX = '/\$\{((\w+\.?)+)\}/';
const TOKEN_REGEX = '/\$\{(([A-Za-z_\-]+\.?)+)\}/';

/**
* Source file.
Expand Down
38 changes: 34 additions & 4 deletions tests/CommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class CommandsTest extends AbstractTest
* @param array $config
* @param array $expected
*
* @dataProvider commandsDataProvider
* @dataProvider simulationDataProvider
*/
public function testSiteInstall($command, array $config, array $expected)
public function testSimulation($command, array $config, array $expected)
{
$configFile = $this->getSandboxPath('runner.test.yml');
file_put_contents($configFile, Yaml::dump($config));
Expand All @@ -39,11 +39,41 @@ public function testSiteInstall($command, array $config, array $expected)
}
}

/**
* @param string $command
* @param string $content
* @param string $expected
*
* @dataProvider setupDataProvider
*/
public function testSetupCommands($command, $content, $expected)
{
$source = $this->getSandboxPath('source.yml');
$destination = $this->getSandboxPath('destination.yml');
file_put_contents($source, $content);

$input = new StringInput("{$command} --source={$source} --destination={$destination}");
$output = new BufferedOutput();
$runner = new TaskRunner([], $input, $output);
$runner->run();

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

/**
* @return array
*/
public function simulationDataProvider()
{
return $this->getFixtureContent('simulation.yml');
}

/**
* @return array
*/
public function commandsDataProvider()
public function setupDataProvider()
{
return $this->getFixtureContent('commands.yml');
return $this->getFixtureContent('setup.yml');
}
}
39 changes: 39 additions & 0 deletions tests/fixtures/setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
- command: setup:replace
content: >
test1: ${drupal.root}
test2: ${drupal.core}
expected: >
test1: build
test2: 8
- command: setup:behat
content: >
default:
extensions:
Behat\MinkExtension:
base_url: ${drupal.base-url}
formatters:
progress: ~
expected: >
default:
extensions:
Behat\MinkExtension:
base_url: http://127.0.0.1:8888
formatters:
progress: ~
- command: setup:phpunit
content: >
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php">
<php>
<env name="BASE_URL" value="${drupal.base-url}"/>
</php>
</phpunit>
expected: >
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php">
<php>
<env name="BASE_URL" value="http://127.0.0.1:8888"/>
</php>
</phpunit>
File renamed without changes.
7 changes: 7 additions & 0 deletions tests/fixtures/tasks/replace-config-tokens/extract.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@
expected:
'${token.four}': 'token.four'

-
text: >
<php>
<env name="BASE_URL" value="${drupal.base-url}"/>
</php>
expected:
'${drupal.base-url}': 'drupal.base-url'

0 comments on commit 3aa1c2b

Please sign in to comment.