Skip to content

Commit 888f64f

Browse files
authored
assertSame instead of assertEquals (#29)
1 parent 23f4fe6 commit 888f64f

File tree

9 files changed

+39
-39
lines changed

9 files changed

+39
-39
lines changed

src/Codeception/Module/Db.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ public function seeInDatabase(string $table, array $criteria = []): void
837837
public function seeNumRecords(int $expectedNumber, string $table, array $criteria = []): void
838838
{
839839
$actualNumber = $this->countInDatabase($table, $criteria);
840-
$this->assertEquals(
840+
$this->assertSame(
841841
$expectedNumber,
842842
$actualNumber,
843843
sprintf(

tests/unit/Codeception/Lib/Driver/DbTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function testGenerateWhereClause(array $criteria, string $expectedResult)
1919
{
2020
$db = new Db('sqlite:tests/data/sqlite.db','root','');
2121
$result = ReflectionHelper::invokePrivateMethod($db, 'generateWhereClause', [&$criteria]);
22-
$this->assertEquals($expectedResult, $result);
22+
$this->assertSame($expectedResult, $result);
2323
}
2424

2525
public function getWhereCriteria(): array

tests/unit/Codeception/Lib/Driver/MysqlTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,33 +69,33 @@ public function testCleanupDatabase()
6969
public function testLoadDump()
7070
{
7171
$res = $this->mysql->getDbh()->query("select * from users where name = 'davert'");
72-
$this->assertNotEquals(false, $res);
72+
$this->assertNotSame(false, $res);
7373
$this->assertGreaterThan(0, $res->rowCount());
7474

7575
$res = $this->mysql->getDbh()->query("select * from groups where name = 'coders'");
76-
$this->assertNotEquals(false, $res);
76+
$this->assertNotSame(false, $res);
7777
$this->assertGreaterThan(0, $res->rowCount());
7878
}
7979

8080
public function testGetSingleColumnPrimaryKey()
8181
{
82-
$this->assertEquals(['id'], $this->mysql->getPrimaryKey('order'));
82+
$this->assertSame(['id'], $this->mysql->getPrimaryKey('order'));
8383
}
8484

8585
public function testGetCompositePrimaryKey()
8686
{
87-
$this->assertEquals(['group_id', 'id'], $this->mysql->getPrimaryKey('composite_pk'));
87+
$this->assertSame(['group_id', 'id'], $this->mysql->getPrimaryKey('composite_pk'));
8888
}
8989

9090
public function testGetEmptyArrayIfTableHasNoPrimaryKey()
9191
{
92-
$this->assertEquals([], $this->mysql->getPrimaryKey('no_pk'));
92+
$this->assertSame([], $this->mysql->getPrimaryKey('no_pk'));
9393
}
9494

9595
public function testSelectWithBooleanParam()
9696
{
9797
$res = $this->mysql->executeQuery("select `id` from `users` where `is_active` = ?", [false]);
98-
$this->assertEquals(1, $res->rowCount());
98+
$this->assertSame(1, $res->rowCount());
9999
}
100100

101101
public function testInsertIntoBitField()
@@ -104,7 +104,7 @@ public function testInsertIntoBitField()
104104
"insert into `users`(`id`,`name`,`email`,`is_active`,`created_at`) values (?,?,?,?,?)",
105105
[5,'insert.test','[email protected]',false,'2012-02-01 21:17:47']
106106
);
107-
$this->assertEquals(1, $res->rowCount());
107+
$this->assertSame(1, $res->rowCount());
108108
}
109109

110110
/**

tests/unit/Codeception/Lib/Driver/PostgresTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,20 @@ public function testCleanupDatabaseDeletesTypes()
8484
public function testLoadDump()
8585
{
8686
$res = $this->postgres->getDbh()->query("select * from users where name = 'davert'");
87-
$this->assertNotEquals(false, $res);
87+
$this->assertNotSame(false, $res);
8888
$this->assertGreaterThan(0, $res->rowCount());
8989

9090
$res = $this->postgres->getDbh()->query("select * from groups where name = 'coders'");
91-
$this->assertNotEquals(false, $res);
91+
$this->assertNotSame(false, $res);
9292
$this->assertGreaterThan(0, $res->rowCount());
9393

9494
$res = $this->postgres->getDbh()->query("select * from users where email = '[email protected]'");
95-
$this->assertNotEquals(false, $res);
95+
$this->assertNotSame(false, $res);
9696
$this->assertGreaterThan(0, $res->rowCount());
9797

9898
$res = $this->postgres->getDbh()
9999
->query("select * from anotherschema.users where email = '[email protected]'");
100-
$this->assertEquals(1, $res->rowCount());
100+
$this->assertSame(1, $res->rowCount());
101101
}
102102

103103
public function testSelectWithEmptyCriteria()
@@ -110,23 +110,23 @@ public function testSelectWithEmptyCriteria()
110110

111111
public function testGetSingleColumnPrimaryKey()
112112
{
113-
$this->assertEquals(['id'], $this->postgres->getPrimaryKey('order'));
113+
$this->assertSame(['id'], $this->postgres->getPrimaryKey('order'));
114114
}
115115

116116
public function testGetCompositePrimaryKey()
117117
{
118-
$this->assertEquals(['group_id', 'id'], $this->postgres->getPrimaryKey('composite_pk'));
118+
$this->assertSame(['group_id', 'id'], $this->postgres->getPrimaryKey('composite_pk'));
119119
}
120120

121121
public function testGetEmptyArrayIfTableHasNoPrimaryKey()
122122
{
123-
$this->assertEquals([], $this->postgres->getPrimaryKey('no_pk'));
123+
$this->assertSame([], $this->postgres->getPrimaryKey('no_pk'));
124124
}
125125

126126
public function testLastInsertIdReturnsSequenceValueWhenNonStandardSequenceNameIsUsed()
127127
{
128128
$this->postgres->executeQuery('INSERT INTO seqnames(name) VALUES(?)',['test']);
129-
$this->assertEquals(1, $this->postgres->lastInsertId('seqnames'));
129+
$this->assertSame('1', $this->postgres->lastInsertId('seqnames'));
130130
}
131131

132132
/**
@@ -138,7 +138,7 @@ public function testLoadDumpEndingWithoutDelimiter()
138138
$newDriver->load(["INSERT INTO empty_table VALUES(1, 'test')"]);
139139

140140
$res = $newDriver->getDbh()->query("select * from empty_table where field = 'test'");
141-
$this->assertNotEquals(false, $res);
141+
$this->assertNotSame(false, $res);
142142
$this->assertNotEmpty($res->fetchAll());
143143
}
144144
}

tests/unit/Codeception/Lib/Driver/SqliteTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,32 @@ public function _tearDown()
5050
public function testLoadDump()
5151
{
5252
$res = self::$sqlite->getDbh()->query("select * from users where name = 'davert'");
53-
$this->assertNotEquals(false, $res);
53+
$this->assertNotSame(false, $res);
5454
$this->assertNotEmpty($res->fetchAll());
5555

5656
$res = self::$sqlite->getDbh()->query("select * from groups where name = 'coders'");
57-
$this->assertNotEquals(false, $res);
57+
$this->assertNotSame(false, $res);
5858
$this->assertNotEmpty($res->fetchAll());
5959
}
6060

6161
public function testGetPrimaryKeyReturnsRowIdIfTableHasIt()
6262
{
63-
$this->assertEquals(['_ROWID_'], self::$sqlite->getPrimaryKey('groups'));
63+
$this->assertSame(['_ROWID_'], self::$sqlite->getPrimaryKey('groups'));
6464
}
6565

6666
public function testGetPrimaryKeyReturnsRowIdIfTableHasNoPrimaryKey()
6767
{
68-
$this->assertEquals(['_ROWID_'], self::$sqlite->getPrimaryKey('no_pk'));
68+
$this->assertSame(['_ROWID_'], self::$sqlite->getPrimaryKey('no_pk'));
6969
}
7070

7171
public function testGetSingleColumnPrimaryKeyWhenTableHasNoRowId()
7272
{
73-
$this->assertEquals(['id'], self::$sqlite->getPrimaryKey('order'));
73+
$this->assertSame(['id'], self::$sqlite->getPrimaryKey('order'));
7474
}
7575

7676
public function testGetCompositePrimaryKeyWhenTableHasNoRowId()
7777
{
78-
$this->assertEquals(['group_id', 'id'], self::$sqlite->getPrimaryKey('composite_pk'));
78+
$this->assertSame(['group_id', 'id'], self::$sqlite->getPrimaryKey('composite_pk'));
7979
}
8080

8181
public function testThrowsExceptionIfInMemoryDatabaseIsUsed()
@@ -95,7 +95,7 @@ public function testLoadDumpEndingWithoutDelimiter()
9595
$newDriver->load(['INSERT INTO empty_table VALUES(1, "test")']);
9696

9797
$res = $newDriver->getDbh()->query("select * from empty_table where field = 'test'");
98-
$this->assertNotEquals(false, $res);
98+
$this->assertNotSame(false, $res);
9999
$this->assertNotEmpty($res->fetchAll());
100100
}
101101
}

tests/unit/Codeception/Module/Db/AbstractDbTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function testConnectionIsKeptForTheWholeSuite()
5959
$this->module->dbh
6060
];
6161
$this->module->_after($testCase2);
62-
$this->assertEquals($driverAndConn2, $driverAndConn1);
62+
$this->assertSame($driverAndConn2, $driverAndConn1);
6363

6464
$this->module->_afterSuite();
6565
}
@@ -145,17 +145,17 @@ public function testHaveInDatabaseWithoutPrimaryKey()
145145
public function testGrabFromDatabase()
146146
{
147147
$email = $this->module->grabFromDatabase('users', 'email', ['name' => 'davert']);
148-
$this->assertEquals('[email protected]', $email);
148+
$this->assertSame('[email protected]', $email);
149149
}
150150

151151
public function testGrabNumRecords()
152152
{
153153
$num = $this->module->grabNumRecords('users', ['name' => 'davert']);
154-
$this->assertEquals($num, 1);
154+
$this->assertSame($num, 1);
155155
$num = $this->module->grabNumRecords('users', ['name' => 'davert', 'email' => '[email protected]']);
156-
$this->assertEquals($num, 0);
156+
$this->assertSame($num, 0);
157157
$num = $this->module->grabNumRecords('users', ['name' => 'user1']);
158-
$this->assertEquals($num, 0);
158+
$this->assertSame($num, 0);
159159
}
160160

161161
public function testLoadWithPopulator()

tests/unit/Codeception/Module/Db/MySqlDbTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public function testConnectionIsResetOnEveryTestWhenReconnectIsTrue()
6969
$connection3 = $this->module->dbh->query('SELECT CONNECTION_ID()')->fetch(PDO::FETCH_COLUMN);
7070
$this->module->_after($testCase3);
7171

72-
$this->assertEquals($connection1, $connection2);
73-
$this->assertNotEquals($connection3, $connection2);
72+
$this->assertSame($connection1, $connection2);
73+
$this->assertNotSame($connection3, $connection2);
7474
}
7575

7676
public function testInitialQueriesAreExecuted()
@@ -86,13 +86,13 @@ public function testInitialQueriesAreExecuted()
8686

8787
$usedDatabaseName = $this->module->dbh->query('SELECT DATABASE();')->fetch(PDO::FETCH_COLUMN);
8888

89-
$this->assertEquals($dbName, $usedDatabaseName);
89+
$this->assertSame($dbName, $usedDatabaseName);
9090
}
9191

9292
public function testGrabColumnFromDatabase()
9393
{
9494
$emails = $this->module->grabColumnFromDatabase('users', 'email');
95-
$this->assertEquals(
95+
$this->assertSame(
9696
[
9797
9898

tests/unit/Codeception/Module/Db/Populator/DbPopulatorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testCommandBuilderInterpolatesVariables()
2424
]
2525
);
2626

27-
$this->assertEquals(
27+
$this->assertSame(
2828
['mysql -u root -h 127.0.0.1 -D my_db < tests/data/dumps/sqlite.sql'],
2929
$dbPopulator->buildCommands()
3030
);
@@ -46,7 +46,7 @@ public function testCommandBuilderInterpolatesVariablesMultiDump()
4646
]
4747
);
4848

49-
$this->assertEquals(
49+
$this->assertSame(
5050
[
5151
'mysql -u root -h 127.0.0.1 -D my_db < tests/data/dumps/sqlite.sql',
5252
'mysql -u root -h 127.0.0.1 -D my_db < tests/data/dumps/sqlite2.sql'
@@ -61,7 +61,7 @@ public function testCommandBuilderWontTouchVariablesNotFound()
6161
'populator' => 'noop_tool -u $user -h $host -D $dbname < $dump',
6262
'user' => 'root',
6363
]);
64-
$this->assertEquals(
64+
$this->assertSame(
6565
['noop_tool -u root -h $host -D $dbname < $dump'],
6666
$dbPopulator->buildCommands()
6767
);

tests/unit/Codeception/Module/Db/SqliteDbTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ public function testConnectionIsResetOnEveryTestWhenReconnectIsTrue()
7171
$connection3 = spl_object_hash($this->module->dbh);
7272
$this->module->_after($testCase3);
7373

74-
$this->assertEquals($connection1, $connection2);
75-
$this->assertNotEquals($connection3, $connection2);
74+
$this->assertSame($connection1, $connection2);
75+
$this->assertNotSame($connection3, $connection2);
7676
}
7777

7878
public function testMultiDatabase()

0 commit comments

Comments
 (0)