Skip to content

Commit

Permalink
Added in fix to complete coverages (#16)
Browse files Browse the repository at this point in the history
* Railsbank config test
* Railsbank test and configuration test
* No mode test
* Added in Railsbank command test
  • Loading branch information
levelfivehub committed Aug 20, 2019
1 parent 2511a70 commit cc78a17
Show file tree
Hide file tree
Showing 21 changed files with 474 additions and 85 deletions.
1 change: 1 addition & 0 deletions config/railsbank.config.php
Expand Up @@ -31,6 +31,7 @@
'commands' => [
Query\Version\GetVersion::class => QueryHandler\Version\GetVersionHandler::class,
Query\Me\Information::class => QueryHandler\Me\InformationHandler::class,
Query\Me\PHPVersion::class => QueryHandler\Me\PHPVersionHandler::class,
Query\Customer\GetLedger::class => QueryHandler\Customer\GetLedgerHandler::class,
Query\Customer\GetLedgers::class => QueryHandler\Customer\GetLedgersHandler::class,
Query\Customer\GetEndusers::class => QueryHandler\Customer\GetEndusersHandler::class,
Expand Down
9 changes: 4 additions & 5 deletions src/ConfigServiceFactory.php
Expand Up @@ -65,9 +65,8 @@ public function getConfigService() :? Config
private function validateConfig(Config $config) :? bool
{
$railsbankConfigValidator = new RailsbankConfigValidator();
return $railsbankConfigValidator->validateConfig(
$this->getRailsbankConfiguration($config)
);
$railsbankConfig = $this->getRailsbankConfiguration($config);
return $railsbankConfigValidator->validateConfig($railsbankConfig);
}

/**
Expand All @@ -78,10 +77,10 @@ private function validateConfig(Config $config) :? bool
*/
private function getRailsbankConfiguration(Config $config) :? Config
{
if (! $config = $config->offsetGet('railsbank_configuration')) {
if (! $config->offsetExists('railsbank_configuration')) {
throw new RailsbankConfigurationMissingException();
}

return $config;
return $config->offsetGet('railsbank_configuration');
}
}
2 changes: 1 addition & 1 deletion src/Exception/InvalidConfigException.php
Expand Up @@ -6,6 +6,6 @@ class InvalidConfigException extends \Exception
{
public function __construct()
{
parent::__construct('Configuration not valid, refer to documentation', 500);
parent::__construct('Configuration not valid, refer to documentation.', 500);
}
}
4 changes: 1 addition & 3 deletions src/Exception/RailsbankConfigurationMissingException.php
Expand Up @@ -2,16 +2,14 @@

namespace Railsbank\Exception;

use Throwable;

class RailsbankConfigurationMissingException extends \Exception
{
public function __construct($key = "")
{
$message = 'Railsbank configuration missing, refer to documentation.';

if ($key !== '') {
$message .= ' Key and/or value missing=' . $key;
$message .= ' Key and/or value missing=' . $key . ' or all mode configuration are missing';
}

parent::__construct($message, 500);
Expand Down
19 changes: 19 additions & 0 deletions src/Query/Me/PHPVersion.php
@@ -0,0 +1,19 @@
<?php
namespace Railsbank\Query\Me;

use Railsbank\Command;
use Railsbank\CommandInterface;
use Railsbank\Query\QueryInterface;

class PHPVersion extends Command implements CommandInterface, QueryInterface
{
public function getInputFilterSpecification() : array
{
return [];
}

public function getBody() :? array
{
return [];
}
}
2 changes: 1 addition & 1 deletion src/Query/Version/GetVersion.php
Expand Up @@ -13,6 +13,6 @@ public function getInputFilterSpecification() : array

public function getBody()
{
//
return [];
}
}
24 changes: 24 additions & 0 deletions src/QueryHandler/Me/PHPVersionHandler.php
@@ -0,0 +1,24 @@
<?php

namespace Railsbank\QueryHandler\Me;

use Railsbank\Handler;
use Railsbank\Query\Me\PHPVersion;
use Railsbank\RailsbankClient;
use Railsbank\Query\Me\Information;

/**
* Class PHPVersionHandler
* @package Railsbank\QueryHandler\Me
*/
class PHPVersionHandler extends Handler
{
/**
* @param PHPVersion $command
* @return string|null
*/
public function handlePHPVersion(PHPVersion $command)
{
return \phpversion('tidy');
}
}
8 changes: 1 addition & 7 deletions src/QueryHandler/Version/GetVersionHandler.php
Expand Up @@ -19,13 +19,7 @@ class GetVersionHandler extends Handler
public function handleGetVersion(GetVersion $command)
{
$client = new RailsbankClient($command->getRailsbankConfig());

try {
$version = $client->handleApiCall($command);
} catch (\Exception $e) {
// handle exceptions
}

$version = $client->handleApiCall($command);
return $version;
}
}
2 changes: 1 addition & 1 deletion src/Railsbank.php
Expand Up @@ -49,7 +49,7 @@ public function __construct(string $configFile = '', string $mode = 'play')
private function getConfiguration(string $configFile)
{
if (empty($configFile)) {
return [];
throw new InvalidConfigException();
}

$config = require_once($configFile);
Expand Down
12 changes: 7 additions & 5 deletions src/RailsbankConfig.php
Expand Up @@ -35,18 +35,20 @@ class RailsbankConfig
*/
public function __construct(array $config = [], string $mode = null)
{
if ( !empty($mode)) {
$this->mode = $mode;
}

$mode = $this->getMode();

$configServiceFactory = new ConfigServiceFactory($config);
$this->configService = $configServiceFactory->getConfigService();

/** @var Config $railsbankConfig */
$railsbankConfig = $this->configService->get('railsbank_configuration');

if ( !empty($mode)) {
$this->mode = $mode;
}

/** @var Config railsbankConfig */
$this->railsbankConfig = $railsbankConfig->get($this->getMode());
$this->railsbankConfig = $railsbankConfig->get($mode);
}

public function getBaseConfig() : Config
Expand Down
8 changes: 6 additions & 2 deletions tests/CommandOrQueryTest.php
Expand Up @@ -6,6 +6,9 @@
use Railsbank\CommandInterface;
use PHPUnit\Framework\TestCase;
use Railsbank\Command;
use Railsbank\RailsbankConfig;
use Zend\Config\Config;
use Zend\InputFilter\InputFilterInterface;

abstract class CommandOrQueryTest extends TestCase implements CommandOrQueryTestInterface
{
Expand All @@ -25,11 +28,12 @@ public function testCommand($errorExpected = false, $input = [], $response = fal

/** @var CommandInterface $command */
$command = new $this->command($input);

self::assertInstanceOf(Command::class, $command);

if ($response) {
if ($response || is_array($response)) {
self::assertEquals($command->getBody(), $response);
}

self::assertInstanceOf(InputFilterInterface::class, $command->getInput());
}
}

0 comments on commit cc78a17

Please sign in to comment.