Skip to content

Commit

Permalink
add case sensitivity testing
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterOdin authored Dec 26, 2023
1 parent 875c2fd commit 2909829
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 10 deletions.
6 changes: 1 addition & 5 deletions src/Phinx/Db/Adapter/PostgresAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -870,11 +870,7 @@ public function hasPrimaryKey(string $tableName, $columns, ?string $constraint =
return $primaryKey['constraint'] === $constraint;
}

// Normalize the columns for comparison
$primaryKeyColumns = array_map('mb_strtolower', $primaryKey['columns']);
$columns = array_map('mb_strtolower', (array)$columns);

return $primaryKeyColumns === $columns;
return $primaryKey['columns'] === (array)$columns;
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/Phinx/Db/Adapter/SqlServerAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -894,11 +894,7 @@ public function hasPrimaryKey(string $tableName, $columns, ?string $constraint =
return $primaryKey['constraint'] === $constraint;
}

// Normalize the columns for comparison
$primaryKeyColumns = array_map('mb_strtolower', $primaryKey['columns']);
$columns = array_map('mb_strtolower', (array)$columns);

return $primaryKeyColumns === $columns;
return $primaryKey['columns'] === (array)$columns;

Check warning on line 897 in src/Phinx/Db/Adapter/SqlServerAdapter.php

View check run for this annotation

Codecov / codecov/patch

src/Phinx/Db/Adapter/SqlServerAdapter.php#L897

Added line #L897 was not covered by tests
}

/**
Expand Down
11 changes: 11 additions & 0 deletions tests/Phinx/Db/Adapter/MysqlAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,17 @@ public function testHasPrimaryKeyMultipleColumns()
$this->assertFalse($table->hasPrimaryKey(['column1', 'column2', 'column3', 'column4']));
}

public function testHasPrimaryKeyCaseInsensitivity()
{
$table = new Table('table', ['id' => false, 'primary_key' => ['column1']], $this->adapter);
$table
->addColumn('column1', 'integer', ['null' => false])
->save();

$this->assertTrue($table->hasPrimaryKey('column1'));
$this->assertTrue($table->hasPrimaryKey('cOlUmN1'));
}

public function testAddComment()
{
$table = new Table('table1', [], $this->adapter);
Expand Down
11 changes: 11 additions & 0 deletions tests/Phinx/Db/Adapter/PostgresAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,17 @@ public function testHasPrimaryKeyMultipleColumns()
$this->assertFalse($table->hasPrimaryKey(['column1', 'column2', 'column3', 'column4']));
}

public function testHasPrimaryKeyCaseSensitivity()
{
$table = new Table('table', ['id' => false, 'primary_key' => ['column1']], $this->adapter);
$table
->addColumn('column1', 'integer', ['null' => false])
->save();

$this->assertTrue($table->hasPrimaryKey('column1'));
$this->assertFalse($table->hasPrimaryKey('cOlUmN1'));
}

public function testAddComment()
{
$table = new Table('table1', [], $this->adapter);
Expand Down
11 changes: 11 additions & 0 deletions tests/Phinx/Db/Adapter/SQLiteAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,17 @@ public function testHasPrimaryKeyMultipleColumns()
$this->assertFalse($table->hasPrimaryKey(['column1', 'column2', 'column3', 'column4']));
}

public function testHasPrimaryKeyCaseInsensitivity()
{
$table = new Table('table', ['id' => false, 'primary_key' => ['column1']], $this->adapter);
$table
->addColumn('column1', 'integer', ['null' => false])
->save();

$this->assertTrue($table->hasPrimaryKey('column1'));
$this->assertTrue($table->hasPrimaryKey('cOlUmN1'));
}

public function testAddMultipleColumnPrimaryKeyFails()
{
$table = new Table('table1', [], $this->adapter);
Expand Down
11 changes: 11 additions & 0 deletions tests/Phinx/Db/Adapter/SqlServerAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,17 @@ public function testHasPrimaryKeyMultipleColumns()
$this->assertFalse($table->hasPrimaryKey(['column1', 'column2', 'column3', 'column4']));
}

public function testHasPrimaryKeyCaseSensitivity()
{
$table = new Table('table', ['id' => false, 'primary_key' => ['column1']], $this->adapter);
$table
->addColumn('column1', 'integer', ['null' => false])
->save();

$this->assertTrue($table->hasPrimaryKey('column1'));
$this->assertFalse($table->hasPrimaryKey('cOlUmN1'));
}

public function testChangeCommentFails()
{
$table = new Table('table1', [], $this->adapter);
Expand Down

0 comments on commit 2909829

Please sign in to comment.