diff --git a/language/api/composer.json b/language/api/composer.json index be05f66738..bd59c21633 100644 --- a/language/api/composer.json +++ b/language/api/composer.json @@ -1,6 +1,6 @@ { "require": { - "google/cloud": "0.8", + "google/cloud": "0.9", "symfony/console": "^3.0" }, "autoload": { @@ -8,10 +8,14 @@ "Google\\Cloud\\Samples\\Language\\": "src/" }, "files": [ + "src/functions/analyze_all.php", + "src/functions/analyze_all_from_file.php", "src/functions/analyze_entities.php", - "src/functions/analyze_everything.php", + "src/functions/analyze_entities_from_file.php", "src/functions/analyze_sentiment.php", + "src/functions/analyze_sentiment_from_file.php", "src/functions/analyze_syntax.php", + "src/functions/analyze_syntax_from_file.php", "src/functions/print_annotation.php" ] } diff --git a/language/api/composer.lock b/language/api/composer.lock index 7a0155a05e..55d70fbfd0 100644 --- a/language/api/composer.lock +++ b/language/api/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "7f7dec10e790c2b6486861fd8f7c43e0", - "content-hash": "9a7b01bf149347dfda66e5d1b036fcde", + "hash": "49a7fb54ffa67b7590cd30ccb4cb8c41", + "content-hash": "3894cd7cf2419ef89488b57e44f337a4", "packages": [ { "name": "firebase/php-jwt", @@ -100,16 +100,16 @@ }, { "name": "google/cloud", - "version": "v0.8.0", + "version": "v0.9.0", "source": { "type": "git", "url": "https://github.com/GoogleCloudPlatform/google-cloud-php.git", - "reference": "79a765fdcb2be9e756f8bf9283ad3626cd2f61d4" + "reference": "a972770d8f36687dbb34f23df7d6d76027bf2323" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/GoogleCloudPlatform/google-cloud-php/zipball/79a765fdcb2be9e756f8bf9283ad3626cd2f61d4", - "reference": "79a765fdcb2be9e756f8bf9283ad3626cd2f61d4", + "url": "https://api.github.com/repos/GoogleCloudPlatform/google-cloud-php/zipball/a972770d8f36687dbb34f23df7d6d76027bf2323", + "reference": "a972770d8f36687dbb34f23df7d6d76027bf2323", "shasum": "" }, "require": { @@ -122,12 +122,13 @@ "rize/uri-template": "~0.3" }, "require-dev": { + "erusev/parsedown": "^1.6", "james-heinrich/getid3": "^1.9", "league/json-guard": "^0.3", - "phpdocumentor/phpdocumentor": "2.8.*", + "phpdocumentor/reflection": "^3.0", "phpunit/phpunit": "4.8.*", "squizlabs/php_codesniffer": "2.*", - "symfony/console": "2.*" + "symfony/console": "^3.0" }, "suggest": { "google/gax": "Required to support gRPC", @@ -178,7 +179,7 @@ "translate", "vision" ], - "time": "2016-09-09 14:17:08" + "time": "2016-09-26 15:59:01" }, { "name": "guzzlehttp/guzzle", @@ -618,20 +619,21 @@ }, { "name": "symfony/console", - "version": "v3.1.4", + "version": "v3.1.5", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "8ea494c34f0f772c3954b5fbe00bffc5a435e563" + "reference": "6cb0872fb57b38b3b09ff213c21ed693956b9eb0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/8ea494c34f0f772c3954b5fbe00bffc5a435e563", - "reference": "8ea494c34f0f772c3954b5fbe00bffc5a435e563", + "url": "https://api.github.com/repos/symfony/console/zipball/6cb0872fb57b38b3b09ff213c21ed693956b9eb0", + "reference": "6cb0872fb57b38b3b09ff213c21ed693956b9eb0", "shasum": "" }, "require": { "php": ">=5.5.9", + "symfony/debug": "~2.8|~3.0", "symfony/polyfill-mbstring": "~1.0" }, "require-dev": { @@ -674,7 +676,64 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com/", - "time": "2016-08-19 06:48:39" + "time": "2016-09-28 00:11:12" + }, + { + "name": "symfony/debug", + "version": "v3.1.5", + "source": { + "type": "git", + "url": "https://github.com/symfony/debug.git", + "reference": "e2b3f74a67fc928adc3c1b9027f73e1bc01190a8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/debug/zipball/e2b3f74a67fc928adc3c1b9027f73e1bc01190a8", + "reference": "e2b3f74a67fc928adc3c1b9027f73e1bc01190a8", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "psr/log": "~1.0" + }, + "conflict": { + "symfony/http-kernel": ">=2.3,<2.3.24|~2.4.0|>=2.5,<2.5.9|>=2.6,<2.6.2" + }, + "require-dev": { + "symfony/class-loader": "~2.8|~3.0", + "symfony/http-kernel": "~2.8|~3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Debug\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Debug Component", + "homepage": "https://symfony.com/", + "time": "2016-09-06 11:02:40" }, { "name": "symfony/polyfill-mbstring", diff --git a/language/api/language.php b/language/api/language.php index 36a6bb8180..5097941bbf 100644 --- a/language/api/language.php +++ b/language/api/language.php @@ -2,15 +2,15 @@ require __DIR__ . '/vendor/autoload.php'; -use Google\Cloud\Samples\Language\AnalyzeEntitiesCommand; -use Google\Cloud\Samples\Language\AnalyzeEverythingCommand; -use Google\Cloud\Samples\Language\AnalyzeSentimentCommand; -use Google\Cloud\Samples\Language\AnalyzeSyntaxCommand; +use Google\Cloud\Samples\Language\AllCommand; +use Google\Cloud\Samples\Language\EntitiesCommand; +use Google\Cloud\Samples\Language\SentimentCommand; +use Google\Cloud\Samples\Language\SyntaxCommand; use Symfony\Component\Console\Application; $application = new Application(); -$application->add(new AnalyzeEntitiesCommand()); -$application->add(new AnalyzeEverythingCommand()); -$application->add(new AnalyzeSentimentCommand()); -$application->add(new AnalyzeSyntaxCommand()); +$application->add(new AllCommand()); +$application->add(new EntitiesCommand()); +$application->add(new SentimentCommand()); +$application->add(new SyntaxCommand()); $application->run(); diff --git a/language/api/src/AnalyzeEverythingCommand.php b/language/api/src/AllCommand.php similarity index 63% rename from language/api/src/AnalyzeEverythingCommand.php rename to language/api/src/AllCommand.php index 035ec6e2be..7effa25f09 100644 --- a/language/api/src/AnalyzeEverythingCommand.php +++ b/language/api/src/AllCommand.php @@ -23,36 +23,44 @@ use Symfony\Component\Console\Output\OutputInterface; /** - * Command line utility to transcribe. + * Command line utility for the Natural Language APIs. * - * Usage: php speech.php transcribe + * Usage: php language.php all TEXT */ -class AnalyzeEverythingCommand extends Command +class AllCommand extends Command { protected function configure() { $this - ->setName('everything') - ->setDescription('Analyze some natural language text.') + ->setName('all') + ->setDescription('Analyze syntax, sentiment and entities in text.') ->setHelp(<<%command.name% command analyzes text using the Google Cloud Natural Language API. php %command.full_name% Text to analyze. + php %command.full_name% gs://my_bucket/file_with_text.txt + EOF ) ->addArgument( - 'text', + 'content', InputArgument::IS_ARRAY | InputArgument::REQUIRED, - 'Text to analyze' + 'Text or path to Cloud Storage file' ) ; } protected function execute(InputInterface $input, OutputInterface $output) { - $text = implode(" ", $input->getArgument('text')); - $result = analyze_everything($text); + $content = implode(' ', (array) $input->getArgument('content')); + // Regex to match a Cloud Storage path as the first argument + // e.g "gs://my-bucket/file_with_text.txt" + if (preg_match('/^gs:\/\/([a-z0-9\._\-]+)\/(\S+)$/', $content, $matches)) { + $result = analyze_all_from_file($matches[1], $matches[2]); + } else { + $result = analyze_all($content); + } print_annotation($result); } } diff --git a/language/api/src/AnalyzeEntitiesCommand.php b/language/api/src/EntitiesCommand.php similarity index 64% rename from language/api/src/AnalyzeEntitiesCommand.php rename to language/api/src/EntitiesCommand.php index af5eefab7d..d174c65362 100644 --- a/language/api/src/AnalyzeEntitiesCommand.php +++ b/language/api/src/EntitiesCommand.php @@ -23,36 +23,44 @@ use Symfony\Component\Console\Output\OutputInterface; /** - * Command line utility to transcribe. + * Command line utility for the Natural Language APIs. * - * Usage: php speech.php transcribe + * Usage: php language.php entities TEXT */ -class AnalyzeEntitiesCommand extends Command +class EntitiesCommand extends Command { protected function configure() { $this ->setName('entities') - ->setDescription('Analyze some natural language text.') + ->setDescription('Analyze entities in text.') ->setHelp(<<%command.name% command analyzes text using the Google Cloud Natural Language API. php %command.full_name% Text to analyze. + php %command.full_name% gs://my_bucket/file_with_text.txt + EOF ) ->addArgument( - 'text', + 'content', InputArgument::IS_ARRAY | InputArgument::REQUIRED, - 'Text to analyze' + 'Text or path to Cloud Storage file' ) ; } protected function execute(InputInterface $input, OutputInterface $output) { - $text = implode(" ", $input->getArgument('text')); - $result = analyze_entities($text); + $content = implode(' ', (array) $input->getArgument('content')); + // Regex to match a Cloud Storage path as the first argument + // e.g "gs://my-bucket/file_with_text.txt" + if (preg_match('/^gs:\/\/([a-z0-9\._\-]+)\/(\S+)$/', $content, $matches)) { + $result = analyze_entities_from_file($matches[1], $matches[2]); + } else { + $result = analyze_entities($content); + } print_annotation($result); } } diff --git a/language/api/src/AnalyzeSentimentCommand.php b/language/api/src/SentimentCommand.php similarity index 64% rename from language/api/src/AnalyzeSentimentCommand.php rename to language/api/src/SentimentCommand.php index 21e5a3284b..b833081450 100644 --- a/language/api/src/AnalyzeSentimentCommand.php +++ b/language/api/src/SentimentCommand.php @@ -23,36 +23,45 @@ use Symfony\Component\Console\Output\OutputInterface; /** - * Command line utility to transcribe. + * Command line utility for the Natural Language APIs. * - * Usage: php speech.php transcribe + * Usage: php language.php sentiment TEXT */ -class AnalyzeSentimentCommand extends Command +class SentimentCommand extends Command { protected function configure() { $this ->setName('sentiment') - ->setDescription('Analyze some natural language text.') + ->setDescription('Analyze sentiment in text.') ->setHelp(<<%command.name% command analyzes text using the Google Cloud Natural Language API. php %command.full_name% Text to analyze. + php %command.full_name% gs://my_bucket/file_with_text.txt + EOF ) ->addArgument( - 'text', + 'content', InputArgument::IS_ARRAY | InputArgument::REQUIRED, - 'Text to analyze' + 'Text or path to Cloud Storage file' ) ; } protected function execute(InputInterface $input, OutputInterface $output) { - $text = implode(" ", $input->getArgument('text')); - $result = analyze_sentiment($text); + $content = implode(' ', (array) $input->getArgument('content')); + // Regex to match a Cloud Storage path as the first argument + // e.g "gs://my-bucket/file_with_text.txt" + if (preg_match('/^gs:\/\/([a-z0-9\._\-]+)\/(\S+)$/', $content, $matches)) { + $result = analyze_sentiment_from_file($matches[1], $matches[2]); + } else { + $result = analyze_sentiment($content); + } + print_annotation($result); } } diff --git a/language/api/src/AnalyzeSyntaxCommand.php b/language/api/src/SyntaxCommand.php similarity index 65% rename from language/api/src/AnalyzeSyntaxCommand.php rename to language/api/src/SyntaxCommand.php index f852ec1470..b7fb4d1367 100644 --- a/language/api/src/AnalyzeSyntaxCommand.php +++ b/language/api/src/SyntaxCommand.php @@ -23,36 +23,44 @@ use Symfony\Component\Console\Output\OutputInterface; /** - * Command line utility to transcribe. + * Command line utility for the Natural Language APIs. * - * Usage: php speech.php transcribe + * Usage: php language.php syntax TEXT */ -class AnalyzeSyntaxCommand extends Command +class SyntaxCommand extends Command { protected function configure() { $this ->setName('syntax') - ->setDescription('Analyze some natural language text.') + ->setDescription('Analyze syntax in text.') ->setHelp(<<%command.name% command analyzes text using the Google Cloud Natural Language API. php %command.full_name% Text to analyze. + php %command.full_name% gs://my_bucket/file_with_text.txt + EOF ) ->addArgument( - 'text', + 'content', InputArgument::IS_ARRAY | InputArgument::REQUIRED, - 'Text to analyze' + 'Text or path to Cloud Storage file' ) ; } protected function execute(InputInterface $input, OutputInterface $output) { - $text = implode(" ", $input->getArgument('text')); - $result = analyze_syntax($text); + $content = implode(' ', (array) $input->getArgument('content')); + // Regex to match a Cloud Storage path as the first argument + // e.g "gs://my-bucket/file_with_text.txt" + if (preg_match('/^gs:\/\/([a-z0-9\._\-]+)\/(\S+)$/', $content, $matches)) { + $result = analyze_syntax_from_file($matches[1], $matches[2]); + } else { + $result = analyze_syntax($content); + } print_annotation($result); } } diff --git a/language/api/src/functions/analyze_everything.php b/language/api/src/functions/analyze_all.php similarity index 87% rename from language/api/src/functions/analyze_everything.php rename to language/api/src/functions/analyze_all.php index b5364a002f..7967abb193 100644 --- a/language/api/src/functions/analyze_everything.php +++ b/language/api/src/functions/analyze_all.php @@ -23,21 +23,21 @@ namespace Google\Cloud\Samples\Language; -# [START analyze_everything] +# [START analyze_all] use Google\Cloud\NaturalLanguage\NaturalLanguageClient; use Google\Cloud\NaturalLanguage\Annotation; /** * Find the everything in text. * ``` - * analyze_everything('Do you know the way to San Jose?'); - * ```. + * analyze_all('Do you know the way to San Jose?'); + * ``` * * @param string $text The text to analyze. * * @return Annotation */ -function analyze_everything($text, $options = []) +function analyze_all($text) { $language = new NaturalLanguageClient(); $annotation = $language->annotateText($text, [ @@ -45,4 +45,4 @@ function analyze_everything($text, $options = []) ]); return $annotation; } -# [END analyze_everything] +# [END analyze_all] diff --git a/language/api/src/functions/analyze_all_from_file.php b/language/api/src/functions/analyze_all_from_file.php new file mode 100644 index 0000000000..561e5ac34b --- /dev/null +++ b/language/api/src/functions/analyze_all_from_file.php @@ -0,0 +1,56 @@ +bucket($bucketName); + $storageObject = $bucket->object($objectName); + + // Call the Natural Language client + $language = new NaturalLanguageClient(); + $annotation = $language->annotateText($storageObject, [ + 'features' => ['entities', 'syntax', 'sentiment'] + ]); + return $annotation; +} +# [END analyze_all_from_file] diff --git a/language/api/src/functions/analyze_entities.php b/language/api/src/functions/analyze_entities.php index 09aa7876db..e08f51a0d5 100644 --- a/language/api/src/functions/analyze_entities.php +++ b/language/api/src/functions/analyze_entities.php @@ -31,7 +31,7 @@ * Find the entities in text. * ``` * analyze_entities('Do you know the way to San Jose?'); - * ```. + * ``` * * @param string $text The text to analyze. * @@ -40,7 +40,7 @@ function analyze_entities($text, $options = []) { $language = new NaturalLanguageClient(); - $annotation = $language->analyzeEntities($text); + $annotation = $language->analyzeEntities($text, $options); return $annotation; } # [END analyze_entities] diff --git a/language/api/src/functions/analyze_entities_from_file.php b/language/api/src/functions/analyze_entities_from_file.php new file mode 100644 index 0000000000..1436bc4735 --- /dev/null +++ b/language/api/src/functions/analyze_entities_from_file.php @@ -0,0 +1,54 @@ +bucket($bucketName); + $storageObject = $bucket->object($objectName); + + // Call the Natural Language client + $language = new NaturalLanguageClient(); + $annotation = $language->analyzeEntities($storageObject, $options); + return $annotation; +} +# [END analyze_entities_from_file] diff --git a/language/api/src/functions/analyze_sentiment.php b/language/api/src/functions/analyze_sentiment.php index 3b0818e835..f73aa6b8f3 100644 --- a/language/api/src/functions/analyze_sentiment.php +++ b/language/api/src/functions/analyze_sentiment.php @@ -31,7 +31,7 @@ * Find the sentiment in text. * ``` * analyze_sentiment('Do you know the way to San Jose?'); - * ```. + * ``` * * @param string $text The text to analyze. * @@ -40,7 +40,7 @@ function analyze_sentiment($text, $options = []) { $language = new NaturalLanguageClient(); - $annotation = $language->analyzeSentiment($text); + $annotation = $language->analyzeSentiment($text, $options); return $annotation; } # [END analyze_sentiment] diff --git a/language/api/src/functions/analyze_sentiment_from_file.php b/language/api/src/functions/analyze_sentiment_from_file.php new file mode 100644 index 0000000000..2d8a031643 --- /dev/null +++ b/language/api/src/functions/analyze_sentiment_from_file.php @@ -0,0 +1,54 @@ +bucket($bucketName); + $storageObject = $bucket->object($objectName); + + // Call the Natural Language client + $language = new NaturalLanguageClient(); + $annotation = $language->analyzeSentiment($storageObject, $options); + return $annotation; +} +# [END analyze_sentiment_from_file] diff --git a/language/api/src/functions/analyze_syntax.php b/language/api/src/functions/analyze_syntax.php index 4fc661203c..b7cb13cc18 100644 --- a/language/api/src/functions/analyze_syntax.php +++ b/language/api/src/functions/analyze_syntax.php @@ -31,7 +31,7 @@ * Find the syntax in text. * ``` * analyze_syntax('Do you know the way to San Jose?'); - * ```. + * ``` * * @param string $text The text to analyze. * @@ -40,7 +40,7 @@ function analyze_syntax($text, $options = []) { $language = new NaturalLanguageClient(); - $annotation = $language->analyzeSyntax($text); + $annotation = $language->analyzeSyntax($text, $options); return $annotation; } # [END analyze_syntax] diff --git a/language/api/src/functions/analyze_syntax_from_file.php b/language/api/src/functions/analyze_syntax_from_file.php new file mode 100644 index 0000000000..3d3fdd1b9d --- /dev/null +++ b/language/api/src/functions/analyze_syntax_from_file.php @@ -0,0 +1,54 @@ +bucket($bucketName); + $storageObject = $bucket->object($objectName); + + // Call the Natural Language client + $language = new NaturalLanguageClient(); + $annotation = $language->analyzeSyntax($storageObject, $options); + return $annotation; +} +# [END analyze_syntax_from_file] diff --git a/language/api/test/AllCommandTest.php b/language/api/test/AllCommandTest.php new file mode 100644 index 0000000000..187c608075 --- /dev/null +++ b/language/api/test/AllCommandTest.php @@ -0,0 +1,96 @@ + 0; + } + + public function setUp() + { + $application = new Application(); + $application->add(new AllCommand()); + $this->commandTester = new CommandTester($application->get('all')); + $this->expectedString = <<markTestSkipped('No application credentials were found.'); + } + + $this->commandTester->execute( + ['content' => explode(' ', 'Do you know the way to San Jose?')], + ['interactive' => false] + ); + + $this->expectOutputString($this->expectedString); + } + + public function testEverythingFromStorageObject() + { + if (!self::$hasCredentials) { + $this->markTestSkipped('No application credentials were found.'); + } + if (!$gcsFile = getenv('GOOGLE_LANGUAGE_GCS_FILE')) { + $this->markTestSkipped('No GCS file.'); + } + + $this->commandTester->execute( + ['content' => $gcsFile], + ['interactive' => false] + ); + + $this->expectOutputString($this->expectedString); + } +} diff --git a/language/api/test/AnalyzeEverythingCommandTest.php b/language/api/test/AnalyzeEverythingCommandTest.php deleted file mode 100644 index 9f60de6280..0000000000 --- a/language/api/test/AnalyzeEverythingCommandTest.php +++ /dev/null @@ -1,55 +0,0 @@ - 0; - } - - public function testEverything() - { - if (!self::$hasCredentials) { - $this->markTestSkipped('No application credentials were found.'); - } - - $application = new Application(); - $application->add(new AnalyzeEverythingCommand()); - $commandTester = new CommandTester($application->get('everything')); - $commandTester->execute( - ['text' => explode(' ', 'Do you know the way to San Jose?')], - ['interactive' => false] - ); - $this->expectOutputRegex('/San Jose: http:\/\/en.wikipedia.org/'); - $this->expectOutputRegex(`sentiment: -`); - $this->expectOutputRegex(`0: Do you know the way`); - } -} diff --git a/language/api/test/AnalyzeEntitiesCommandTest.php b/language/api/test/EntitiesCommandTest.php similarity index 58% rename from language/api/test/AnalyzeEntitiesCommandTest.php rename to language/api/test/EntitiesCommandTest.php index 08b33dd08f..c66059311e 100644 --- a/language/api/test/AnalyzeEntitiesCommandTest.php +++ b/language/api/test/EntitiesCommandTest.php @@ -17,16 +17,17 @@ namespace Google\Cloud\Samples\Language\Tests; -use Google\Cloud\Samples\Language\AnalyzeEntitiesCommand; +use Google\Cloud\Samples\Language\EntitiesCommand; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; /** - * Unit Tests for TablesCommand. + * Unit Tests for EntitiesCommand. */ -class AnalyzeEntitiesCommandTest extends \PHPUnit_Framework_TestCase +class EntitiesCommandTest extends \PHPUnit_Framework_TestCase { protected static $hasCredentials; + private $commandTester; public static function setUpBeforeClass() { @@ -35,17 +36,37 @@ public static function setUpBeforeClass() filesize($path) > 0; } + public function setUp() + { + $application = new Application(); + $application->add(new EntitiesCommand()); + $this->commandTester = new CommandTester($application->get('entities')); + } + public function testEntities() { if (!self::$hasCredentials) { $this->markTestSkipped('No application credentials were found.'); } - $application = new Application(); - $application->add(new AnalyzeEntitiesCommand()); - $commandTester = new CommandTester($application->get('entities')); - $commandTester->execute( - ['text' => explode(' ', 'Do you know the way to San Jose?')], + $this->commandTester->execute( + ['content' => explode(' ', 'Do you know the way to San Jose?')], + ['interactive' => false] + ); + $this->expectOutputRegex('/San Jose: http:\/\/en.wikipedia.org/'); + } + + public function testEntitiesFromStorageObject() + { + if (!self::$hasCredentials) { + $this->markTestSkipped('No application credentials were found.'); + } + if (!$gcsFile = getenv('GOOGLE_LANGUAGE_GCS_FILE')) { + $this->markTestSkipped('No GCS file.'); + } + + $this->commandTester->execute( + ['content' => $gcsFile], ['interactive' => false] ); $this->expectOutputRegex('/San Jose: http:\/\/en.wikipedia.org/'); diff --git a/language/api/test/AnalyzeSentimentCommandTest.php b/language/api/test/SentimentCommandTest.php similarity index 55% rename from language/api/test/AnalyzeSentimentCommandTest.php rename to language/api/test/SentimentCommandTest.php index 13ddded6df..c049bcb55a 100644 --- a/language/api/test/AnalyzeSentimentCommandTest.php +++ b/language/api/test/SentimentCommandTest.php @@ -17,16 +17,17 @@ namespace Google\Cloud\Samples\Language\Tests; -use Google\Cloud\Samples\Language\AnalyzeSentimentCommand; +use Google\Cloud\Samples\Language\SentimentCommand; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; /** - * Unit Tests for TablesCommand. + * Unit Tests for SentimentCommand. */ -class AnalyzeSentimentCommandTest extends \PHPUnit_Framework_TestCase +class SentimentCommandTest extends \PHPUnit_Framework_TestCase { protected static $hasCredentials; + private $commandTester; public static function setUpBeforeClass() { @@ -35,19 +36,41 @@ public static function setUpBeforeClass() filesize($path) > 0; } + public function setUp() + { + $application = new Application(); + $application->add(new SentimentCommand()); + $this->commandTester = new CommandTester($application->get('sentiment')); + } + public function testSentiment() { if (!self::$hasCredentials) { $this->markTestSkipped('No application credentials were found.'); } - $application = new Application(); - $application->add(new AnalyzeSentimentCommand()); - $commandTester = new CommandTester($application->get('sentiment')); - $commandTester->execute( - ['text' => explode(' ', 'Do you know the way to San Jose?')], + $this->commandTester->execute( + ['content' => explode(' ', 'Do you know the way to San Jose?')], ['interactive' => false] ); - $this->expectOutputRegex(`sentiment: -`); + + $this->expectOutputRegex('/sentiment: -/'); + } + + public function testEverythingFromStorageObject() + { + if (!self::$hasCredentials) { + $this->markTestSkipped('No application credentials were found.'); + } + if (!$gcsFile = getenv('GOOGLE_LANGUAGE_GCS_FILE')) { + $this->markTestSkipped('No GCS file.'); + } + + $this->commandTester->execute( + ['content' => $gcsFile], + ['interactive' => false] + ); + + $this->expectOutputRegex('/sentiment: -/'); } } diff --git a/language/api/test/AnalyzeSyntaxCommandTest.php b/language/api/test/SyntaxCommandTest.php similarity index 55% rename from language/api/test/AnalyzeSyntaxCommandTest.php rename to language/api/test/SyntaxCommandTest.php index 90f2c02233..a5f54b6d8a 100644 --- a/language/api/test/AnalyzeSyntaxCommandTest.php +++ b/language/api/test/SyntaxCommandTest.php @@ -17,16 +17,17 @@ namespace Google\Cloud\Samples\Language\Tests; -use Google\Cloud\Samples\Language\AnalyzeSyntaxCommand; +use Google\Cloud\Samples\Language\SyntaxCommand; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; /** - * Unit Tests for TablesCommand. + * Unit Tests for SyntaxCommand. */ -class AnalyzeSyntaxCommandTest extends \PHPUnit_Framework_TestCase +class SyntaxCommandTest extends \PHPUnit_Framework_TestCase { protected static $hasCredentials; + private $commandTester; public static function setUpBeforeClass() { @@ -35,19 +36,41 @@ public static function setUpBeforeClass() filesize($path) > 0; } + public function setUp() + { + $application = new Application(); + $application->add(new SyntaxCommand()); + $this->commandTester = new CommandTester($application->get('syntax')); + } + public function testSyntax() { if (!self::$hasCredentials) { $this->markTestSkipped('No application credentials were found.'); } - $application = new Application(); - $application->add(new AnalyzeSyntaxCommand()); - $commandTester = new CommandTester($application->get('syntax')); - $commandTester->execute( - ['text' => explode(' ', 'Do you know the way to San Jose?')], + $this->commandTester->execute( + ['content' => explode(' ', 'Do you know the way to San Jose?')], ['interactive' => false] ); - $this->expectOutputRegex(`0: Do you know the way`); + + $this->expectOutputRegex('/0: Do you know the way/'); + } + + public function testEverythingFromStorageObject() + { + if (!self::$hasCredentials) { + $this->markTestSkipped('No application credentials were found.'); + } + if (!$gcsFile = getenv('GOOGLE_LANGUAGE_GCS_FILE')) { + $this->markTestSkipped('No GCS file.'); + } + + $this->commandTester->execute( + ['content' => $gcsFile], + ['interactive' => false] + ); + + $this->expectOutputRegex('/0: Do you know the way/'); } }