Skip to content
This repository was archived by the owner on Jul 2, 2021. It is now read-only.

Commit ed97ff6

Browse files
authored
#3 & #4 - Improve testing, Change configuration-behavior to follow default (#6)
* Resolves #4 - Change configuration-behavior to follow default * Resolves #3 - Improve testing
1 parent 8939f86 commit ed97ff6

23 files changed

+388
-194
lines changed

.coveralls.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
coverage_clover: build/logs/clover.xml
2+
service_name: travis-pro

.gitignore

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
tests/var/cache/*
2-
!tests/var/cache/.gitkeep
3-
tests/var/logs/*
4-
!tests/var/logs/.gitkeep
5-
vendor/
1+
/build/
2+
/vendor/
63

74
.php_cs.cache
85
composer.lock

.travis.yml

+22-32
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,36 @@ cache:
88
matrix:
99
fast_finish: true
1010
include:
11-
- php: 5.6
12-
env: SYMFONY_VERSION=2.7.*
13-
- php: 5.6
14-
env: SYMFONY_VERSION=2.8.*
15-
- php: 5.6
16-
env: SYMFONY_VERSION=3.4.*
17-
- php: 7.0
18-
env: SYMFONY_VERSION=2.7.*
19-
- php: 7.0
20-
env: SYMFONY_VERSION=2.8.*
21-
- php: 7.0
22-
env: SYMFONY_VERSION=3.4.*
23-
- php: 7.1
24-
env: SYMFONY_VERSION=2.7.*
25-
- php: 7.1
26-
env: SYMFONY_VERSION=2.8.*
27-
- php: 7.1
28-
env: SYMFONY_VERSION=3.4.*
29-
- php: 7.1
30-
env: SYMFONY_VERSION=4.0.*
31-
- php: 7.2
32-
env: SYMFONY_VERSION=2.7.*
33-
- php: 7.2
34-
env: SYMFONY_VERSION=2.8.*
35-
- php: 7.2
36-
env: SYMFONY_VERSION=3.4.*
37-
- php: 7.2
38-
env: SYMFONY_VERSION=4.0.*
11+
- php: 7.1
12+
env: SYMFONY_VERSION=2.8.*
13+
- php: 7.1
14+
env: SYMFONY_VERSION=3.4.*
15+
- php: 7.1
16+
env: SYMFONY_VERSION=4.0.*
17+
- php: 7.1
18+
env: SYMFONY_VERSION=4.1.*
19+
- php: 7.2
20+
env: SYMFONY_VERSION=2.8.*
21+
- php: 7.2
22+
env: SYMFONY_VERSION=3.4.*
23+
- php: 7.2
24+
env: SYMFONY_VERSION=4.0.*
25+
- php: 7.2
26+
env: SYMFONY_VERSION=4.1.*
3927

4028
before_install:
41-
- phpenv config-rm xdebug.ini || echo "xdebug not available";
4229
- echo "memory_limit=1G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini;
4330

4431
install:
4532
- if [ "$SYMFONY_VERSION" != "" ]; then composer require --dev --no-update "symfony/framework-bundle:${SYMFONY_VERSION}"; fi;
4633
- composer install --no-interaction
4734

4835
before_script:
49-
- wget http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar -O php-cs-fixer && chmod +x php-cs-fixer
36+
- mkdir -p build/logs/
5037

5138
script:
52-
- "./vendor/bin/phpunit -c phpunit.dist.xml"
53-
- "./php-cs-fixer fix --diff --dry-run --no-interaction -v"
39+
- ./vendor/bin/phpunit -c phpunit.dist.xml
40+
- ./vendor/bin/php-cs-fixer fix --diff --dry-run --no-interaction -v
41+
42+
after_success:
43+
- travis_retry php vendor/bin/php-coveralls

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# INWX Service Provider for Symfony
22

3-
[![Build Status](https://travis-ci.com/SebTM/inwx-api-bundle.svg?branch=master)](https://travis-ci.com/SebTM/inwx-api-bundle)[![Total Downloads](https://img.shields.io/packagist/dt/SebTM/inwx-api-bundle.svg)](https://packagist.org/packages/SebTM/inwx-api-bundle)
3+
[![Build Status](https://travis-ci.com/SebTM/inwx-api-bundle.svg?branch=master)](https://travis-ci.com/SebTM/inwx-api-bundle)
4+
[![Coverage Status](https://coveralls.io/repos/github/SebTM/inwx-api-bundle/badge.svg)](https://coveralls.io/github/SebTM/inwx-api-bundle)
5+
[![Total Downloads](https://img.shields.io/packagist/dt/SebTM/inwx-api-bundle.svg)](https://packagist.org/packages/SebTM/inwx-api-bundle)
46
[![GitHub license](https://img.shields.io/github/license/SebTM/inwx-api-bundle.svg)](https://github.com/SebTM/inwx-api-bundle/blob/master/LICENSE.md)
57

68
A Symfony bundle for including the [INWX PHP-Client](https://github.com/inwx/php-client).
@@ -13,7 +15,7 @@ requiring the `sebtm/inwx-api-bundle` package in your project's `composer.json`:
1315
```json
1416
{
1517
"require": {
16-
"sebtm/inwx-api-bundle": "~0.1"
18+
"sebtm/inwx-api-bundle": "~0.2"
1719
}
1820
}
1921
```

composer.json

+9-5
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@
1212
}
1313
],
1414
"require": {
15-
"php": ">=5.6",
16-
"inwx/domrobot": "^2.4"
15+
"php": ">=7.1",
16+
"inwx/domrobot": "^2.4",
17+
"symfony/config": "^2.8|^3.4|^4.0|^4.1",
18+
"symfony/http-kernel": "^2.8|^3.4|^4.0|^4.1",
19+
"symfony/yaml": "^2.8|^3.4|^4.0|^4.1"
1720
},
1821
"require-dev": {
19-
"symfony/framework-bundle": "^2.7|^2.8|^3.4|^4.0",
20-
"symfony/yaml": "^2.7|^2.8|^3.4|^4.0",
21-
"phpunit/phpunit": "^5.7|^6.5|^7.0"
22+
"friendsofphp/php-cs-fixer": "^2.12",
23+
"matthiasnoback/symfony-dependency-injection-test": "^3.0",
24+
"php-coveralls/php-coveralls": "^2.1",
25+
"phpunit/phpunit": "^7.2"
2226
},
2327
"autoload": {
2428
"psr-4": {

phpunit.dist.xml

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/7.0/phpunit.xsd"
3+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/7.2/phpunit.xsd"
44
backupGlobals="false"
55
colors="true"
66
>
7-
<php>
8-
<ini name="error_reporting" value="-1" />
9-
<ini name="display_errors" value="On" />
10-
<ini name="display_startup_errors" value="On" />
11-
<ini name="date.timezone" value="Europe/Berlin" />
12-
<env name="APP_ENV" value="test" />
13-
<env name="APP_DEBUG" value="1" />
14-
</php>
7+
<filter>
8+
<whitelist>
9+
<directory>./src/</directory>
10+
</whitelist>
11+
</filter>
12+
13+
<logging>
14+
<log type="coverage-clover" target="build/logs/clover.xml" />
15+
</logging>
1516

1617
<testsuites>
1718
<testsuite name="INWX-Api-Bundle tests">
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace SebTM\INWX\DependencyInjection;
4+
5+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6+
use Symfony\Component\Config\Definition\ConfigurationInterface;
7+
8+
class Configuration implements ConfigurationInterface
9+
{
10+
/**
11+
* @return TreeBuilder
12+
*/
13+
public function getConfigTreeBuilder(): TreeBuilder
14+
{
15+
$treeBuilder = new TreeBuilder();
16+
$rootNode = $treeBuilder->root('inwx_api');
17+
18+
$rootNode
19+
->children()
20+
->enumNode('environment')
21+
->values(
22+
array(
23+
'production',
24+
'test',
25+
)
26+
)
27+
->defaultValue('test')
28+
->end()
29+
->scalarNode('username')
30+
->isRequired()
31+
->end()
32+
->scalarNode('password')
33+
->isRequired()
34+
->end()
35+
->scalarNode('language')
36+
->defaultValue('en')
37+
->end()
38+
->booleanNode('debug')
39+
->defaultFalse()
40+
->end()
41+
->end();
42+
43+
return $treeBuilder;
44+
}
45+
}

src/DependencyInjection/InwxApiExtension.php

+6-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace SebTM\INWX\DependencyInjection;
44

5-
use SebTM\INWX\Exception\InvalidConfigurationException;
65
use Symfony\Component\Config\FileLocator;
76
use Symfony\Component\DependencyInjection\ContainerBuilder;
87
use Symfony\Component\DependencyInjection\Extension\Extension;
@@ -14,26 +13,17 @@ class InwxApiExtension extends Extension
1413
* @param array $configs
1514
* @param ContainerBuilder $container
1615
*
17-
* @throws \Exception Error occurred while parsing "services.yml"
18-
* @throws InvalidConfigurationException Missing environment-variable to construct a client-instance
16+
* @throws \Exception Error occurred while parsing "services.yml"
1917
*/
2018
public function load(array $configs, ContainerBuilder $container)
2119
{
22-
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config/'));
23-
$loader->load('services.yml');
20+
$configuration = new Configuration();
21+
$config = $this->processConfiguration($configuration, $configs);
2422

25-
$config = array(
26-
'environment' => \getenv('INWX_API_ENVIRONMENT'),
27-
'username' => \getenv('INWX_API_USERNAME'),
28-
'password' => \getenv('INWX_API_PASSWORD'),
29-
'language' => \getenv('INWX_API_LANGUAGE'),
30-
'debug' => \filter_var(\getenv('INWX_API_DEBUG'), FILTER_VALIDATE_BOOLEAN),
31-
);
23+
$container->setParameter('inwx_api', $config);
3224

33-
$validate = \array_search(false, $config, true);
34-
if (false !== $validate && 'debug' !== $validate) {
35-
throw new InvalidConfigurationException();
36-
}
25+
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config/'));
26+
$loader->load('services.yml');
3727

3828
$definition = $container->getDefinition('inwx_api');
3929
$definition->replaceArgument(0, $config['environment']);

src/Domrobot.php

+52-15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace SebTM\INWX;
44

55
use INWX\Domrobot as BaseDomrobot;
6+
use SebTM\INWX\Exception\LoginUnsuccessfulException;
7+
use SebTM\INWX\Exception\UnsupportedEnvironmentException;
68

79
class Domrobot extends BaseDomrobot
810
{
@@ -11,51 +13,86 @@ class Domrobot extends BaseDomrobot
1113
*/
1214
protected $environment;
1315

16+
/**
17+
* @var string
18+
*/
19+
protected $username;
20+
21+
/**
22+
* @var string
23+
*/
24+
protected $password;
25+
1426
/**
1527
* @param string $environment
1628
* @param string $username
1729
* @param string $password
1830
* @param string $language
1931
* @param bool $debug
2032
*
21-
* @throws \Exception
33+
* @throws UnsupportedEnvironmentException
2234
*/
2335
public function __construct($environment, $username, $password, $language = 'en', $debug = false)
2436
{
2537
$this->environment = $environment;
26-
parent::__construct($this->getAddress($environment));
38+
$this->username = $username;
39+
$this->password = $password;
40+
41+
parent::__construct($this->getApiUrl());
2742

2843
$this->setLanguage($language);
2944
$this->setDebug($debug);
30-
$this->login($username, $password);
3145
}
3246

3347
/**
48+
* @throws UnsupportedEnvironmentException
49+
*
3450
* @return string
3551
*/
36-
public function getEnvironment()
52+
public function getApiUrl(): string
53+
{
54+
switch ($this->environment) {
55+
case 'production':
56+
return 'https://api.domrobot.com/xmlrpc/';
57+
58+
case 'test':
59+
return 'https://api.ote.domrobot.com/xmlrpc/';
60+
61+
default:
62+
throw new UnsupportedEnvironmentException();
63+
}
64+
}
65+
66+
/**
67+
* @return string
68+
*/
69+
public function getEnvironment(): string
3770
{
3871
return $this->environment;
3972
}
4073

4174
/**
42-
* @param string $environment
75+
* @param null|string $username Should not be set to use values from DI - must have method signature compatible
76+
* @param null|string $password Should not be set to use values from DI - must have method signature compatible
77+
* @param null|string $sharedSecret
4378
*
44-
* @throws \Exception Unsupported environment
79+
* @throws LoginUnsuccessfulException
4580
*
46-
* @return string
81+
* @return bool
4782
*/
48-
protected function getAddress($environment)
83+
public function login($username = null, $password = null, $sharedSecret = null): bool
4984
{
50-
switch ($environment) {
51-
case 'production':
52-
return ' https://api.domrobot.com/xmlrpc/';
85+
if (null === $username && null === $password) {
86+
$username = $this->username;
87+
$password = $this->password;
88+
}
5389

54-
case 'test':
55-
return 'https://api.ote.domrobot.com/xmlrpc/';
90+
$result = parent::login($username, $password, $sharedSecret);
5691

57-
default:
58-
throw new \Exception('Unsupported environment!');
92+
if (1000 === $result['code']) {
93+
return true;
5994
}
95+
96+
throw new LoginUnsuccessfulException();
6097
}
6198
}

src/Exception/InvalidConfigurationException.php

-11
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace SebTM\INWX\Exception;
4+
5+
class LoginUnsuccessfulException extends \Exception
6+
{
7+
/**
8+
* @var string
9+
*/
10+
protected $message = 'Login using "inwx-api-bundle" was unsuccessful!';
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace SebTM\INWX\Exception;
4+
5+
class UnsupportedEnvironmentException extends \Exception
6+
{
7+
/**
8+
* @var string
9+
*/
10+
protected $message = 'Unsupported environment given for "sebtm/inwx-api-bundle"!';
11+
}

0 commit comments

Comments
 (0)