Including Tests and verifications for errors

This commit is contained in:
2019-06-27 20:03:10 -03:00
parent e4f2bd04be
commit aaabb91039
10 changed files with 221 additions and 9 deletions

View File

@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use BrunoFontes\Memsource;
final class BilingualFileTest extends TestCase
{
public function testEmptyDownloadJobUidListShouldReturnEmptyFilenames()
{
$api = new Memsource('fakeToken');
$this->assertEquals(
[],
$api->bilingualFile()->download('uid', [], 'filename')
);
}
public function testInvalidDownloadUidsShouldThrowError()
{
$api = new Memsource('fakeToken');
$this->expectException(\Exception::class);
$api->bilingualFile()->download('uid', ['a'], 'filename');
}
public function testUploadInexistentFileShouldThrowError()
{
$api = new Memsource('fakeToken');
$this->expectException(\Exception::class);
$api->bilingualFile()->upload('myInvalidFile', []);
}
public function testUploadWithNoTokenShouldThrowError()
{
$api = new Memsource('fakeToken');
$this->expectException(\Exception::class);
$api->bilingualFile()->upload('tests/bilingualFileTest.php', []);
}
}

57
tests/fetchApiTest.php Normal file
View File

@@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use BrunoFontes\Memsource\FetchApi;
final class FetchApiTest extends TestCase
{
public function testEmptyFetchUrlShouldThrowError()
{
$fetch = new FetchApi('fakeToken', 'https://google.com');
$this->expectExceptionMessage('URL not defined');
$this->assertNotEmpty($fetch->fetch('get', ''));
}
public function testNotEmptyTokenOnFetchShouldNotThrowError()
{
$fetch = new FetchApi('fakeToken', 'https://google.com');
$this->assertNotEmpty($fetch->fetch('get', '/'));
}
public function testEmptyTokenOnFetchRawShouldNotThrowError()
{
$fetch = new FetchApi(null, 'http://google.com');
$this->assertNotEmpty($fetch->fetch('raw', '/'));
}
public function testEmptyTokenOnFetchGetShouldThrowError()
{
$fetch = new FetchApi(null, 'http://testUrl.com');
$this->expectExceptionMessage('Missing Access Token');
$fetch->fetch('get', 'url');
}
public function testEmptyTokenOnFetchPutShouldThrowError()
{
$fetch = new FetchApi(null, 'http://testUrl.com');
$this->expectExceptionMessage('Missing Access Token');
$fetch->fetch('put', 'url');
}
public function testEmptyTokenOnFetchPostShouldThrowError()
{
$fetch = new FetchApi(null, 'http://testUrl.com');
$this->expectExceptionMessage('Missing Access Token');
$fetch->fetch('post', 'url');
}
public function testEmptyTokenOnFetchJsonPostShouldThrowError()
{
$fetch = new FetchApi(null, 'http://testUrl.com');
$this->expectExceptionMessage('Missing Access Token');
$fetch->fetch('jsonPost', 'url');
}
public function testEmptyTokenOnFetchDownloadShouldThrowError()
{
$fetch = new FetchApi(null, 'http://testUrl.com');
$this->expectExceptionMessage('Missing Access Token');
$fetch->fetch('download', 'url');
}
}

15
tests/jobsTest.php Normal file
View File

@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use BrunoFontes\Memsource;
final class JobsTest extends TestCase
{
public function testInvalidProjectUidShouldThrowError()
{
$api = new Memsource('fakeToken');
$this->expectException(\Exception::class);
$api->jobs()->list('invalidProjectUid', []);
}
}

34
tests/oauthTest.php Normal file
View File

@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use BrunoFontes\Memsource;
final class oauthTest extends TestCase
{
public function testOauthGetAuthorizationCodeUrl()
{
$customServerURL = 'http://myPersonalMemsource.com';
$api = new Memsource(null, $customServerURL);
$expected = $customServerURL . '/oauth/authorize?response_type=code&client_id=id&redirect_uri=http%3A%2F%2Furi&scope=openid';
$memsourceUrl = $api->oauth()->getAuthorizationCodeUrl('id', 'http://uri');
$this->assertEquals(
$expected,
$memsourceUrl
);
}
public function testGetAccessTokenExceptionOnFakeCode()
{
$api = new Memsource();
$this->expectException(\Exception::class);
$token = $api->oauth()->getAccessToken('fakeCode', 'fakeId', 'fakePass', 'http://any');
}
public function testGetAccessTokenExceptionOnEmptyCode()
{
$api = new Memsource();
$this->expectException(\Exception::class);
$token = $api->oauth()->getAccessToken('', '', '', '');
}
}

21
tests/projectTest.php Normal file
View File

@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use BrunoFontes\Memsource;
final class ProjectTest extends TestCase
{
public function testNoTokenShouldThrowError()
{
$api = new Memsource('fakeToken');
$this->expectException(\Exception::class);
$api->project()->list();
}
public function testInvalidProjectUidShouldThrowError()
{
$api = new Memsource('fakeToken');
$this->expectException(\Exception::class);
$api->project()->get('invalidProjectUid');
}
}