Skip to content

Commit 3be7101

Browse files
committed
Add failure tests
1 parent 7fe135b commit 3be7101

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

src/Schema/Grammar.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,13 @@ protected function columnizeWithDirection(array $columns, string $direction)
200200
}, $columnNames, $columnDirections));
201201
}
202202

203+
if (array_filter($columns, 'is_array') !== []) {
204+
throw new InvalidArgumentException('You must set the direction for each sort key column or use the second parameter to set the direction for all sort key columns');
205+
}
206+
203207
$wrapped = array_map([$this, 'wrap'], $columns);
204208

205209
return implode(', ', array_map(function ($column) use ($direction) {
206-
if (is_array($column)) {
207-
throw new InvalidArgumentException('You must set the direction for each sort key column or use the second parameter to set the direction for all sort key columns');
208-
}
209-
210210
return $column.' '.$direction;
211211
}, $wrapped));
212212
}

tests/Hybrid/CreateTable/SortKeysTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
namespace SingleStore\Laravel\Tests\Hybrid\CreateTable;
77

8+
use InvalidArgumentException;
89
use SingleStore\Laravel\Schema\Blueprint;
910
use SingleStore\Laravel\Tests\BaseTest;
1011
use SingleStore\Laravel\Tests\Hybrid\HybridTestHelpers;
@@ -112,6 +113,34 @@ public function it_adds_a_dual_sort_key_with_different_directions()
112113
);
113114
}
114115

116+
/** @test */
117+
public function it_cannot_add_a_dual_sort_key_with_only_one_direction()
118+
{
119+
$blueprint = $this->createTable(function (Blueprint $table) {
120+
$table->string('f_name');
121+
$table->string('l_name');
122+
$table->sortKey(['f_name', ['l_name', 'desc']]);
123+
});
124+
125+
$this->expectException(InvalidArgumentException::class);
126+
127+
$blueprint->toSql($this->getConnection(), $this->getGrammar());
128+
}
129+
130+
/** @test */
131+
public function it_cannot_add_a_dual_sort_key_with_only_one_direction_desc()
132+
{
133+
$blueprint = $this->createTable(function (Blueprint $table) {
134+
$table->string('f_name');
135+
$table->string('l_name');
136+
$table->sortKey(['f_name', ['l_name', 'asc']], 'desc');
137+
});
138+
139+
$this->expectException(InvalidArgumentException::class);
140+
141+
$blueprint->toSql($this->getConnection(), $this->getGrammar());
142+
}
143+
115144
/** @test */
116145
public function shard_and_sort_keys()
117146
{

0 commit comments

Comments
 (0)