Skip to content

Commit a505059

Browse files
committed
Added another test
1 parent ba0e4cf commit a505059

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace LasseRafn\Hexer\Exceptions;
4+
5+
class PercentageIsNotAnInteger extends \Exception
6+
{
7+
}

src/Hex.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use LasseRafn\Hexer\Exceptions\HexTooLongException;
66
use LasseRafn\Hexer\Exceptions\HexTooShortException;
7+
use LasseRafn\Hexer\Exceptions\PercentageIsNotAnInteger;
78
use LasseRafn\Hexer\Exceptions\PercentageTooHighException;
89
use LasseRafn\Hexer\Exceptions\PercentageTooLowException;
910

@@ -55,8 +56,19 @@ public function darken($percentage = 0)
5556
return $this->brightnessModifier->adjustBrightness($this->hex, $percentage * -1);
5657
}
5758

59+
/**
60+
* @param integer $percentage
61+
*
62+
* @throws PercentageTooHighException
63+
* @throws PercentageTooLowException
64+
* @throws PercentageIsNotAnInteger
65+
*/
5866
private function validatePercentage($percentage)
5967
{
68+
if( ! is_int($percentage)) {
69+
throw new PercentageIsNotAnInteger("The percentage ({$percentage}) is not an integer.");
70+
}
71+
6072
if ($percentage < 0) {
6173
throw new PercentageTooLowException("The percentage ({$percentage}) is below zero (0)");
6274
}
@@ -66,6 +78,10 @@ private function validatePercentage($percentage)
6678
}
6779
}
6880

81+
/**
82+
* @throws HexTooLongException
83+
* @throws HexTooShortException
84+
*/
6985
private function validateHex()
7086
{
7187
$hex = str_replace('#', '', $this->hex);

tests/HexModifierTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ public function test_will_fail_with_too_high_percentage_input()
100100
$hex->lighten(101);
101101
}
102102

103+
public function test_will_fail_with_a_non_integer_percentage_input()
104+
{
105+
$this->expectException(\LasseRafn\Hexer\Exceptions\PercentageIsNotAnInteger::class);
106+
107+
$hex = new \LasseRafn\Hexer\Hex('#fff');
108+
$hex->lighten('ab12');
109+
}
110+
103111
public function test_will_return_initial_hex_with_zero_percentage()
104112
{
105113
$hex = new \LasseRafn\Hexer\Hex('#fff');

0 commit comments

Comments
 (0)