Skip to content

Commit

Permalink
Add param/return types to test
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrans committed Aug 20, 2024
1 parent 23e743e commit 883c9a0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 42 deletions.
36 changes: 20 additions & 16 deletions QueryGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Designed to work with PHPUnit
*/
class QueryGeneratorTest extends PHPUnit\Framework\TestCase {
public function testIncompleteQuery() {
public function testIncompleteQuery(): void {
$incompleteQueryClauseSets = [
'select' => [
[],
Expand Down Expand Up @@ -48,10 +48,10 @@ public function testIncompleteQuery() {
$qGen->$clause('clause');
}

$build = function() use ($qGen) {
$build = function() use ($qGen): array {
return $qGen->build();
};
$buildIncomplete = function() use ($qGen) {
$buildIncomplete = function() use ($qGen): array {
return $qGen->skipValidation()->build();
};

Expand All @@ -61,7 +61,7 @@ public function testIncompleteQuery() {
}
}

public function testCompleteQuery() {
public function testCompleteQuery(): void {
$completeQueryClauseSets = [
'select' => [['select', 'from']],
'insert' => [
Expand All @@ -83,10 +83,10 @@ public function testCompleteQuery() {
$qGen->$clause('clause');
}

$build = function() use ($qGen) {
$build = function() use ($qGen): array {
return $qGen->build();
};
$buildIncomplete = function() use ($qGen) {
$buildIncomplete = function() use ($qGen): array {
return $qGen->skipValidation()->build();
};

Expand All @@ -96,7 +96,7 @@ public function testCompleteQuery() {
}
}

public function testSmallQuery() {
public function testSmallQuery(): void {
$qGen = new QueryGenerator();
$qGen->select(['field']);
$qGen->from(['table']);
Expand All @@ -110,7 +110,7 @@ public function testSmallQuery() {
$this->assertQuery($qGen, $expectedQuery, $expectedParams);
}

public function testBigQuery() {
public function testBigQuery(): void {
$qGen = new QueryGenerator();
$qGen->select(['field1', 'field2']);
$qGen->from(['table1', 'table2']);
Expand Down Expand Up @@ -142,7 +142,7 @@ public function testBigQuery() {
$this->assertQuery($qGen, $expectedQuery, $expectedParams);
}

public function testUseOr() {
public function testUseOr(): void {
$qGen = new QueryGenerator();
$qGen->select('field')
->from('table')
Expand All @@ -161,7 +161,7 @@ public function testUseOr() {
$this->assertQuery($qGen, $expectedQuery, $expectedParams);
}

public function testNestedGenerators() {
public function testNestedGenerators(): void {
$where = new QueryGenerator();
$where->where('abcd', [1]);
$qGen = new QueryGenerator();
Expand All @@ -179,7 +179,7 @@ public function testNestedGenerators() {
$this->assertQuery($qGen, $expectedQuery, $expectedParams);
}

public function testSingleArguments() {
public function testSingleArguments(): void {
$qGen = new QueryGenerator();
$qGen->select('field');
$qGen->from('table');
Expand All @@ -193,7 +193,7 @@ public function testSingleArguments() {
$this->assertQuery($qGen, $expectedQuery, $expectedParams);
}

public function testModifiers() {
public function testModifiers(): void {
$qGen = new QueryGenerator();
$qGen->insert('table');
$qGen->set('field = ?', 0);
Expand All @@ -208,7 +208,7 @@ public function testModifiers() {
$this->assertQuery($qGen, $expectedQuery, $expectedParams);
}

public function testForUpdate() {
public function testForUpdate(): void {
$qGen = new QueryGenerator();
$qGen->select('a');
$qGen->from('b');
Expand All @@ -223,7 +223,7 @@ public function testForUpdate() {
$this->assertQuery($qGen, $expectedQuery, []);
}

public function testOnDuplicate() {
public function testOnDuplicate(): void {
$qGen = new QueryGenerator();
$qGen->insert('a');
$qGen->as('row');
Expand All @@ -241,7 +241,7 @@ public function testOnDuplicate() {
$this->assertQuery($qGen, $expectedQuery, []);
}

public function assertQuery($qGen, $expectedQuery, $expectedParams) {
public function assertQuery(QueryGenerator $qGen, string $expectedQuery, array $expectedParams): void {
list($actualQuery, $actualParams) = $qGen->build();
$this->assertEquals($expectedQuery, $actualQuery);
$this->assertEquals($expectedParams, $actualParams);
Expand All @@ -251,7 +251,11 @@ public function assertQuery($qGen, $expectedQuery, $expectedParams) {
$this->assertEquals($expectedParams, $actualParams);
}

public function didThrowException($callback) {
/**
* @param callable $callback
* @return non-falsy-string|bool
*/
public function didThrowException($callback): string|bool {
try {
$callback();
return false;
Expand Down
26 changes: 0 additions & 26 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,6 @@
</UnusedProperty>
</file>
<file src="QueryGeneratorTest.php">
<MissingClosureReturnType>
<code><![CDATA[function() use ($qGen) {]]></code>
<code><![CDATA[function() use ($qGen) {]]></code>
<code><![CDATA[function() use ($qGen) {]]></code>
<code><![CDATA[function() use ($qGen) {]]></code>
</MissingClosureReturnType>
<MissingParamType>
<code><![CDATA[$callback]]></code>
<code><![CDATA[$expectedParams]]></code>
<code><![CDATA[$expectedQuery]]></code>
<code><![CDATA[$qGen]]></code>
</MissingParamType>
<MissingReturnType>
<code><![CDATA[assertQuery]]></code>
<code><![CDATA[didThrowException]]></code>
<code><![CDATA[testBigQuery]]></code>
<code><![CDATA[testCompleteQuery]]></code>
<code><![CDATA[testForUpdate]]></code>
<code><![CDATA[testIncompleteQuery]]></code>
<code><![CDATA[testModifiers]]></code>
<code><![CDATA[testNestedGenerators]]></code>
<code><![CDATA[testOnDuplicate]]></code>
<code><![CDATA[testSingleArguments]]></code>
<code><![CDATA[testSmallQuery]]></code>
<code><![CDATA[testUseOr]]></code>
</MissingReturnType>
<UnusedClass>
<code><![CDATA[QueryGeneratorTest]]></code>
</UnusedClass>
Expand Down

0 comments on commit 883c9a0

Please sign in to comment.