Skip to content

Commit 4be35de

Browse files
author
Takashi Matsuo
authored
Fixed a broken test for Language API quickstart (GoogleCloudPlatform#208)
1 parent d0542c3 commit 4be35de

File tree

4 files changed

+32
-27
lines changed

4 files changed

+32
-27
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ language: php
2020

2121
matrix:
2222
include:
23-
- php: 5.5
24-
env: RUN_DEVSERVER_TESTS=true RUN_CS_FIXER=true
2523
- php: 5.6
24+
env: RUN_DEVSERVER_TESTS=true RUN_CS_FIXER=true
2625
- php: 7.0
2726

2827
env:

language/quickstart/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"require": {
33
"php": ">=5.4",
4-
"google/cloud": "0.10"
4+
"google/cloud": "~0.11"
55
}
66
}

language/quickstart/composer.lock

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

language/quickstart/test/quickstartTest.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,26 @@ public function testQuickstart()
3232
file_put_contents($file, $contents);
3333

3434
// Invoke quickstart.php
35+
36+
ob_start();
3537
$sentiment = include $file;
38+
$output = ob_get_clean();
3639

3740
// Make sure it looks correct
3841
$this->assertTrue(is_array($sentiment));
3942
$this->assertArrayHasKey('polarity', $sentiment);
4043
$this->assertArrayHasKey('magnitude', $sentiment);
4144
$this->assertEquals(1, $sentiment['polarity']);
42-
$this->assertEquals(.6, $sentiment['magnitude']);
43-
44-
$expectedOutput = <<<EOF
45-
Text: Hello, world!
46-
Sentiment: 1, 0.6
47-
EOF;
45+
$this->assertTrue(0.1 < $sentiment['magnitude']);
46+
$this->assertTrue($sentiment['magnitude'] < 1.0);
4847

49-
$this->expectOutputString($expectedOutput);
48+
49+
$expectedPatterns = array(
50+
'/Text: Hello, world!/',
51+
'/Sentiment: \\d, \\d.\\d/',
52+
);
53+
foreach ($expectedPatterns as $pattern) {
54+
$this->assertRegExp($pattern, $output);
55+
}
5056
}
5157
}

0 commit comments

Comments
 (0)