Skip to content
This repository has been archived by the owner on Aug 17, 2022. It is now read-only.

Commit

Permalink
Merge pull request #8 from loveOSS/removed-unused-function
Browse files Browse the repository at this point in the history
Added tests
  • Loading branch information
mickaelandrieu committed May 20, 2019
2 parents 27f7feb + e9a7f37 commit 6900934
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/Exceptions/InvalidSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public static function missingSettings(array $settings): self

foreach (self::REQUIRED_SETTINGS as $setting) {
if (!array_key_exists($setting, $settings)) {
$exceptionMessage .= sprintf('The setting "%s" is missing from configuration', $setting);
$exceptionMessage .= sprintf(
'The setting "%s" is missing from configuration',
$setting
) . PHP_EOL;
}
}

Expand Down
12 changes: 0 additions & 12 deletions src/Places/AbstractPlace.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,6 @@ public function getThreshold(): float
return $this->threshold;
}

/**
* Helper: create a Place from an array.
*
* @var array the failures, timeout and threshold
*
* @return self
*/
public static function fromArray(array $settings): self
{
return new static((int) $settings[0], (float) $settings[1], (float) $settings[2]);
}

/**
* Ensure the place is valid
*
Expand Down
73 changes: 73 additions & 0 deletions tests/Exceptions/InvalidSystemTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace Tests\Resiliency\Exceptions;

use PHPUnit\Framework\TestCase;
use Resiliency\Exceptions\InvalidSystem;

class InvalidSystemTest extends TestCase
{
public function testCreation()
{
$invalidPlace = new InvalidSystem();

$this->assertInstanceOf(InvalidSystem::class, $invalidPlace);
}

/**
* @dataProvider getSettings
*
* @param array $settings
* @param string $expectedExceptionMessage
*/
public function testInvalidSettings($settings, $expectedExceptionMessage)
{
$invalidSystem = InvalidSystem::missingSettings($settings);

$this->assertSame($invalidSystem->getMessage(), $expectedExceptionMessage);
}

/**
* @return array
*/
public function getSettings()
{
return [
'all_missing_settings' => [
[],
'Missing settings for System:' . PHP_EOL .
'The setting "timeout" is missing from configuration' . PHP_EOL .
'The setting "stripped_timeout" is missing from configuration' . PHP_EOL .
'The setting "failures" is missing from configuration' . PHP_EOL .
'The setting "threshold" is missing from configuration' . PHP_EOL,
],
'2_missing_settings' => [
[
'failures' => 1,
'timeout' => -1,
],
'Missing settings for System:' . PHP_EOL .
'The setting "stripped_timeout" is missing from configuration' . PHP_EOL .
'The setting "threshold" is missing from configuration' . PHP_EOL,
],
'1_missing_setting' => [
[
'failures' => 1,
'timeout' => 1.0,
'stripped_timeout' => -1,
],
'Missing settings for System:' . PHP_EOL .
'The setting "threshold" is missing from configuration' . PHP_EOL,
],
'all_present_settings' => [
[
'failures' => 1,
'timeout' => 1.0,
'stripped_timeout' => 1.0,
'threshold' => 1.0,
],
'Missing settings for System:' . PHP_EOL,
],
];
}
}

0 comments on commit 6900934

Please sign in to comment.