add tests structure

This commit is contained in:
Daniel Seifert 2022-07-09 22:16:46 +02:00
parent 8411ed0786
commit 740b14f868
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
5 changed files with 125 additions and 2 deletions

60
Tests/ApiTestCase.php Normal file
View File

@ -0,0 +1,60 @@
<?php
namespace D3\LinkmobilityClient\Tests;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use ReflectionException;
abstract class ApiTestCase extends TestCase
{
/**
* Calls a private or protected object method.
*
* @param object $object
* @param string $methodName
* @param array $arguments
*
* @return mixed
* @throws ReflectionException
*/
public function callMethod(object $object, string $methodName, array $arguments = array()): mixed
{
$class = new ReflectionClass($object);
$method = $class->getMethod($methodName);
$method->setAccessible(true);
return $method->invokeArgs($object, $arguments);
}
/**
* Sets a private or protected property in defined class instance
*
* @param object $object
* @param string $valueName
* @param $value
* @throws ReflectionException
*/
public function setValue(object $object, string $valueName, $value)
{
$reflection = new ReflectionClass($object);
$property = $reflection->getProperty($valueName);
$property->setAccessible(true);
$property->setValue($object, $value);
}
/**
* get a private or protected property from defined class instance
*
* @param object $object
* @param string $valueName
* @return mixed
* @throws ReflectionException
*/
public function getValue(object $object, string $valueName): mixed
{
$reflection = new ReflectionClass($object);
$property = $reflection->getProperty($valueName);
$property->setAccessible(true);
return $property->getValue($object);
}
}

28
Tests/ClientTest.php Normal file
View File

@ -0,0 +1,28 @@
<?php
namespace D3\LinkmobilityClient\Tests;
use D3\LinkmobilityClient\Client;
class ApiClientTest extends ApiTestCase
{
public string $fixtureApiKey = 'fixtureApiKey';
/** @var ApiClient */
public Client $api;
public string $jsonFixture = 'json_content';
public function setUp():void
{
parent::setUp();
$this->api = new Client($this->fixtureApiKey);
}
/**
* @test
*/
public function testRun()
{
$this->assertTrue(true);
}
}

11
Tests/README.md Normal file
View File

@ -0,0 +1,11 @@
# Installation
```
composer create-project -s dev --prefer-source --repository="{\"url\": \"gitfhfac@git.d3data.de:D3Private/linkmobility-php-client.git\", \"type\": \"vcs\"}" d3/linkmobility-php-client .
```
# Run tests
```
./vendor/bin/phpunit [--no-coverage]
```

View File

@ -28,12 +28,14 @@
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit" : "~5.7||~6.0",
"php": "^7.2",
"phpunit/phpunit" : "^8.0",
"friendsofphp/php-cs-fixer": "^2.0"
},
"autoload": {
"psr-4": {
"D3\\LinkmobilityClient\\": "src"
"D3\\LinkmobilityClient\\": "src",
"D3\\LinkmobilityClient\\Tests\\": "Tests"
}
},
"scripts": {

22
phpunit.xml Normal file
View File

@ -0,0 +1,22 @@
<phpunit
bootstrap="vendor/autoload.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true">
<testsuite name="tankerkoenig">
<directory>./Tests</directory>
</testsuite>
<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</phpunit>