-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
315 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
language: php | ||
|
||
php: | ||
- '7.0' | ||
- '7.1' | ||
- '7.2' | ||
|
||
install: composer install | ||
|
||
script: | ||
- mkdir build/logs -p | ||
- phpunit | ||
|
||
after_success: | ||
- travis_retry php vendor/bin/coveralls -v | ||
- bash <(curl -s https://codecov.io/bash) | ||
- php vendor/bin/codacycoverage clover build/logs/clover.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
beStrictAboutChangesToGlobalState="true" | ||
beStrictAboutOutputDuringTests="true" | ||
beStrictAboutTestsThatDoNotTestAnything="true" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
columns="max" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnError="false" | ||
stopOnFailure="false" | ||
stopOnRisky="false" | ||
verbose="true" | ||
> | ||
<php> | ||
<ini name="error_reporting" value="E_ALL" /> | ||
</php> | ||
|
||
<testsuites> | ||
<testsuite name="PHP Coveralls component test suite"> | ||
<directory>./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory>./src</directory> | ||
<exclude> | ||
<directory>./build</directory> | ||
<directory>./tests</directory> | ||
<directory>./vendor</directory> | ||
</exclude> | ||
</whitelist> | ||
</filter> | ||
|
||
<logging> | ||
<log type="coverage-clover" target="build/logs/clover.xml"/> | ||
</logging> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace SSitdikov\TelegraphAPI\Tests\Account; | ||
|
||
use SSitdikov\TelegraphAPI\Request\CreateAccountRequest; | ||
use PHPUnit\Framework\TestCase; | ||
use SSitdikov\TelegraphAPI\Request\RequestInterface; | ||
use SSitdikov\TelegraphAPI\Type\Account; | ||
|
||
class CreateAccountRequestTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function simpleCreateAccount() | ||
{ | ||
$account = new Account(); | ||
$shortName = md5(random_bytes(16)); | ||
$authorName = md5(random_bytes(16)); | ||
$authorUrl = md5(random_bytes(16)); | ||
$account->setShortName($shortName); | ||
$account->setAuthorName($authorName); | ||
$account->setAuthorUrl($authorUrl); | ||
$request = new CreateAccountRequest($account); | ||
|
||
$this->assertEquals(RequestInterface::POST, $request->getMethod()); | ||
$this->assertEquals('createAccount', $request->getUrlRequest()); | ||
$expectedParams = [ | ||
'json' => [ | ||
'short_name' => $shortName, | ||
'author_name' => $authorName, | ||
'author_url' => $authorUrl, | ||
] | ||
]; | ||
$this->assertEquals($expectedParams, $request->getParams()); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace SSitdikov\TelegraphAPI\Tests\Account; | ||
|
||
use SSitdikov\TelegraphAPI\Request\GetAccountInfoRequest; | ||
use PHPUnit\Framework\TestCase; | ||
use SSitdikov\TelegraphAPI\Request\RequestInterface; | ||
use SSitdikov\TelegraphAPI\Type\Account; | ||
|
||
class GetPageRequestTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function simpleGetAccountInfo() | ||
{ | ||
$account = new Account(); | ||
$accessToken = md5(random_bytes(16)); | ||
$account->setAccessToken($accessToken); | ||
$request = new GetAccountInfoRequest($account); | ||
$request->setAccountFields(['short_name', 'author_name', 'author_url', 'auth_url', 'page_count']); | ||
|
||
$this->assertEquals(RequestInterface::POST, $request->getMethod()); | ||
$this->assertEquals('getAccountInfo', $request->getUrlRequest()); | ||
$expectedParams = [ | ||
'json' => [ | ||
'access_token' => $accessToken, | ||
'fields' => [ | ||
'short_name', 'author_name', 'author_url', 'auth_url', 'page_count' | ||
] | ||
] | ||
]; | ||
$this->assertEquals($expectedParams, $request->getParams()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
<?php | ||
/** | ||
* User: Salavat Sitdikov | ||
*/ | ||
|
||
namespace SSitdikov\TelegraphAPI\Tests\Client; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Psr7\Response; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use SSitdikov\TelegraphAPI\Client\TelegraphClient; | ||
use PHPUnit\Framework\TestCase; | ||
use SSitdikov\TelegraphAPI\Exception\ShortNameRequiredException; | ||
use SSitdikov\TelegraphAPI\Request\CreateAccountRequest; | ||
use SSitdikov\TelegraphAPI\Request\GetAccountInfoRequest; | ||
use SSitdikov\TelegraphAPI\Type\Account; | ||
|
||
class TelegraphClientTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @var Account | ||
*/ | ||
private $account; | ||
/** | ||
* @var MockObject | ||
*/ | ||
private $client; | ||
|
||
public function setUp() | ||
{ | ||
$shortName = md5(time()); | ||
$this->account = new Account(); | ||
$this->account->setShortName($shortName); | ||
|
||
$this->client = $this->getMockBuilder(Client::class)->getMock(); | ||
|
||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function createAccount() | ||
{ | ||
|
||
$accessToken = md5(random_bytes(16)); | ||
$authUrl = md5(random_bytes(16)); | ||
|
||
$responseContent = [ | ||
'ok' => true, | ||
'result' => [ | ||
'short_name' => $this->account->getShortName(), | ||
'author_name' => '', | ||
'author_url' => '', | ||
'auth_url' => $authUrl, | ||
'access_token' => $accessToken, | ||
] | ||
]; | ||
$response = new Response(200, [], json_encode($responseContent)); | ||
$this->client->expects($this->once())->method('request')->willReturn($response); | ||
|
||
$telegraph = new TelegraphClient($this->client); | ||
$account = $telegraph->createAccount( | ||
new CreateAccountRequest($this->account) | ||
); | ||
|
||
$this->assertEquals($account->getAccessToken(), $accessToken); | ||
$this->assertEquals($account->getAuthUrl(), $authUrl); | ||
} | ||
|
||
/** | ||
* @test | ||
* @depends createAccount | ||
*/ | ||
public function createAccountError() | ||
{ | ||
$responseContent = [ | ||
'ok' => false, | ||
'error' => 'SomeStringError' | ||
]; | ||
$response = new Response(200, [], json_encode($responseContent)); | ||
$this->client->expects($this->once())->method('request')->willReturn($response); | ||
|
||
$telegraph = new TelegraphClient($this->client); | ||
|
||
$this->expectException(\Exception::class); | ||
$telegraph->createAccount( | ||
new CreateAccountRequest($this->account) | ||
); | ||
} | ||
|
||
/** | ||
* @test | ||
* @depends createAccountError | ||
*/ | ||
public function createAccountErrorNotRequiredFields() | ||
{ | ||
$responseContent = [ | ||
'ok' => false, | ||
'error' => 'SHORT_NAME_REQUIRED' | ||
]; | ||
|
||
$response = new Response(200, [], json_encode($responseContent)); | ||
$this->client->expects($this->once())->method('request')->willReturn($response); | ||
|
||
$telegraph = new TelegraphClient($this->client); | ||
|
||
$this->expectException(ShortNameRequiredException::class); | ||
$telegraph->createAccount( | ||
new CreateAccountRequest($this->account) | ||
); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function getAccountInfo() | ||
{ | ||
$authUrl = md5(random_bytes(16)); | ||
$accessToken = md5($authUrl . random_bytes(16)); | ||
$pageCount = random_int(100, 9999); | ||
$responseContent = [ | ||
'ok' => true, | ||
'result' => [ | ||
'short_name' => $this->account->getShortName(), | ||
'author_name' => '', | ||
'author_url' => '', | ||
'auth_url' => $authUrl, | ||
'access_token' => $accessToken, | ||
'page_count' => $pageCount, | ||
] | ||
]; | ||
|
||
$response = new Response(200, [], json_encode($responseContent)); | ||
$this->client->expects($this->once())->method('request')->willReturn($response); | ||
|
||
$telegraph = new TelegraphClient($this->client); | ||
|
||
$account = $telegraph->getAccountInfo( | ||
new GetAccountInfoRequest($this->account) | ||
); | ||
|
||
$this->assertEquals($pageCount, $account->getPageCount()); | ||
} | ||
|
||
/** | ||
* @test | ||
* @depends getAccountInfo | ||
*/ | ||
public function getAccountInfoError() | ||
{ | ||
$errorString = md5(random_bytes(16)); | ||
$responseContent = [ | ||
'ok' => false, | ||
'error' => $errorString | ||
]; | ||
|
||
$response = new Response(200, [], json_encode($responseContent)); | ||
$this->client->expects($this->once())->method('request')->willReturn($response); | ||
|
||
$telegraph = new TelegraphClient($this->client); | ||
|
||
$this->expectException(\Exception::class); | ||
$telegraph->getAccountInfo( | ||
new GetAccountInfoRequest($this->account) | ||
); | ||
} | ||
|
||
} |