add availability tests
This commit is contained in:
parent
96551718bc
commit
bce2e201a3
11
phpunit.xml
11
phpunit.xml
@ -13,8 +13,13 @@
|
|||||||
<clover outputFile="build/logs/clover.xml"/>
|
<clover outputFile="build/logs/clover.xml"/>
|
||||||
</report>
|
</report>
|
||||||
</coverage>
|
</coverage>
|
||||||
<testsuite name="KlicktippPhpClient">
|
<testsuites>
|
||||||
<directory>./tests</directory>
|
<testsuite name="unit">
|
||||||
</testsuite>
|
<directory>./tests/unit</directory>
|
||||||
|
</testsuite>
|
||||||
|
<testsuite name="integration">
|
||||||
|
<directory>./tests/integration</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
<logging/>
|
<logging/>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
@ -9,3 +9,10 @@ composer create-project -s dev --prefer-source [--repository '{"type": "vcs", "u
|
|||||||
```
|
```
|
||||||
./vendor/bin/phpunit [--no-coverage] [--coverage-html coverage]
|
./vendor/bin/phpunit [--no-coverage] [--coverage-html coverage]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Test interface availability
|
||||||
|
|
||||||
|
These are not code tests. This call checks the accessibility and availability of the interface endpoints. The account login details are requested to perform these tests.
|
||||||
|
```
|
||||||
|
./vendor/bin/phpunit --no-coverage ~/KlicktippApi/tests/availability/
|
||||||
|
```
|
39
tests/availability/AccountTest.php
Normal file
39
tests/availability/AccountTest.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*
|
||||||
|
* https://www.d3data.de
|
||||||
|
*
|
||||||
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||||
|
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||||
|
* @link https://www.oxidmodule.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace D3\KlicktippPhpClient\tests\availability;
|
||||||
|
|
||||||
|
use D3\KlicktippPhpClient\Resources\Account;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @coversNothing
|
||||||
|
*/
|
||||||
|
class AccountTest extends AvailabilityTestCase
|
||||||
|
{
|
||||||
|
public function testFields(): void
|
||||||
|
{
|
||||||
|
$klicktipp = $this->getKlicktipp();
|
||||||
|
$endpoint = $klicktipp->account();
|
||||||
|
|
||||||
|
$properties = $endpoint->get();
|
||||||
|
$this->assertArrayHasKey(Account::USERNAME, $properties);
|
||||||
|
$this->assertEquals($properties[Account::USERNAME], trim(getenv(AvailabilityTestCase::CLIENT_VAR)));
|
||||||
|
|
||||||
|
$success = $endpoint->logout();
|
||||||
|
$this->assertTrue($success);
|
||||||
|
}
|
||||||
|
}
|
53
tests/availability/AvailabilityTestCase.php
Normal file
53
tests/availability/AvailabilityTestCase.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*
|
||||||
|
* https://www.d3data.de
|
||||||
|
*
|
||||||
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||||
|
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||||
|
* @link https://www.oxidmodule.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace D3\KlicktippPhpClient\tests\availability;
|
||||||
|
|
||||||
|
use D3\KlicktippPhpClient\Connection;
|
||||||
|
use D3\KlicktippPhpClient\Klicktipp;
|
||||||
|
use D3\KlicktippPhpClient\tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @coversNothing
|
||||||
|
*/
|
||||||
|
abstract class AvailabilityTestCase extends TestCase
|
||||||
|
{
|
||||||
|
public const CLIENT_VAR = 'KLICKTIPP_CLIENT_ENV';
|
||||||
|
public const SECRET_VAR = 'KLICKTIPP_SECRET_ENV';
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
if (!strlen((string) getenv('KLICKTIPP_CLIENT_ENV')) || !strlen((string) getenv('KLICKTIPP_SECRET_ENV'))) {
|
||||||
|
fwrite(STDOUT, 'Insert your client key / username: ');
|
||||||
|
$clientKey = fgets(STDIN);
|
||||||
|
putenv(self::CLIENT_VAR.'=' . $clientKey);
|
||||||
|
fwrite(STDOUT, 'Enter your secret / password: ');
|
||||||
|
$secretKey = fgets(STDIN);
|
||||||
|
putenv(self::SECRET_VAR.'=' . $secretKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getKlicktipp(): Klicktipp
|
||||||
|
{
|
||||||
|
return new Klicktipp(
|
||||||
|
getenv(self::CLIENT_VAR),
|
||||||
|
getenv(self::SECRET_VAR)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
64
tests/availability/FieldTest.php
Normal file
64
tests/availability/FieldTest.php
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*
|
||||||
|
* https://www.d3data.de
|
||||||
|
*
|
||||||
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||||
|
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||||
|
* @link https://www.oxidmodule.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace D3\KlicktippPhpClient\tests\availability;
|
||||||
|
|
||||||
|
use D3\KlicktippPhpClient\Exceptions\KlicktippExceptionInterface;
|
||||||
|
use D3\KlicktippPhpClient\Resources\Field;
|
||||||
|
use PHPUnit\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @coversNothing
|
||||||
|
*/
|
||||||
|
class FieldTest extends AvailabilityTestCase
|
||||||
|
{
|
||||||
|
public function testFields(): void
|
||||||
|
{
|
||||||
|
$klicktipp = $this->getKlicktipp();
|
||||||
|
$endpoint = $klicktipp->field();
|
||||||
|
$fieldId = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$fieldId = $endpoint->create('testFieldName');
|
||||||
|
$this->assertNotEmpty($fieldId);
|
||||||
|
|
||||||
|
$properties = $endpoint->get($fieldId);
|
||||||
|
$this->assertArrayHasKey(Field::NAME, $properties);
|
||||||
|
$this->assertEquals($properties[Field::NAME], 'testFieldName');
|
||||||
|
|
||||||
|
$fieldList = $endpoint->index();
|
||||||
|
$this->assertArrayHasKey('field'.$fieldId, $fieldList->toArray());
|
||||||
|
|
||||||
|
$success = $endpoint->update($fieldId, 'updatedTestFieldName');
|
||||||
|
$this->assertTrue($success);
|
||||||
|
|
||||||
|
$success = $endpoint->delete($fieldId);
|
||||||
|
$this->assertTrue($success);
|
||||||
|
|
||||||
|
} catch (KlicktippExceptionInterface|Exception $exception) {
|
||||||
|
if ($fieldId) {
|
||||||
|
if (!$endpoint->delete($fieldId)) {
|
||||||
|
echo "can't delete field with id $fieldId\n";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
throw $exception;
|
||||||
|
} finally {
|
||||||
|
$klicktipp->account()->logout();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
65
tests/availability/TagTest.php
Normal file
65
tests/availability/TagTest.php
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*
|
||||||
|
* https://www.d3data.de
|
||||||
|
*
|
||||||
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||||
|
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||||
|
* @link https://www.oxidmodule.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace D3\KlicktippPhpClient\tests\availability;
|
||||||
|
|
||||||
|
use D3\KlicktippPhpClient\Exceptions\KlicktippExceptionInterface;
|
||||||
|
use D3\KlicktippPhpClient\Resources\Tag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @coversNothing
|
||||||
|
*/
|
||||||
|
class TagTest extends AvailabilityTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
* @throws KlicktippExceptionInterface
|
||||||
|
*/
|
||||||
|
public function testFields(): void
|
||||||
|
{
|
||||||
|
$klicktipp = $this->getKlicktipp();
|
||||||
|
$endpoint = $klicktipp->tag();
|
||||||
|
$tagId = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$tagId = $endpoint->create('testTagName');
|
||||||
|
$this->assertNotEmpty($tagId);
|
||||||
|
|
||||||
|
$properties = $endpoint->get($tagId);
|
||||||
|
$this->assertArrayHasKey(Tag::NAME, $properties);
|
||||||
|
$this->assertEquals('testTagName', $properties[Tag::NAME]);
|
||||||
|
|
||||||
|
$fieldList = $endpoint->index();
|
||||||
|
$this->assertArrayHasKey($tagId, $fieldList->toArray());
|
||||||
|
|
||||||
|
$success = $endpoint->update($tagId, 'updatedTestFieldName');
|
||||||
|
$this->assertTrue($success);
|
||||||
|
|
||||||
|
$success = $endpoint->delete($tagId);
|
||||||
|
$this->assertTrue($success);
|
||||||
|
|
||||||
|
} catch (KlicktippExceptionInterface $exception) {
|
||||||
|
if ($tagId) {
|
||||||
|
if (!$endpoint->delete($tagId)) {
|
||||||
|
echo "can't delete tag with id $tagId\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw $exception;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user