102 lines
2.6 KiB
PHP
102 lines
2.6 KiB
PHP
<?php
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use App\Api\PorkbunAPI;
|
|
|
|
class PorkbunAPITest extends TestCase
|
|
{
|
|
private string $tmpConfig;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->tmpConfig = tempnam(sys_get_temp_dir(), 'cfg_');
|
|
file_put_contents($this->tmpConfig, json_encode([
|
|
"url" => "https://example.com/api/",
|
|
"apikey" => "TESTKEY",
|
|
"secretapikey" => "TESTSECRET"
|
|
]));
|
|
}
|
|
|
|
public function testPingBuildsCorrectEndpointAndReturnsValue()
|
|
{
|
|
$api = $this->getMockBuilder(PorkbunAPI::class)
|
|
->setConstructorArgs([$this->tmpConfig])
|
|
->onlyMethods(['ping'])
|
|
->getMock();
|
|
|
|
$api->expects($this->once())
|
|
->method('ping')
|
|
->willReturn('{"status":"SUCCESS"}');
|
|
|
|
$this->assertSame('{"status":"SUCCESS"}', $api->ping());
|
|
}
|
|
|
|
public function testCreateReturnsExpectedValue()
|
|
{
|
|
$api = $this->getMockBuilder(PorkbunAPI::class)
|
|
->setConstructorArgs([$this->tmpConfig])
|
|
->onlyMethods(['create'])
|
|
->getMock();
|
|
|
|
$api->expects($this->once())
|
|
->method('create')
|
|
->with("example.com", "www", "A", "1.2.3.4", 600)
|
|
->willReturn('{"status":"CREATED"}');
|
|
|
|
$result = $api->create("example.com", "www", "A", "1.2.3.4", 600);
|
|
|
|
$this->assertSame('{"status":"CREATED"}', $result);
|
|
}
|
|
|
|
public function testEditReturnsExpectedValue()
|
|
{
|
|
$api = $this->getMockBuilder(PorkbunAPI::class)
|
|
->setConstructorArgs([$this->tmpConfig])
|
|
->onlyMethods(['edit'])
|
|
->getMock();
|
|
|
|
$api->expects($this->once())
|
|
->method('edit')
|
|
->with("example.com", "123", "5.6.7.8", "www")
|
|
->willReturn('{"status":"EDITED"}');
|
|
|
|
$result = $api->edit("example.com", "123", "5.6.7.8", "www");
|
|
|
|
$this->assertSame('{"status":"EDITED"}', $result);
|
|
}
|
|
|
|
public function testRetrieveReturnsExpectedValue()
|
|
{
|
|
$api = $this->getMockBuilder(PorkbunAPI::class)
|
|
->setConstructorArgs([$this->tmpConfig])
|
|
->onlyMethods(['retrieve'])
|
|
->getMock();
|
|
|
|
$api->expects($this->once())
|
|
->method('retrieve')
|
|
->with("example.com", null)
|
|
->willReturn('{"records":[1,2,3]}');
|
|
|
|
$result = $api->retrieve("example.com");
|
|
|
|
$this->assertSame('{"records":[1,2,3]}', $result);
|
|
}
|
|
|
|
public function testRetrieveByNameTypeReturnsExpectedValue()
|
|
{
|
|
$api = $this->getMockBuilder(PorkbunAPI::class)
|
|
->setConstructorArgs([$this->tmpConfig])
|
|
->onlyMethods(['retrieveByNameType'])
|
|
->getMock();
|
|
|
|
$api->expects($this->once())
|
|
->method('retrieveByNameType')
|
|
->with("example.com", "A", "www")
|
|
->willReturn('{"records":["A","B"]}');
|
|
|
|
$result = $api->retrieveByNameType("example.com", "A", "www");
|
|
|
|
$this->assertSame('{"records":["A","B"]}', $result);
|
|
}
|
|
}
|