add tests
This commit is contained in:
parent
8e2e69a8ae
commit
4ee05a81cf
@ -23,6 +23,7 @@
|
|||||||
"d3/sensitive-message-formatter": "^1.0"
|
"d3/sensitive-message-formatter": "^1.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^10.5",
|
||||||
"friendsofphp/php-cs-fixer": "^3.65",
|
"friendsofphp/php-cs-fixer": "^3.65",
|
||||||
"phpstan/phpstan": "^2.0"
|
"phpstan/phpstan": "^2.0"
|
||||||
},
|
},
|
||||||
@ -37,6 +38,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"test": "./vendor/bin/phpunit",
|
||||||
"check-style": "./vendor/bin/php-cs-fixer fix --verbose --dry-run",
|
"check-style": "./vendor/bin/php-cs-fixer fix --verbose --dry-run",
|
||||||
"fix-style": "./vendor/bin/php-cs-fixer fix --verbose",
|
"fix-style": "./vendor/bin/php-cs-fixer fix --verbose",
|
||||||
"check-code": "./vendor/bin/phpstan analyse -c phpstan.neon --no-progress --ansi"
|
"check-code": "./vendor/bin/phpstan analyse -c phpstan.neon --no-progress --ansi"
|
||||||
|
20
phpunit.xml
Normal file
20
phpunit.xml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
bootstrap="vendor/autoload.php"
|
||||||
|
convertErrorsToExceptions="true"
|
||||||
|
convertNoticesToExceptions="true"
|
||||||
|
convertWarningsToExceptions="true"
|
||||||
|
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||||
|
<coverage>
|
||||||
|
<include>
|
||||||
|
<directory suffix=".php">src</directory>
|
||||||
|
</include>
|
||||||
|
<report>
|
||||||
|
<clover outputFile="build/logs/clover.xml"/>
|
||||||
|
</report>
|
||||||
|
</coverage>
|
||||||
|
<testsuite name="GuzzleFactory">
|
||||||
|
<directory>./tests</directory>
|
||||||
|
</testsuite>
|
||||||
|
<logging/>
|
||||||
|
</phpunit>
|
75
tests/ApiTestCase.php
Normal file
75
tests/ApiTestCase.php
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
<?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\OxidGuzzleFactory\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 = []): 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): void
|
||||||
|
{
|
||||||
|
$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);
|
||||||
|
}
|
||||||
|
}
|
35
tests/GuzzleFactoryTest.php
Normal file
35
tests/GuzzleFactoryTest.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?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\OxidGuzzleFactory\tests;
|
||||||
|
|
||||||
|
use D3\OxidGuzzleFactory\GuzzleFactory;
|
||||||
|
|
||||||
|
class GuzzleFactoryTest extends ApiTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @return void
|
||||||
|
* @covers \D3\OxidGuzzleFactory\GuzzleFactory::create
|
||||||
|
*/
|
||||||
|
public function testCreate(): void
|
||||||
|
{
|
||||||
|
$instance = GuzzleFactory::create();
|
||||||
|
|
||||||
|
$this->assertInstanceOf(GuzzleFactory::class, $instance);
|
||||||
|
}
|
||||||
|
}
|
11
tests/README.md
Normal file
11
tests/README.md
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# Installation
|
||||||
|
|
||||||
|
```
|
||||||
|
composer create-project -s dev --prefer-source [--repository '{"type": "vcs", "url": "repository url"}'] d3/guzzle-factory .
|
||||||
|
```
|
||||||
|
|
||||||
|
# Run tests
|
||||||
|
|
||||||
|
```
|
||||||
|
./vendor/bin/phpunit [--no-coverage] [--coverage-html=cov]
|
||||||
|
```
|
Loading…
x
Reference in New Issue
Block a user