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

Commit

Permalink
#3 & #4 - Improve testing, Change configuration-behavior to follow de…
Browse files Browse the repository at this point in the history
…fault (#6)

* Resolves #4 - Change configuration-behavior to follow default
* Resolves #3 - Improve testing
  • Loading branch information
SebTM authored Jul 23, 2018
1 parent 8939f86 commit ed97ff6
Show file tree
Hide file tree
Showing 23 changed files with 388 additions and 194 deletions.
2 changes: 2 additions & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage_clover: build/logs/clover.xml
service_name: travis-pro
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
tests/var/cache/*
!tests/var/cache/.gitkeep
tests/var/logs/*
!tests/var/logs/.gitkeep
vendor/
/build/
/vendor/

.php_cs.cache
composer.lock
Expand Down
54 changes: 22 additions & 32 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,36 @@ cache:
matrix:
fast_finish: true
include:
- php: 5.6
env: SYMFONY_VERSION=2.7.*
- php: 5.6
env: SYMFONY_VERSION=2.8.*
- php: 5.6
env: SYMFONY_VERSION=3.4.*
- php: 7.0
env: SYMFONY_VERSION=2.7.*
- php: 7.0
env: SYMFONY_VERSION=2.8.*
- php: 7.0
env: SYMFONY_VERSION=3.4.*
- php: 7.1
env: SYMFONY_VERSION=2.7.*
- php: 7.1
env: SYMFONY_VERSION=2.8.*
- php: 7.1
env: SYMFONY_VERSION=3.4.*
- php: 7.1
env: SYMFONY_VERSION=4.0.*
- php: 7.2
env: SYMFONY_VERSION=2.7.*
- php: 7.2
env: SYMFONY_VERSION=2.8.*
- php: 7.2
env: SYMFONY_VERSION=3.4.*
- php: 7.2
env: SYMFONY_VERSION=4.0.*
- php: 7.1
env: SYMFONY_VERSION=2.8.*
- php: 7.1
env: SYMFONY_VERSION=3.4.*
- php: 7.1
env: SYMFONY_VERSION=4.0.*
- php: 7.1
env: SYMFONY_VERSION=4.1.*
- php: 7.2
env: SYMFONY_VERSION=2.8.*
- php: 7.2
env: SYMFONY_VERSION=3.4.*
- php: 7.2
env: SYMFONY_VERSION=4.0.*
- php: 7.2
env: SYMFONY_VERSION=4.1.*

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

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

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

script:
- "./vendor/bin/phpunit -c phpunit.dist.xml"
- "./php-cs-fixer fix --diff --dry-run --no-interaction -v"
- ./vendor/bin/phpunit -c phpunit.dist.xml
- ./vendor/bin/php-cs-fixer fix --diff --dry-run --no-interaction -v

after_success:
- travis_retry php vendor/bin/php-coveralls
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# INWX Service Provider for Symfony

[![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)
[![Build Status](https://travis-ci.com/SebTM/inwx-api-bundle.svg?branch=master)](https://travis-ci.com/SebTM/inwx-api-bundle)
[![Coverage Status](https://coveralls.io/repos/github/SebTM/inwx-api-bundle/badge.svg)](https://coveralls.io/github/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)
[![GitHub license](https://img.shields.io/github/license/SebTM/inwx-api-bundle.svg)](https://github.com/SebTM/inwx-api-bundle/blob/master/LICENSE.md)

A Symfony bundle for including the [INWX PHP-Client](https://github.com/inwx/php-client).
Expand All @@ -13,7 +15,7 @@ requiring the `sebtm/inwx-api-bundle` package in your project's `composer.json`:
```json
{
"require": {
"sebtm/inwx-api-bundle": "~0.1"
"sebtm/inwx-api-bundle": "~0.2"
}
}
```
Expand Down
14 changes: 9 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
}
],
"require": {
"php": ">=5.6",
"inwx/domrobot": "^2.4"
"php": ">=7.1",
"inwx/domrobot": "^2.4",
"symfony/config": "^2.8|^3.4|^4.0|^4.1",
"symfony/http-kernel": "^2.8|^3.4|^4.0|^4.1",
"symfony/yaml": "^2.8|^3.4|^4.0|^4.1"
},
"require-dev": {
"symfony/framework-bundle": "^2.7|^2.8|^3.4|^4.0",
"symfony/yaml": "^2.7|^2.8|^3.4|^4.0",
"phpunit/phpunit": "^5.7|^6.5|^7.0"
"friendsofphp/php-cs-fixer": "^2.12",
"matthiasnoback/symfony-dependency-injection-test": "^3.0",
"php-coveralls/php-coveralls": "^2.1",
"phpunit/phpunit": "^7.2"
},
"autoload": {
"psr-4": {
Expand Down
19 changes: 10 additions & 9 deletions phpunit.dist.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/7.0/phpunit.xsd"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/7.2/phpunit.xsd"
backupGlobals="false"
colors="true"
>
<php>
<ini name="error_reporting" value="-1" />
<ini name="display_errors" value="On" />
<ini name="display_startup_errors" value="On" />
<ini name="date.timezone" value="Europe/Berlin" />
<env name="APP_ENV" value="test" />
<env name="APP_DEBUG" value="1" />
</php>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>

<logging>
<log type="coverage-clover" target="build/logs/clover.xml" />
</logging>

<testsuites>
<testsuite name="INWX-Api-Bundle tests">
Expand Down
45 changes: 45 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace SebTM\INWX\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
/**
* @return TreeBuilder
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('inwx_api');

$rootNode
->children()
->enumNode('environment')
->values(
array(
'production',
'test',
)
)
->defaultValue('test')
->end()
->scalarNode('username')
->isRequired()
->end()
->scalarNode('password')
->isRequired()
->end()
->scalarNode('language')
->defaultValue('en')
->end()
->booleanNode('debug')
->defaultFalse()
->end()
->end();

return $treeBuilder;
}
}
22 changes: 6 additions & 16 deletions src/DependencyInjection/InwxApiExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace SebTM\INWX\DependencyInjection;

use SebTM\INWX\Exception\InvalidConfigurationException;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
Expand All @@ -14,26 +13,17 @@ class InwxApiExtension extends Extension
* @param array $configs
* @param ContainerBuilder $container
*
* @throws \Exception Error occurred while parsing "services.yml"
* @throws InvalidConfigurationException Missing environment-variable to construct a client-instance
* @throws \Exception Error occurred while parsing "services.yml"
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config/'));
$loader->load('services.yml');
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$config = array(
'environment' => \getenv('INWX_API_ENVIRONMENT'),
'username' => \getenv('INWX_API_USERNAME'),
'password' => \getenv('INWX_API_PASSWORD'),
'language' => \getenv('INWX_API_LANGUAGE'),
'debug' => \filter_var(\getenv('INWX_API_DEBUG'), FILTER_VALIDATE_BOOLEAN),
);
$container->setParameter('inwx_api', $config);

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

$definition = $container->getDefinition('inwx_api');
$definition->replaceArgument(0, $config['environment']);
Expand Down
67 changes: 52 additions & 15 deletions src/Domrobot.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace SebTM\INWX;

use INWX\Domrobot as BaseDomrobot;
use SebTM\INWX\Exception\LoginUnsuccessfulException;
use SebTM\INWX\Exception\UnsupportedEnvironmentException;

class Domrobot extends BaseDomrobot
{
Expand All @@ -11,51 +13,86 @@ class Domrobot extends BaseDomrobot
*/
protected $environment;

/**
* @var string
*/
protected $username;

/**
* @var string
*/
protected $password;

/**
* @param string $environment
* @param string $username
* @param string $password
* @param string $language
* @param bool $debug
*
* @throws \Exception
* @throws UnsupportedEnvironmentException
*/
public function __construct($environment, $username, $password, $language = 'en', $debug = false)
{
$this->environment = $environment;
parent::__construct($this->getAddress($environment));
$this->username = $username;
$this->password = $password;

parent::__construct($this->getApiUrl());

$this->setLanguage($language);
$this->setDebug($debug);
$this->login($username, $password);
}

/**
* @throws UnsupportedEnvironmentException
*
* @return string
*/
public function getEnvironment()
public function getApiUrl(): string
{
switch ($this->environment) {
case 'production':
return 'https://api.domrobot.com/xmlrpc/';

case 'test':
return 'https://api.ote.domrobot.com/xmlrpc/';

default:
throw new UnsupportedEnvironmentException();
}
}

/**
* @return string
*/
public function getEnvironment(): string
{
return $this->environment;
}

/**
* @param string $environment
* @param null|string $username Should not be set to use values from DI - must have method signature compatible
* @param null|string $password Should not be set to use values from DI - must have method signature compatible
* @param null|string $sharedSecret
*
* @throws \Exception Unsupported environment
* @throws LoginUnsuccessfulException
*
* @return string
* @return bool
*/
protected function getAddress($environment)
public function login($username = null, $password = null, $sharedSecret = null): bool
{
switch ($environment) {
case 'production':
return ' https://api.domrobot.com/xmlrpc/';
if (null === $username && null === $password) {
$username = $this->username;
$password = $this->password;
}

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

default:
throw new \Exception('Unsupported environment!');
if (1000 === $result['code']) {
return true;
}

throw new LoginUnsuccessfulException();
}
}
11 changes: 0 additions & 11 deletions src/Exception/InvalidConfigurationException.php

This file was deleted.

11 changes: 11 additions & 0 deletions src/Exception/LoginUnsuccessfulException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace SebTM\INWX\Exception;

class LoginUnsuccessfulException extends \Exception
{
/**
* @var string
*/
protected $message = 'Login using "inwx-api-bundle" was unsuccessful!';
}
11 changes: 11 additions & 0 deletions src/Exception/UnsupportedEnvironmentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace SebTM\INWX\Exception;

class UnsupportedEnvironmentException extends \Exception
{
/**
* @var string
*/
protected $message = 'Unsupported environment given for "sebtm/inwx-api-bundle"!';
}
Loading

0 comments on commit ed97ff6

Please sign in to comment.