From 883c9a056b5704d6c236303b0b0ae85ecc11ff07 Mon Sep 17 00:00:00 2001 From: David Rans Date: Tue, 20 Aug 2024 12:41:10 -0700 Subject: [PATCH] Add param/return types to test --- QueryGeneratorTest.php | 36 ++++++++++++++++++++---------------- psalm-baseline.xml | 26 -------------------------- 2 files changed, 20 insertions(+), 42 deletions(-) diff --git a/QueryGeneratorTest.php b/QueryGeneratorTest.php index 65ba246..c3b8b3c 100644 --- a/QueryGeneratorTest.php +++ b/QueryGeneratorTest.php @@ -6,7 +6,7 @@ * Designed to work with PHPUnit */ class QueryGeneratorTest extends PHPUnit\Framework\TestCase { - public function testIncompleteQuery() { + public function testIncompleteQuery(): void { $incompleteQueryClauseSets = [ 'select' => [ [], @@ -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(); }; @@ -61,7 +61,7 @@ public function testIncompleteQuery() { } } - public function testCompleteQuery() { + public function testCompleteQuery(): void { $completeQueryClauseSets = [ 'select' => [['select', 'from']], 'insert' => [ @@ -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(); }; @@ -96,7 +96,7 @@ public function testCompleteQuery() { } } - public function testSmallQuery() { + public function testSmallQuery(): void { $qGen = new QueryGenerator(); $qGen->select(['field']); $qGen->from(['table']); @@ -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']); @@ -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') @@ -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(); @@ -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'); @@ -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); @@ -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'); @@ -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'); @@ -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); @@ -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; diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 516e89f..9b7b170 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -15,32 +15,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - -