From 35b955752dceef63c8adc3f403101d200e82105e Mon Sep 17 00:00:00 2001 From: michaelbausor Date: Fri, 2 Mar 2018 11:01:08 -0800 Subject: [PATCH] Update Core with changes to support restructure (#922) * Add exclude filter * update scanner, add fixture * Fix travis errors * Fix snippet test --- .../Snippet/Coverage/ExcludeFilter.php | 55 +++++++++++++++++++ src/Core/Testing/Snippet/Coverage/Scanner.php | 29 ++++++---- src/Core/Testing/Snippet/Fixtures.php | 32 +++++++++++ src/Core/Testing/Snippet/Parser/Parser.php | 5 +- src/Core/Testing/Snippet/keyfile-stub.json | 12 ++++ tests/snippets/Vision/Annotation/FaceTest.php | 2 +- 6 files changed, 121 insertions(+), 14 deletions(-) create mode 100644 src/Core/Testing/Snippet/Coverage/ExcludeFilter.php create mode 100644 src/Core/Testing/Snippet/Fixtures.php create mode 100644 src/Core/Testing/Snippet/keyfile-stub.json diff --git a/src/Core/Testing/Snippet/Coverage/ExcludeFilter.php b/src/Core/Testing/Snippet/Coverage/ExcludeFilter.php new file mode 100644 index 000000000000..da9a254f4dc4 --- /dev/null +++ b/src/Core/Testing/Snippet/Coverage/ExcludeFilter.php @@ -0,0 +1,55 @@ +excludeDirs = $excludeDirs; + } + + /** + * @return bool + */ + public function accept() + { + // Accept the current item if we can recurse into it + // or it is a value starting with "test" + foreach ($this->excludeDirs as $excludeDir) { + if (strpos($this->current(), $excludeDir) !== false) { + return false; + } + } + return true; + } +} diff --git a/src/Core/Testing/Snippet/Coverage/Scanner.php b/src/Core/Testing/Snippet/Coverage/Scanner.php index 285e15162487..26c6724846fd 100644 --- a/src/Core/Testing/Snippet/Coverage/Scanner.php +++ b/src/Core/Testing/Snippet/Coverage/Scanner.php @@ -35,13 +35,13 @@ class Scanner implements ScannerInterface protected $parser; /** - * @var string + * @var array */ private $basePath; /** * @param Parser $parser An instance of the Snippet Parser. - * @param string $basepath The path to scan for PHP files. + * @param \Iterator|string $basepath The path(s) to scan for PHP files. * * @experimental * @internal @@ -49,6 +49,9 @@ class Scanner implements ScannerInterface public function __construct(Parser $parser, $basePath) { $this->parser = $parser; + if (is_string($basePath)) { + $basePath = [$basePath]; + } $this->basePath = $basePath; } @@ -62,17 +65,19 @@ public function __construct(Parser $parser, $basePath) */ public function files() { - $regexIterator = new \RegexIterator( - new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($this->basePath) - ), - '/^.+\.php$/i', - \RecursiveRegexIterator::GET_MATCH - ); - $files = []; - foreach ($regexIterator as $item) { - array_push($files, $item[0]); + foreach ($this->basePath as $basePath) { + $regexIterator = new \RegexIterator( + new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator($basePath) + ), + '/^.+\.php$/i', + \RecursiveRegexIterator::GET_MATCH + ); + + foreach ($regexIterator as $item) { + array_push($files, $item[0]); + } } return $files; diff --git a/src/Core/Testing/Snippet/Fixtures.php b/src/Core/Testing/Snippet/Fixtures.php new file mode 100644 index 000000000000..cbf7132bce2e --- /dev/null +++ b/src/Core/Testing/Snippet/Fixtures.php @@ -0,0 +1,32 @@ +getMethods(); foreach ($methods as $method) { + if ($method->getDeclaringClass() !== $class->getName()) { + continue; + } $snippets = array_merge($snippets, $this->examplesFromMethod($class, $method)); } @@ -274,7 +277,7 @@ public function examples(DocBlock $docBlock, $fullyQualifiedName, $file, $line, $snippet = new Snippet($identifier, [ 'content' => $example->textContent, 'fqn' => $fullyQualifiedName, - 'index' => $index, + 'index' => $indexOrName, 'name' => $name, 'file' => $file, 'line' => $line diff --git a/src/Core/Testing/Snippet/keyfile-stub.json b/src/Core/Testing/Snippet/keyfile-stub.json new file mode 100644 index 000000000000..e1c618b7497e --- /dev/null +++ b/src/Core/Testing/Snippet/keyfile-stub.json @@ -0,0 +1,12 @@ +{ + "type": "service_account", + "project_id": "my-awesome-project", + "private_key_id": "", + "private_key": "", + "client_email": "", + "client_id": "", + "auth_uri": "", + "token_uri": "", + "auth_provider_x509_cert_url": "", + "client_x509_cert_url": "" +} diff --git a/tests/snippets/Vision/Annotation/FaceTest.php b/tests/snippets/Vision/Annotation/FaceTest.php index 87ccd02f16e9..3f8e76ac3fa3 100644 --- a/tests/snippets/Vision/Annotation/FaceTest.php +++ b/tests/snippets/Vision/Annotation/FaceTest.php @@ -95,7 +95,7 @@ public function testInfo() public function testLandmarks() { - $snippet = $this->snippetFromMagicMethod(Face::class, 'landmarks'); + $snippet = $this->snippetFromMethod(Face::class, 'landmarks'); $snippet->addLocal('face', new Face([ 'landmarks' => [ [