-
Notifications
You must be signed in to change notification settings - Fork 182
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
4 changed files
with
168 additions
and
0 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
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,77 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VonageTest\Client\Response; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Vonage\Client\Response\AbstractResponse; | ||
|
||
class AbstractResponseTest extends TestCase | ||
{ | ||
public function testGetDataReturnsCorrectData() | ||
{ | ||
$mock = $this->getMockForAbstractClass(AbstractResponse::class); | ||
|
||
$reflection = new \ReflectionClass($mock); | ||
$property = $reflection->getProperty('data'); | ||
$property->setAccessible(true); | ||
|
||
$testData = ['key' => 'value']; | ||
$property->setValue($mock, $testData); | ||
|
||
$this->assertSame($testData, $mock->getData()); | ||
} | ||
|
||
public function testIsSuccessReturnsTrueWhenStatusIsZero() | ||
{ | ||
$mock = $this->getMockForAbstractClass(AbstractResponse::class); | ||
|
||
$reflection = new \ReflectionClass($mock); | ||
$property = $reflection->getProperty('data'); | ||
$property->setAccessible(true); | ||
|
||
$property->setValue($mock, ['status' => 0]); | ||
|
||
$this->assertTrue($mock->isSuccess()); | ||
} | ||
|
||
public function testIsSuccessReturnsFalseWhenStatusIsNotZero() | ||
{ | ||
$mock = $this->getMockForAbstractClass(AbstractResponse::class); | ||
|
||
$reflection = new \ReflectionClass($mock); | ||
$property = $reflection->getProperty('data'); | ||
$property->setAccessible(true); | ||
|
||
$property->setValue($mock, ['status' => 1]); | ||
|
||
$this->assertFalse($mock->isSuccess()); | ||
} | ||
|
||
public function testIsErrorReturnsTrueWhenStatusIsNotZero() | ||
{ | ||
$mock = $this->getMockForAbstractClass(AbstractResponse::class); | ||
|
||
$reflection = new \ReflectionClass($mock); | ||
$property = $reflection->getProperty('data'); | ||
$property->setAccessible(true); | ||
|
||
$property->setValue($mock, ['status' => 1]); | ||
|
||
$this->assertTrue($mock->isError()); | ||
} | ||
|
||
public function testIsErrorReturnsFalseWhenStatusIsZero() | ||
{ | ||
$mock = $this->getMockForAbstractClass(AbstractResponse::class); | ||
|
||
$reflection = new \ReflectionClass($mock); | ||
$property = $reflection->getProperty('data'); | ||
$property->setAccessible(true); | ||
|
||
$property->setValue($mock, ['status' => 0]); | ||
|
||
$this->assertFalse($mock->isError()); | ||
} | ||
} |
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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VonageTest\Client\Response; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Vonage\Client\Response\Error; | ||
|
||
class ErrorTest extends TestCase | ||
{ | ||
public function testErrorInstance(): void | ||
{ | ||
$data = [ | ||
'status' => '400', | ||
'error_text' => 'Invalid request' | ||
]; | ||
|
||
$error = new Error($data); | ||
|
||
$this->assertInstanceOf(Error::class, $error); | ||
$this->assertTrue($error->isError()); | ||
$this->assertFalse($error->isSuccess()); | ||
$this->assertEquals(400, $error->getCode()); | ||
$this->assertEquals('Invalid request', $error->getMessage()); | ||
} | ||
|
||
public function testErrorTextNormalization(): void | ||
{ | ||
$data = [ | ||
'status' => '500', | ||
'error_text' => 'Internal Server Error' | ||
]; | ||
|
||
$error = new Error($data); | ||
|
||
$this->assertEquals(500, $error->getCode()); | ||
$this->assertEquals('Internal Server Error', $error->getMessage()); | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VonageTest\Client\Response; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Vonage\Client\Response\Response; | ||
use RuntimeException; | ||
|
||
class ResponseTest extends TestCase | ||
{ | ||
public function testConstructorWithExpectedKeys() | ||
{ | ||
$stub = new class(['key1' => 'value1', 'key2' => 'value2']) extends Response { | ||
protected $expected = ['key1', 'key2']; | ||
}; | ||
|
||
$this->assertInstanceOf(Response::class, $stub); | ||
} | ||
|
||
public function testConstructorThrowsExceptionOnMissingKeys() | ||
{ | ||
$this->expectException(RuntimeException::class); | ||
$this->expectExceptionMessage('missing expected response keys: key2'); | ||
|
||
new class(['key1' => 'value1']) extends Response { | ||
protected $expected = ['key1', 'key2']; | ||
}; | ||
} | ||
} |