From 43d3f4db3f41ff735716670bd9cccd06072cb53d Mon Sep 17 00:00:00 2001 From: MarvinKlemp Date: Fri, 12 Aug 2016 17:19:46 +0200 Subject: [PATCH 1/2] Implemented directory collector --- examples/DirectoryLayer.depfile.yml | 20 ++++++++ .../Layer1/AnotherClassLikeAController.php | 28 +++++++++++ examples/Layer1/SomeClass.php | 21 +++++++++ examples/Layer1/SomeClass2.php | 21 +++++++++ examples/Layer2/SomeOtherClass.php | 21 +++++++++ examples/Layer2/SomeOtherClass2.php | 21 +++++++++ services.xml | 4 ++ src/Collector/DirectoryCollector.php | 40 ++++++++++++++++ .../Collector/DirectoryCollectorTest.php | 47 +++++++++++++++++++ 9 files changed, 223 insertions(+) create mode 100644 examples/DirectoryLayer.depfile.yml create mode 100644 examples/Layer1/AnotherClassLikeAController.php create mode 100644 examples/Layer1/SomeClass.php create mode 100644 examples/Layer1/SomeClass2.php create mode 100644 examples/Layer2/SomeOtherClass.php create mode 100644 examples/Layer2/SomeOtherClass2.php create mode 100644 src/Collector/DirectoryCollector.php create mode 100644 src/Tests/Collector/DirectoryCollectorTest.php diff --git a/examples/DirectoryLayer.depfile.yml b/examples/DirectoryLayer.depfile.yml new file mode 100644 index 000000000..4c7618089 --- /dev/null +++ b/examples/DirectoryLayer.depfile.yml @@ -0,0 +1,20 @@ +paths: ["./examples/Layer1/", "./examples/Layer2/"] +exclude_files: [] +layers: + - name: Controller + collectors: + - type: className + regex: .*Controller.* + - name: Layer1 + collectors: + - type: directory + regex: ./examples/Layer1/.* + - name: Layer2 + collectors: + - type: directory + regex: ./examples/Layer2/* +ruleset: + Controller: + - Layer1 + Layer1: + - Layer2 diff --git a/examples/Layer1/AnotherClassLikeAController.php b/examples/Layer1/AnotherClassLikeAController.php new file mode 100644 index 000000000..5d4a30c13 --- /dev/null +++ b/examples/Layer1/AnotherClassLikeAController.php @@ -0,0 +1,28 @@ +someClass = $someClass; + $this->someOtherClass = $someOtherClass; + } +} diff --git a/examples/Layer1/SomeClass.php b/examples/Layer1/SomeClass.php new file mode 100644 index 000000000..ddcac153f --- /dev/null +++ b/examples/Layer1/SomeClass.php @@ -0,0 +1,21 @@ +someOtherClass = $someOtherClass; + } +} diff --git a/examples/Layer1/SomeClass2.php b/examples/Layer1/SomeClass2.php new file mode 100644 index 000000000..1be99fcb3 --- /dev/null +++ b/examples/Layer1/SomeClass2.php @@ -0,0 +1,21 @@ +someOtherClass2 = $someOtherClass2; + } +} diff --git a/examples/Layer2/SomeOtherClass.php b/examples/Layer2/SomeOtherClass.php new file mode 100644 index 000000000..6565a8b48 --- /dev/null +++ b/examples/Layer2/SomeOtherClass.php @@ -0,0 +1,21 @@ +someClass = $someClass; + } +} diff --git a/examples/Layer2/SomeOtherClass2.php b/examples/Layer2/SomeOtherClass2.php new file mode 100644 index 000000000..afcd298a8 --- /dev/null +++ b/examples/Layer2/SomeOtherClass2.php @@ -0,0 +1,21 @@ +someClass2 = $someClass2; + } +} diff --git a/services.xml b/services.xml index f3151688f..4970685e7 100644 --- a/services.xml +++ b/services.xml @@ -47,6 +47,10 @@ + + + + diff --git a/src/Collector/DirectoryCollector.php b/src/Collector/DirectoryCollector.php new file mode 100644 index 000000000..d107bf577 --- /dev/null +++ b/src/Collector/DirectoryCollector.php @@ -0,0 +1,40 @@ +getRegexByConfiguration($configuration).'#i', + $abstractClassReference->getFileReference()->getFilepath(), + $collectorFactory + ); + } +} diff --git a/src/Tests/Collector/DirectoryCollectorTest.php b/src/Tests/Collector/DirectoryCollectorTest.php new file mode 100644 index 000000000..0d6c98092 --- /dev/null +++ b/src/Tests/Collector/DirectoryCollectorTest.php @@ -0,0 +1,47 @@ +assertEquals('directory', (new DirectoryCollector())->getType()); + } + + public function dataProviderStatisfy() + { + yield [['regex' => 'foo/layer1/.*'], 'foo/layer1/bar.php', true]; + yield [['regex' => 'foo/layer1/.*'], 'foo/layer1/dir/bar.php', true]; + yield [['regex' => 'foo/layer1/.*'], 'foo/layer2/bar.php', false]; + } + + /** + * @dataProvider dataProviderStatisfy + */ + public function testSatisfy($configuration, $filePath, $expected) + { + $fileReference = $this->prophesize(AstFileReference::class); + $fileReference->getFilepath()->willReturn($filePath); + + $astClassReference = $this->prophesize(AstClassReferenceInterface::class); + $astClassReference->getFileReference()->willReturn($fileReference->reveal()); + + $stat = (new DirectoryCollector())->satisfy( + $configuration, + $astClassReference->reveal(), + $this->prophesize(AstMap::class)->reveal(), + $this->prophesize(CollectorFactory::class)->reveal(), + $this->prophesize(AstParserInterface::class)->reveal() + ); + + $this->assertEquals($expected, $stat); + } +} From 7c811e65c097607f3b3f4de214057c72ba4cce1e Mon Sep 17 00:00:00 2001 From: MarvinKlemp Date: Fri, 12 Aug 2016 17:24:34 +0200 Subject: [PATCH 2/2] Minor fix --- examples/DirectoryLayer.depfile.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/DirectoryLayer.depfile.yml b/examples/DirectoryLayer.depfile.yml index 4c7618089..d4dedc470 100644 --- a/examples/DirectoryLayer.depfile.yml +++ b/examples/DirectoryLayer.depfile.yml @@ -12,7 +12,7 @@ layers: - name: Layer2 collectors: - type: directory - regex: ./examples/Layer2/* + regex: ./examples/Layer2/.* ruleset: Controller: - Layer1