Skip to content

Commit

Permalink
Fix generating enum fields having values of uppercase letters (#79)
Browse files Browse the repository at this point in the history
* add a failed test case.

* stop converting consumption to lower case.

* convert column type to lower case again.
  • Loading branch information
kevinb1989 authored Jan 6, 2024
1 parent 286fbaa commit 7a91445
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Tokenizers/MySQL/ColumnTokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ protected function consumeZeroFill()

protected function consumeColumnType()
{
$originalColumnType = $columnType = strtolower($this->consume());
$originalColumnType = $columnType = $this->consume();
$hasConstraints = Str::contains($columnType, '(');

if ($hasConstraints) {
$columnType = explode('(', $columnType)[0];
}

$this->columnDataType = $columnType;
$this->columnDataType = strtolower($columnType);

$this->resolveColumnMethod();
if ($hasConstraints) {
Expand Down
15 changes: 15 additions & 0 deletions tests/Unit/Tokenizers/MySQL/ColumnTokenizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,21 @@ public function test_it_tokenizes_enum_column()
$this->assertEquals('$table->enum(\'status_flag\', [\'1\', \'2\', \'3\', \'4\'])', $columnDefinition->render());
}

public function test_it_tokenizes_enum_column_with_upper_case_values()
{
$columnTokenizer = ColumnTokenizer::parse('`film_rating` enum(\'G\',\'PG\',\'PG-13\',\'R\',\'NC-17\')');
$columnDefinition = $columnTokenizer->definition();

$this->assertEquals('film_rating', $columnDefinition->getColumnName());
$this->assertEquals('enum', $columnTokenizer->getColumnDataType());
$this->assertEquals('enum', $columnDefinition->getMethodName());
$this->assertCount(5, $columnDefinition->getMethodParameters()[0]);
$this->assertEqualsCanonicalizing(['G', 'PG', 'PG-13', 'R', 'NC-17'], $columnDefinition->getMethodParameters()[0]);
$this->assertNull($columnDefinition->isNullable());
$this->assertNull($columnDefinition->getCollation());
$this->assertEquals('$table->enum(\'film_rating\', [\'G\', \'PG\', \'PG-13\', \'R\', \'NC-17\'])', $columnDefinition->render());
}

public function test_it_tokenizes_not_null_enum_column()
{
$columnTokenizer = ColumnTokenizer::parse('`status_flag` enum(\'1\',\'2\',\'3\',\'4\') NOT NULL');
Expand Down

0 comments on commit 7a91445

Please sign in to comment.