Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Clause/Conditional.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public function getValues(): array
if ($values[$i] instanceof QueryInterface) {
$value = $values[$i]->getValues();
array_splice($values, $i, 1, $value);
$i += count($value);
$i += count($value) - 1;
$count += count($value) - 1;
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/Clause/Join.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ public function __construct($subject, ConditionalInterface $on, string $type = '
*/
public function getValues(): array
{
if (is_array($this->subject)) {
reset($this->subject);
$alias = key($this->subject);
if (!is_string($alias)) {
trigger_error('Invalid subject array, use string keys for alias', E_USER_ERROR);
}
$table = $this->subject[$alias];
if ($table instanceof SelectInterface) {
return array_merge($table->getValues(), $this->on->getValues());
}
}
return $this->on->getValues();
}

Expand Down
4 changes: 0 additions & 4 deletions src/Statement/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ public function getValues(): array
$values = array_merge($values, $this->where->getValues());
}

if (!empty($this->orderBy)) {
$values = array_merge($values, $this->orderBy);
}

if ($this->limit != null) {
$values = array_merge($values, $this->limit->getValues());
}
Expand Down
11 changes: 11 additions & 0 deletions tests/Clause/ConditionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function testGetValues()

$this->assertIsArray($subject->getValues());
$this->assertCount(1, $subject->getValues());
$this->assertEquals($subject->getValues(), ['val']);
}

public function testGetValuesWithQuery()
Expand All @@ -92,5 +93,15 @@ public function testGetValuesWithQueryAndArgs()

$this->assertIsArray($subject->getValues());
$this->assertCount(2, $subject->getValues());
$this->assertEquals($subject->getValues(), [1, 2]);
}

public function testGetValuesWithMultipleValues()
{
$subject = new Conditional('col', 'BETWEEN', [new Method('test', 1, 2), new Method('test', 3, 4)]);

$this->assertIsArray($subject->getValues());
$this->assertCount(4, $subject->getValues());
$this->assertEquals($subject->getValues(), [1, 2, 3, 4]);
}
}
17 changes: 17 additions & 0 deletions tests/Clause/JoinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,21 @@ public function testGetValues()
$this->assertIsArray($subject->getValues());
$this->assertCount(1, $subject->getValues());
}

public function testGetValuesWithSubselect()
{
$db = $this->createMock(Database::class);
$subject = new Join(
['alias' => (new Select($db))->from('table')->where(new Conditional('column1', '=', 'value1'))],
new Conditional('column2', '=', 'value2')
);

$this->assertStringMatchesFormat(
'JOIN (SELECT * FROM table WHERE column1 = ?) AS alias ON column2 = ?',
$subject->__toString()
);
$this->assertIsArray($subject->getValues());
$this->assertCount(2, $subject->getValues());
$this->assertEquals(['value1', 'value2'], $subject->getValues());
}
}
3 changes: 1 addition & 2 deletions tests/Statement/DeleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,8 @@ public function testGetValuesWithOrderBy()
->orderBy('id', 'ASC')
->orderBy('name', 'DESC');

// FIXME This seems broken...
$this->assertIsArray($this->subject->getValues());
$this->assertCount(2, $this->subject->getValues());
$this->assertCount(0, $this->subject->getValues());
}

public function testGetValuesWithLimit()
Expand Down
1 change: 0 additions & 1 deletion tests/Statement/UpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ public function testGetValuesWithOrderBy()
->orderBy('id', 'ASC')
->orderBy('name', 'DESC');

// FIXME This seems broken...
$this->assertIsArray($this->subject->getValues());
$this->assertCount(1, $this->subject->getValues());
}
Expand Down