Skip to content

Commit 060a268

Browse files
author
Alex
committed
Improve tests
1 parent ab90633 commit 060a268

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

phpunit.xml.dist

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="./tests/bootstrap.php" backupGlobals="false" colors="true">
3-
<coverage>
4-
<include>
5-
<directory suffix=".php">./src</directory>
6-
</include>
7-
<exclude/>
8-
</coverage>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd" bootstrap="./tests/bootstrap.php" backupGlobals="false" colors="true">
93
<php>
104
<ini name="error_reporting" value="-1"/>
115
<const name="PHPUNIT_TESTSUITE" value="true"/>
@@ -15,4 +9,10 @@
159
<directory>./tests/</directory>
1610
</testsuite>
1711
</testsuites>
12+
<source>
13+
<include>
14+
<directory suffix=".php">./src</directory>
15+
</include>
16+
<exclude/>
17+
</source>
1818
</phpunit>

tests/CommentsClientAnalyzeTest.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
use PHPUnit\Framework\TestCase;
77

88
class CommentsClientAnalyzeTest extends TestCase {
9-
/** @var CommentsResponse */
10-
protected static $response;
9+
protected static CommentsResponse $response;
1110

11+
/**
12+
* @throws CommentsException
13+
*/
1214
public static function setUpBeforeClass(): void {
1315
$commentsClient = new CommentsClient($_ENV['PERSPECTIVE_API_TOKEN']);
1416
$commentsClient->comment(['text' => 'What kind of idiot name is foo? Sorry, I like your name.']);
@@ -32,7 +34,7 @@ public function testAttributeScores(): void {
3234

3335
$this->assertIsArray($attributeScores);
3436
$this->arrayHasKey('TOXICITY');
35-
$this->assertGreaterThan(0.8, $attributeScores['TOXICITY']['summaryScore']['value']);
37+
$this->assertGreaterThan(0.7, $attributeScores['TOXICITY']['summaryScore']['value']);
3638
}
3739

3840
public function testLanguages() {
@@ -50,9 +52,10 @@ public function testClientToken() {
5052

5153
public function testCommentsException() {
5254
$this->expectException(CommentsException::class);
53-
$this->expectExceptionMessage('The request is missing a valid API key.');
55+
$this->expectExceptionMessage('API key not valid. Please pass a valid API key.');
5456

55-
$commentsClient = new CommentsClient('');
57+
$commentsClient = new CommentsClient('invalid key');
58+
$commentsClient->comment(['text' => 'What kind of idiot name is foo? Sorry, I like your name.']);
5659
$commentsClient->analyze();
5760
}
5861
}

tests/CommentsClientSuggestScoreTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
use PHPUnit\Framework\TestCase;
77

88
class CommentsClientSuggestScoreTest extends TestCase {
9-
/** @var CommentsResponse */
10-
protected static $response;
9+
protected static CommentsResponse $response;
1110

1211
public static function setUpBeforeClass(): void {
1312
$commentsClient = new CommentsClient($_ENV['PERSPECTIVE_API_TOKEN']);
@@ -39,9 +38,10 @@ public function testClientToken() {
3938

4039
public function testCommentsException() {
4140
$this->expectException(CommentsException::class);
42-
$this->expectExceptionMessage('The request is missing a valid API key.');
41+
$this->expectExceptionMessage('API key not valid. Please pass a valid API key.');
4342

44-
$commentsClient = new CommentsClient('');
43+
$commentsClient = new CommentsClient('invalid key');
44+
$commentsClient->comment(['text' => 'What kind of idiot name is foo? Sorry, I like your name.']);
4545
$commentsClient->suggestScore();
4646
}
4747
}

0 commit comments

Comments
 (0)