From 1e96989b99b108356ef349ce3a40f8681b71e925 Mon Sep 17 00:00:00 2001 From: Christopher Joe Date: Tue, 21 Nov 2017 12:33:57 +1300 Subject: [PATCH 1/2] BUG Fix parameter order --- src/Transformer/YamlTransformer.php | 3 ++- tests/Transformer/YamlTransformerTest.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Transformer/YamlTransformer.php b/src/Transformer/YamlTransformer.php index 51ddaf5..8898216 100644 --- a/src/Transformer/YamlTransformer.php +++ b/src/Transformer/YamlTransformer.php @@ -428,7 +428,7 @@ function ($document) use ($flag) { // and check their filename and maybe their document name, depending on the pattern. // We don't want to do any pattern matching after the first hash as the document name // is assumed to follow it. - $firstHash = strpos('#', $pattern); + $firstHash = strpos($pattern, '#'); $documentName = false; if ($firstHash !== false) { $documentName = substr($pattern, $firstHash + 1); @@ -445,6 +445,7 @@ function ($part) { explode('*', $pattern) ) ).'%'; + $matchedDocuments = []; foreach ($documents as $document) { // Ensure filename is relative diff --git a/tests/Transformer/YamlTransformerTest.php b/tests/Transformer/YamlTransformerTest.php index a9857f8..657e79a 100644 --- a/tests/Transformer/YamlTransformerTest.php +++ b/tests/Transformer/YamlTransformerTest.php @@ -273,7 +273,7 @@ public function testBeforeAfterStatementWithPath() $content = <<<'YAML' --- name: test2 -before: 'test/*' +before: 'test/*#test' --- test: 'should not overwrite' YAML; @@ -289,6 +289,7 @@ public function testBeforeAfterStatementWithPath() $this->assertEquals('test', $collection->get('test')); + // this one is kind of moot because if the matching fails, it'll go after anyway... $content = <<<'YAML' --- name: test3 From 14b2641d0e10641817c15f1cda183b046fb86232 Mon Sep 17 00:00:00 2001 From: Christopher Joe Date: Tue, 21 Nov 2017 16:08:05 +1300 Subject: [PATCH 2/2] BUG Fix added module fluid-prefix so module config will not require the full path to match --- src/Transformer/YamlTransformer.php | 2 +- tests/Transformer/YamlTransformerTest.php | 51 +++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/Transformer/YamlTransformer.php b/src/Transformer/YamlTransformer.php index 8898216..1ae4bd9 100644 --- a/src/Transformer/YamlTransformer.php +++ b/src/Transformer/YamlTransformer.php @@ -436,7 +436,7 @@ function ($document) use ($flag) { } // Replace all `*` with `[^\.][a-zA-Z0-9\-_\/\.]+`, and quote other characters - $patternRegExp = '%^'.implode( + $patternRegExp = '%(^|[/\\\\])'.implode( '[^\.][a-zA-Z0-9\-_\/\.]+', array_map( function ($part) { diff --git a/tests/Transformer/YamlTransformerTest.php b/tests/Transformer/YamlTransformerTest.php index 657e79a..b7be485 100644 --- a/tests/Transformer/YamlTransformerTest.php +++ b/tests/Transformer/YamlTransformerTest.php @@ -309,6 +309,57 @@ public function testBeforeAfterStatementWithPath() $this->assertEquals('overwrite', $collection->get('test')); } + public function testBeforeAfterStatementWithNestedPath() + { + $content = <<<'YAML' +--- +name: test +--- +test: 'test' +YAML; + mkdir($this->getConfigDirectory().'/test'); + mkdir($this->getConfigDirectory().'/test/test1-1'); + file_put_contents($this->getFilePath('test/test1-1/config.yml'), $content); + + $content = <<<'YAML' +--- +name: test2 +before: 'test1-1/*#test' +--- +test: 'should not overwrite' +YAML; + mkdir($this->getConfigDirectory().'/test2'); + file_put_contents($this->getFilePath('test2/config.yml'), $content); + + $collection = new MemoryConfigCollection; + $transformer = new YamlTransformer( + $this->getConfigDirectory(), + $this->getFinder() + ); + $collection->transform([$transformer]); + + $this->assertEquals('test', $collection->get('test')); + + $content = <<<'YAML' +--- +name: test3 +after: 'test1-1/*#test' +--- +test: 'overwrite' +YAML; + file_put_contents($this->getFilePath('test2/config.yml'), $content); + + $collection = new MemoryConfigCollection; + $transformer = new YamlTransformer( + $this->getConfigDirectory(), + $this->getFinder() + ); + $collection->transform([$transformer]); + + $this->assertEquals('overwrite', $collection->get('test')); + + } + /** * Tests that an exception is correctly thrown when a circular dependency is present. * This means when two YAML documents are stated as both becoming before (or after)