Skip to content

Commit 234905a

Browse files
committed
👷 添加 phpunit
1 parent a1393d2 commit 234905a

File tree

4 files changed

+73
-2
lines changed

4 files changed

+73
-2
lines changed

composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,21 @@
1919
],
2020
"require": {
2121
"ext-json": "*",
22-
"php": "^7.2",
22+
"php": ">=7.2",
2323
"guzzlehttp/guzzle": "^7.3"
2424
},
2525
"autoload": {
2626
"psr-4": {
2727
"ALAPI\\": "src"
2828
}
2929
},
30+
"autoload-dev": {
31+
"psr-4": {
32+
"ALAPI\\Tests\\": "tests"
33+
}
34+
},
3035
"require-dev": {
31-
"friendsofphp/php-cs-fixer": "^3.0"
36+
"friendsofphp/php-cs-fixer": "^3.0",
37+
"phpunit/phpunit": "^7.5"
3238
}
3339
}

phpunit.xml.dist

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false">
11+
<testsuites>
12+
<testsuite name="Application Test Suite">
13+
<directory>./tests/</directory>
14+
</testsuite>
15+
</testsuites>
16+
<filter>
17+
<whitelist>
18+
<directory suffix=".php">src/</directory>
19+
</whitelist>
20+
</filter>
21+
</phpunit>

tests/ALAPITest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the ALAPI-SDK/php-sdk.
5+
* (c) Alone88 <[email protected]>
6+
* This source file is subject to the MIT license that is bundled
7+
* with this source code in the file LICENSE.
8+
*/
9+
10+
namespace ALAPI\Tests;
11+
12+
use ALAPI\Client;
13+
use ALAPI\Exception\ALAPIException;
14+
use PHPUnit\Framework\Assert;
15+
use PHPUnit\Framework\TestCase;
16+
17+
class ALAPITest extends TestCase
18+
{
19+
public function testAlapi()
20+
{
21+
$client = new Client('token');
22+
23+
try {
24+
$result = $client->setApi('/api/hitokoto')
25+
->setParam('type', 'a')
26+
->request();
27+
Assert::assertEquals(100, $result->getCode());
28+
} catch (ALAPIException $e) {
29+
}
30+
}
31+
32+
public function testUpload()
33+
{
34+
$client = new Client('token');
35+
try {
36+
$result = $client->setApi('/api/image')
37+
->setParam('image', 'tests/img.png', true)
38+
->setParam('type', 'alapi')
39+
->request();
40+
Assert::assertEquals(100, $result->getCode());
41+
} catch (ALAPIException $e) {
42+
}
43+
}
44+
}

tests/img.png

2.53 KB
Loading

0 commit comments

Comments
 (0)