add availability tests

This commit is contained in:
Daniel Seifert 2025-01-09 10:48:38 +01:00
parent 96551718bc
commit bce2e201a3
6 changed files with 236 additions and 3 deletions

View File

@ -13,8 +13,13 @@
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<testsuite name="KlicktippPhpClient">
<directory>./tests</directory>
</testsuite>
<testsuites>
<testsuite name="unit">
<directory>./tests/unit</directory>
</testsuite>
<testsuite name="integration">
<directory>./tests/integration</directory>
</testsuite>
</testsuites>
<logging/>
</phpunit>

View File

@ -9,3 +9,10 @@ composer create-project -s dev --prefer-source [--repository '{"type": "vcs", "u
```
./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/
```

View 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);
}
}

View 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)
);
}
}

View 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();
}
}
}

View 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;
}
}
}