Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use assertCount where applicable #863

Merged
merged 2 commits into from
Apr 26, 2021
Merged
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
7 changes: 0 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
18 changes: 9 additions & 9 deletions tests/ConditionSqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
}
4 changes: 2 additions & 2 deletions tests/ConditionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
44 changes: 22 additions & 22 deletions tests/PersistentArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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]);
Expand All @@ -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]);
Expand All @@ -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]);
Expand All @@ -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());
}

/**
Expand Down Expand Up @@ -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]);
Expand All @@ -436,23 +436,23 @@ 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();

$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();

$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);
Expand All @@ -461,15 +461,15 @@ 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();

$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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/UserActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down
9 changes: 2 additions & 7 deletions tests/ValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,7 +48,7 @@ public function validate($intent = null): array
}
}

class ValidationTests extends AtkPhpunit\TestCase
class ValidationTest extends AtkPhpunit\TestCase
{
public $m;

Expand Down Expand Up @@ -139,7 +134,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);
}
}
}
2 changes: 1 addition & 1 deletion tests/WithTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down