More error detection for range to column
This commit is contained in:
parent
777ed5c746
commit
6f4fffc305
|
|
@ -10,7 +10,12 @@ class ConverterHelpers{
|
||||||
*/
|
*/
|
||||||
public static function RangeToColumnArray(string $range): array{
|
public static function RangeToColumnArray(string $range): array{
|
||||||
$rangeArray = explode("-",$range);
|
$rangeArray = explode("-",$range);
|
||||||
if(count($rangeArray) !== 2){
|
if(count($rangeArray) !== 2
|
||||||
|
|| strlen($rangeArray[0]) === 0
|
||||||
|
|| strlen($rangeArray[1]) === 0
|
||||||
|
|| !(strlen($rangeArray[0]) < strlen($rangeArray[1])
|
||||||
|
|| (strlen($rangeArray[0]) === strlen($rangeArray[1])
|
||||||
|
&& strcmp($rangeArray[0], $rangeArray[1]) <= 0))){
|
||||||
throw new MalformattedRangeStringException();
|
throw new MalformattedRangeStringException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
use CSO\Excel2Html\ConverterHelpers;
|
use CSO\Excel2Html\ConverterHelpers;
|
||||||
|
use CSO\Excel2Html\Exceptions\MalformattedRangeStringException;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class ConverterHelpersTest extends TestCase{
|
final class ConverterHelpersTest extends TestCase{
|
||||||
|
|
@ -8,4 +9,16 @@ final class ConverterHelpersTest extends TestCase{
|
||||||
$res = implode("|", $columns);
|
$res = implode("|", $columns);
|
||||||
$this->assertSame('Y|Z|AA|AB|AC', $res);
|
$this->assertSame('Y|Z|AA|AB|AC', $res);
|
||||||
}
|
}
|
||||||
|
public function testColumnRangeErrorOnWrongFormat(): void{
|
||||||
|
$this->expectException(MalformattedRangeStringException::class);
|
||||||
|
$columns = ConverterHelpers::RangeToColumnArray("-AC");
|
||||||
|
}
|
||||||
|
public function testColumnRangeErrorOnTwoLetterColumnFirst(): void{
|
||||||
|
$this->expectException(MalformattedRangeStringException::class);
|
||||||
|
$columns = ConverterHelpers::RangeToColumnArray("AC-Y");
|
||||||
|
}
|
||||||
|
public function testColumnRangeErrorOnHigherColumnFirst(): void{
|
||||||
|
$this->expectException(MalformattedRangeStringException::class);
|
||||||
|
$columns = ConverterHelpers::RangeToColumnArray("Z-B");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue