Skip to content

Commit

Permalink
Columns in GoggleSheet Adapter cannot contain unicode characters
Browse files Browse the repository at this point in the history
  • Loading branch information
stloyd committed Oct 22, 2023
1 parent 0ad27a7 commit 47e2a18
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ public function __construct(
throw new InvalidArgumentException('Sheet name can\'t be empty');
}

if (!\preg_match('/^[A-Z]+$/u', $startColumn)) {
throw new InvalidArgumentException(\sprintf('The column `%s` needs to contain only letters.', $startColumn));
if (!\preg_match('/^[A-Z]+$/', $startColumn)) {
throw new InvalidArgumentException(\sprintf('The column "%s" needs to contain only upper-case letters.', $startColumn));
}

if (!\preg_match('/^[A-Z]+$/u', $endColumn)) {
throw new InvalidArgumentException(\sprintf('The column `%s` needs to contain only letters.', $endColumn));
if (!\preg_match('/^[A-Z]+$/', $endColumn)) {
throw new InvalidArgumentException(\sprintf('The column "%s" needs to contain only upper-case letters.', $endColumn));
}

if ($endColumn < $startColumn) {
throw new InvalidArgumentException(\sprintf(
'The column that starts the range `%s` must not be after the end column `%s`',
'The column that starts the range "%s" must not be after the end column "%s"',
$startColumn,
$endColumn
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Flow\ETL\Adapter\GoogleSheet\Tests\Unit;

use Flow\ETL\Adapter\GoogleSheet\Columns;
use Flow\ETL\Exception\InvalidArgumentException;
use PHPUnit\Framework\TestCase;

final class ColumnsTest extends TestCase
Expand All @@ -17,23 +18,31 @@ public static function invalid_cases() : \Generator
];
yield 'start column contains number' => [
'Sheet', 'ABC1', 'CBA',
'The column `ABC1` needs to contain only letters.',
'The column "ABC1" needs to contain only upper-case letters.',
];
yield 'start column contains white space' => [
'Sheet', 'AB C', 'CBA',
'The column `AB C` needs to contain only letters.',
'The column "AB C" needs to contain only upper-case letters.',
];
yield 'start column contains unicode' => [
'Sheet', 'ABĆ', 'CBA',
'The column "ABĆ" needs to contain only upper-case letters.',
];
yield 'end column contains number' => [
'Sheet', 'ABC', 'CBA1',
'The column `CBA1` needs to contain only letters.',
'The column "CBA1" needs to contain only upper-case letters.',
];
yield 'end column contains white space' => [
'Sheet', 'ABC', 'CB A',
'The column `CB A` needs to contain only letters.',
'The column "CB A" needs to contain only upper-case letters.',
];
yield 'end column contains unicode' => [
'Sheet', 'ABC', 'ĆB',
'The column "ĆB" needs to contain only upper-case letters.',
];
yield 'columns in valid orders' => [
'Sheet', 'BA', 'AB',
'The column that starts the range `BA` must not be after the end column `AB`',
'The column that starts the range "BA" must not be after the end column "AB"',
];
}

Expand All @@ -42,7 +51,9 @@ public static function invalid_cases() : \Generator
*/
public function test_assertions(string $sheetName, string $startColumn, string $endColumn, string $expectedExceptionMessage) : void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage($expectedExceptionMessage);

new Columns($sheetName, $startColumn, $endColumn);
}
}

0 comments on commit 47e2a18

Please sign in to comment.