From 4d9fd10384183417e9a45b1dd547d237872bb28d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sun, 25 Apr 2021 21:05:14 +0200 Subject: [PATCH 1/2] Use assertCount where applicable --- composer.json | 7 ------ tests/ConditionSqlTest.php | 18 +++++++------- tests/ConditionTest.php | 4 ++-- tests/PersistentArrayTest.php | 44 +++++++++++++++++------------------ tests/UserActionTest.php | 4 ++-- tests/ValidationTest.php | 2 +- tests/WithTest.php | 2 +- 7 files changed, 37 insertions(+), 44 deletions(-) diff --git a/composer.json b/composer.json index 2d8b26daa..74ae1d971 100644 --- a/composer.json +++ b/composer.json @@ -56,13 +56,6 @@ "phpunit/phpcov": "*", "phpunit/phpunit": ">=9.0" }, - "require-dev-release": { - "friendsofphp/php-cs-fixer": "^2.17", - "johnkary/phpunit-speedtrap": "^3.2", - "phpstan/phpstan": "^0.12.58", - "phpunit/phpcov": "*", - "phpunit/phpunit": ">=9.0" - }, "config": { "sort-packages": true }, diff --git a/tests/ConditionSqlTest.php b/tests/ConditionSqlTest.php index 3cd28eabe..190018b1b 100644 --- a/tests/ConditionSqlTest.php +++ b/tests/ConditionSqlTest.php @@ -289,22 +289,22 @@ public function testArrayCondition() $m = new Model($this->db, ['table' => 'user']); $m->addField('name'); $m->addCondition('name', ['John', 'Doe']); - $this->assertSame(1, count($m->export())); + $this->assertCount(1, $m->export()); $m = new Model($this->db, ['table' => 'user']); $m->addField('name'); $m->addCondition('name', 'in', ['Johhny', 'Doe', 'Mary']); - $this->assertSame(2, count($m->export())); + $this->assertCount(2, $m->export()); $m = new Model($this->db, ['table' => 'user']); $m->addField('name'); $m->addCondition('name', []); // this should not fail, always should be false - $this->assertSame(0, count($m->export())); + $this->assertCount(0, $m->export()); $m = new Model($this->db, ['table' => 'user']); $m->addField('name'); $m->addCondition('name', 'not in', []); // this should not fail, always should be true - $this->assertSame(3, count($m->export())); + $this->assertCount(3, $m->export()); } public function testDateCondition() @@ -435,18 +435,18 @@ public function testLikeCondition() $u->addField('created', ['type' => 'datetime']); $t = (clone $u)->addCondition('created', 'like', '%19%'); - $this->assertSame(2, count($t->export())); // only year 2019 records + $this->assertCount(2, $t->export()); // only year 2019 records $t = (clone $u)->addCondition('active', 'like', '%1%'); - $this->assertSame(2, count($t->export())); // only active records + $this->assertCount(2, $t->export()); // only active records $t = (clone $u)->addCondition('active', 'like', '%0%'); - $this->assertSame(1, count($t->export())); // only inactive records + $this->assertCount(1, $t->export()); // only inactive records $t = (clone $u)->addCondition('active', 'like', '%999%'); - $this->assertSame(0, count($t->export())); // bad value, so it will not match anything + $this->assertCount(0, $t->export()); // bad value, so it will not match anything $t = (clone $u)->addCondition('active', 'like', '%ABC%'); - $this->assertSame(0, count($t->export())); // bad value, so it will not match anything + $this->assertCount(0, $t->export()); // bad value, so it will not match anything } } diff --git a/tests/ConditionTest.php b/tests/ConditionTest.php index e7aad40d1..a93ecf8c4 100644 --- a/tests/ConditionTest.php +++ b/tests/ConditionTest.php @@ -29,11 +29,11 @@ public function testBasicDiscrimination() $m->addCondition('gender', 'M'); - $this->assertSame(1, count($m->scope()->getNestedConditions())); + $this->assertCount(1, $m->scope()->getNestedConditions()); $m->addCondition('gender', 'F'); - $this->assertSame(2, count($m->scope()->getNestedConditions())); + $this->assertCount(2, $m->scope()->getNestedConditions()); } public function testEditableAfterCondition() diff --git a/tests/PersistentArrayTest.php b/tests/PersistentArrayTest.php index 752844714..c5adc8f79 100644 --- a/tests/PersistentArrayTest.php +++ b/tests/PersistentArrayTest.php @@ -311,7 +311,7 @@ public function testLike() // case : str% $m->addCondition('country', 'LIKE', 'La%'); $result = $m->action('select')->getRows(); - $this->assertSame(3, count($result)); + $this->assertCount(3, $result); $this->assertSame($dbDataCountries[3], $result[3]); $this->assertSame($dbDataCountries[7], $result[7]); $this->assertSame($dbDataCountries[9], $result[9]); @@ -322,7 +322,7 @@ public function testLike() $m->scope()->clear(); $m->addCondition('country', 'NOT LIKE', 'La%'); $result = $m->action('select')->getRows(); - $this->assertSame(7, count($m->export())); + $this->assertCount(7, $m->export()); $this->assertSame($dbDataCountries[1], $result[1]); $this->assertSame($dbDataCountries[2], $result[2]); $this->assertSame($dbDataCountries[4], $result[4]); @@ -335,7 +335,7 @@ public function testLike() $m->scope()->clear(); $m->addCondition('country', 'LIKE', '%ia'); $result = $m->action('select')->getRows(); - $this->assertSame(4, count($result)); + $this->assertCount(4, $result); $this->assertSame($dbDataCountries[3], $result[3]); $this->assertSame($dbDataCountries[7], $result[7]); $this->assertSame($dbDataCountries[8], $result[8]); @@ -347,7 +347,7 @@ public function testLike() $m->scope()->clear(); $m->addCondition('country', 'LIKE', '%a%'); $result = $m->action('select')->getRows(); - $this->assertSame(8, count($result)); + $this->assertCount(8, $result); $this->assertSame($dbDataCountries[1], $result[1]); $this->assertSame($dbDataCountries[2], $result[2]); $this->assertSame($dbDataCountries[3], $result[3]); @@ -361,36 +361,36 @@ public function testLike() // case : boolean field $m->scope()->clear(); $m->addCondition('active', 'LIKE', '0'); - $this->assertSame(4, count($m->export())); + $this->assertCount(4, $m->export()); $m->scope()->clear(); $m->addCondition('active', 'LIKE', '1'); - $this->assertSame(6, count($m->export())); + $this->assertCount(6, $m->export()); $m->scope()->clear(); $m->addCondition('active', 'LIKE', '%0%'); - $this->assertSame(4, count($m->export())); + $this->assertCount(4, $m->export()); $m->scope()->clear(); $m->addCondition('active', 'LIKE', '%1%'); - $this->assertSame(6, count($m->export())); + $this->assertCount(6, $m->export()); $m->scope()->clear(); $m->addCondition('active', 'LIKE', '%999%'); - $this->assertSame(0, count($m->export())); + $this->assertCount(0, $m->export()); $m->scope()->clear(); $m->addCondition('active', 'LIKE', '%ABC%'); - $this->assertSame(0, count($m->export())); + $this->assertCount(0, $m->export()); // null value $m->scope()->clear(); $m->addCondition('code', '=', null); - $this->assertSame(1, count($m->export())); + $this->assertCount(1, $m->export()); $m->scope()->clear(); $m->addCondition('code', '!=', null); - $this->assertSame(9, count($m->export())); + $this->assertCount(9, $m->export()); } /** @@ -424,7 +424,7 @@ public function testConditions() $m->scope()->clear(); $m->addCondition('country', 'REGEXP', 'Ireland|UK'); $result = $m->action('select')->getRows(); - $this->assertSame(5, count($result)); + $this->assertCount(5, $result); $this->assertSame($dbDataCountries[1], $result[1]); $this->assertSame($dbDataCountries[2], $result[2]); $this->assertSame($dbDataCountries[4], $result[4]); @@ -436,7 +436,7 @@ public function testConditions() $m->scope()->clear(); $m->addCondition('country', 'NOT REGEXP', 'Ireland|UK|Latvia'); $result = $m->action('select')->getRows(); - $this->assertSame(1, count($result)); + $this->assertCount(1, $result); $this->assertSame($dbDataCountries[8], $result[8]); unset($result); $m->unload(); @@ -444,7 +444,7 @@ public function testConditions() $m->scope()->clear(); $m->addCondition('code', '>', 18); $result = $m->action('select')->getRows(); - $this->assertSame(1, count($result)); + $this->assertCount(1, $result); $this->assertSame($dbDataCountries[9], $result[9]); unset($result); $m->unload(); @@ -452,7 +452,7 @@ public function testConditions() $m->scope()->clear(); $m->addCondition('code', '>=', 18); $result = $m->action('select')->getRows(); - $this->assertSame(2, count($result)); + $this->assertCount(2, $result); $this->assertSame($dbDataCountries[8], $result[8]); $this->assertSame($dbDataCountries[9], $result[9]); unset($result); @@ -461,7 +461,7 @@ public function testConditions() $m->scope()->clear(); $m->addCondition('code', '<', 12); $result = $m->action('select')->getRows(); - $this->assertSame(1, count($result)); + $this->assertCount(1, $result); $this->assertSame($dbDataCountries[1], $result[1]); unset($result); $m->unload(); @@ -469,7 +469,7 @@ public function testConditions() $m->scope()->clear(); $m->addCondition('code', '<=', 12); $result = $m->action('select')->getRows(); - $this->assertSame(2, count($result)); + $this->assertCount(2, $result); $this->assertSame($dbDataCountries[1], $result[1]); $this->assertSame($dbDataCountries[2], $result[2]); unset($result); @@ -478,7 +478,7 @@ public function testConditions() $m->scope()->clear(); $m->addCondition('code', [11, 12]); $result = $m->action('select')->getRows(); - $this->assertSame(2, count($result)); + $this->assertCount(2, $result); $this->assertSame($dbDataCountries[1], $result[1]); $this->assertSame($dbDataCountries[2], $result[2]); unset($result); @@ -487,14 +487,14 @@ public function testConditions() $m->scope()->clear(); $m->addCondition('code', 'IN', []); $result = $m->action('select')->getRows(); - $this->assertSame(0, count($result)); + $this->assertCount(0, $result); unset($result); $m->unload(); $m->scope()->clear(); $m->addCondition('code', 'NOT IN', [11, 12, 13, 14, 15, 16, 17]); $result = $m->action('select')->getRows(); - $this->assertSame(2, count($result)); + $this->assertCount(2, $result); $this->assertSame($dbDataCountries[8], $result[8]); $this->assertSame($dbDataCountries[9], $result[9]); unset($result); @@ -503,7 +503,7 @@ public function testConditions() $m->scope()->clear(); $m->addCondition('code', '!=', [11, 12, 13, 14, 15, 16, 17]); $result = $m->action('select')->getRows(); - $this->assertSame(2, count($result)); + $this->assertCount(2, $result); $this->assertSame($dbDataCountries[8], $result[8]); $this->assertSame($dbDataCountries[9], $result[9]); unset($result); diff --git a/tests/UserActionTest.php b/tests/UserActionTest.php index 82a8920fd..e9801e72a 100644 --- a/tests/UserActionTest.php +++ b/tests/UserActionTest.php @@ -71,8 +71,8 @@ public function testBasic() $client = new UaClient($this->pers); $actions = $client->getUserActions(); - $this->assertSame(4, count($actions)); // don't return system actions here, but include add/edit/delete - $this->assertSame(0, count($client->getUserActions(Model\UserAction::APPLIES_TO_ALL_RECORDS))); // don't return system actions here + $this->assertCount(4, $actions); // don't return system actions here, but include add/edit/delete + $this->assertCount(0, $client->getUserActions(Model\UserAction::APPLIES_TO_ALL_RECORDS)); // don't return system actions here $act1 = $actions['send_reminder']; diff --git a/tests/ValidationTest.php b/tests/ValidationTest.php index 9d6d93c80..1789b1d68 100644 --- a/tests/ValidationTest.php +++ b/tests/ValidationTest.php @@ -139,7 +139,7 @@ public function testValidateHook() $this->m->save(); $this->fail('Expected exception'); } catch (\Atk4\Data\ValidationException $e) { - $this->assertSame(2, count($e->errors)); + $this->assertCount(2, $e->errors); } } } diff --git a/tests/WithTest.php b/tests/WithTest.php index 69596300f..677b32f99 100644 --- a/tests/WithTest.php +++ b/tests/WithTest.php @@ -50,7 +50,7 @@ public function testWith() 'with "i" ("user_id","invoiced") as (select "user_id","net" from "invoice" where "net" > :a) select "user"."id","user"."name","user"."salary","_i"."invoiced" from "user" inner join "i" "_i" on "_i"."user_id" = "user"."id"', $m->action('select')->render() ); - $this->assertSame(2, count($m->export())); + $this->assertCount(2, $m->export()); } /** From b787d11f8173429ae6aa4dc8b39ae0ec148ada1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sun, 25 Apr 2021 23:41:53 +0200 Subject: [PATCH 2/2] fix ValidationTest class name --- tests/ValidationTest.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/ValidationTest.php b/tests/ValidationTest.php index 1789b1d68..228451b34 100644 --- a/tests/ValidationTest.php +++ b/tests/ValidationTest.php @@ -9,11 +9,6 @@ use Atk4\Data\Persistence; use Atk4\Data\ValidationException; -class ValidationTest -{ - // TODO ignore CS fixer error -} - class MyValidationModel extends Model { protected function init(): void @@ -53,7 +48,7 @@ public function validate($intent = null): array } } -class ValidationTests extends AtkPhpunit\TestCase +class ValidationTest extends AtkPhpunit\TestCase { public $m;