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 9f35630
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public function __construct(
throw new InvalidArgumentException('Sheet name can\'t be empty');
}

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

if (!\preg_match('/^[A-Z]+$/u', $endColumn)) {
if (!\preg_match('/^[A-Z]+$/', $endColumn)) {
throw new InvalidArgumentException(\sprintf('The column `%s` needs to contain only letters.', $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 @@ -23,6 +24,10 @@ public static function invalid_cases() : \Generator
'Sheet', 'AB C', 'CBA',
'The column `AB C` needs to contain only letters.',
];
yield 'start column contains unicode' => [
'Sheet', 'ABĆ', 'CBA',
'The column `ABĆ` needs to contain only letters.',
];
yield 'end column contains number' => [
'Sheet', 'ABC', 'CBA1',
'The column `CBA1` needs to contain only letters.',
Expand All @@ -31,6 +36,10 @@ public static function invalid_cases() : \Generator
'Sheet', 'ABC', 'CB A',
'The column `CB A` needs to contain only letters.',
];
yield 'end column contains unicode' => [
'Sheet', 'ABC', 'ĆB',
'The column `ĆB` needs to contain only letters.',
];
yield 'columns in valid orders' => [
'Sheet', 'BA', '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 9f35630

Please sign in to comment.