Skip to content

Commit 38eea35

Browse files
committed
Replace test constant with private property
1 parent b2fe079 commit 38eea35

1 file changed

Lines changed: 19 additions & 19 deletions

File tree

test/DbTest.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
class DbTest extends TestCase
1717
{
18-
CONST TABLE_NAME = 'Users';
18+
private string $table = 'Users';
1919

2020
public static function tearDownAfterClass(): void
2121
{
@@ -79,8 +79,8 @@ public function testTransactions(PeachySql $peachySql): void
7979
'uuid' => $peachySql->makeBinaryParam(Uuid::uuid4()->getBytes(), 16),
8080
];
8181

82-
$id = $peachySql->insertRow(self::TABLE_NAME, $colVals)->id;
83-
$sql = 'SELECT user_id, isDisabled FROM Users WHERE user_id = ?';
82+
$id = $peachySql->insertRow($this->table, $colVals)->id;
83+
$sql = "SELECT user_id, isDisabled FROM {$this->table} WHERE user_id = ?";
8484
$result = $peachySql->query($sql, [$id]);
8585

8686
$this->assertSame(-1, $result->getAffected());
@@ -91,9 +91,9 @@ public function testTransactions(PeachySql $peachySql): void
9191
$this->assertSame(null, $sameRow); // the row should no longer exist
9292

9393
$peachySql->begin(); // start another transaction
94-
$newId = $peachySql->insertRow(self::TABLE_NAME, $colVals)->id;
94+
$newId = $peachySql->insertRow($this->table, $colVals)->id;
9595
$peachySql->commit(); // complete the transaction
96-
$newRow = $peachySql->selectFrom("SELECT user_id FROM " . self::TABLE_NAME)
96+
$newRow = $peachySql->selectFrom("SELECT user_id FROM {$this->table}")
9797
->where(['user_id' => $newId])->query()->getFirst();
9898

9999
$this->assertSame(['user_id' => $newId], $newRow); // the row should exist
@@ -144,8 +144,8 @@ public function testIteratorQuery(PeachySql $peachySql): void
144144
$insertColVals[] = $row;
145145
}
146146

147-
$ids = $peachySql->insertRows(self::TABLE_NAME, $insertColVals)->ids;
148-
$iterator = $peachySql->selectFrom("SELECT * FROM Users")
147+
$ids = $peachySql->insertRows($this->table, $insertColVals)->ids;
148+
$iterator = $peachySql->selectFrom("SELECT * FROM {$this->table}")
149149
->where(['user_id' => $ids])->query()->getIterator();
150150

151151
$this->assertInstanceOf(\Generator::class, $iterator);
@@ -160,7 +160,7 @@ public function testIteratorQuery(PeachySql $peachySql): void
160160
$this->assertSame($colVals, $colValsCompare);
161161

162162
// use a prepared statement to update both of the rows
163-
$sql = "UPDATE Users SET name = ? WHERE user_id = ?";
163+
$sql = "UPDATE {$this->table} SET name = ? WHERE user_id = ?";
164164
$_id = $_name = null;
165165
$stmt = $peachySql->prepare($sql, [&$_name, &$_id]);
166166

@@ -175,7 +175,7 @@ public function testIteratorQuery(PeachySql $peachySql): void
175175

176176
$stmt->close();
177177

178-
$updatedNames = $peachySql->selectFrom("SELECT name FROM " . self::TABLE_NAME)
178+
$updatedNames = $peachySql->selectFrom("SELECT name FROM {$this->table}")
179179
->where(['user_id' => $ids])->query()->getAll();
180180

181181
$expected = [
@@ -215,34 +215,34 @@ public function testInsertBulk(PeachySql $peachySql): void
215215
$insertColVals[] = $row;
216216
}
217217

218-
$result = $peachySql->insertRows(self::TABLE_NAME, $insertColVals);
218+
$result = $peachySql->insertRows($this->table, $insertColVals);
219219
$this->assertSame($expectedQueries, $result->queryCount);
220220
$this->assertSame($rowCount, $result->affected);
221221
$ids = $result->ids;
222222
$this->assertSame($rowCount, count($ids));
223223
$columns = implode(', ', array_keys($colVals[0]));
224224

225-
$rows = $peachySql->selectFrom("SELECT {$columns} FROM " . self::TABLE_NAME)
225+
$rows = $peachySql->selectFrom("SELECT {$columns} FROM {$this->table}")
226226
->where(['user_id' => $ids])->query()->getAll();
227227

228228
$this->assertSame($colVals, $rows);
229229

230230
// update the inserted rows
231-
$numUpdated = $peachySql->updateRows(self::TABLE_NAME, ['name' => 'updated'], ['user_id' => $ids]);
231+
$numUpdated = $peachySql->updateRows($this->table, ['name' => 'updated'], ['user_id' => $ids]);
232232
$this->assertSame($rowCount, $numUpdated);
233233

234234
// update a binary column
235235
$newUuid = Uuid::uuid4()->getBytes();
236236
$userId = $ids[0];
237237
$set = ['uuid' => $peachySql->makeBinaryParam($newUuid)];
238-
$peachySql->updateRows(self::TABLE_NAME, $set, ['user_id' => $userId]);
238+
$peachySql->updateRows($this->table, $set, ['user_id' => $userId]);
239239
/** @var array{uuid: string} $updatedRow */
240-
$updatedRow = $peachySql->selectFrom("SELECT uuid FROM " . self::TABLE_NAME)
240+
$updatedRow = $peachySql->selectFrom("SELECT uuid FROM {$this->table}")
241241
->where(['user_id' => $userId])->query()->getFirst();
242242
$this->assertSame($newUuid, $updatedRow['uuid']);
243243

244244
// delete the inserted rows
245-
$numDeleted = $peachySql->deleteFrom(self::TABLE_NAME, ['user_id' => $ids]);
245+
$numDeleted = $peachySql->deleteFrom($this->table, ['user_id' => $ids]);
246246
$this->assertSame($rowCount, $numDeleted);
247247
}
248248

@@ -251,7 +251,7 @@ public function testInsertBulk(PeachySql $peachySql): void
251251
*/
252252
public function testEmptyBulkInsert(PeachySql $peachySql): void
253253
{
254-
$result = $peachySql->insertRows(self::TABLE_NAME, []);
254+
$result = $peachySql->insertRows($this->table, []);
255255
$this->assertSame(0, $result->affected);
256256
$this->assertSame(0, $result->queryCount);
257257
$this->assertEmpty($result->ids);
@@ -263,15 +263,15 @@ public function testEmptyBulkInsert(PeachySql $peachySql): void
263263
public function testSelectFromBinding(PeachySql $peachySql): void
264264
{
265265
$row = ['name' => 'Test User', 'dob' => '2000-01-01', 'weight' => 123, 'isDisabled' => true];
266-
$id = $peachySql->insertRow(self::TABLE_NAME, $row)->id;
266+
$id = $peachySql->insertRow($this->table, $row)->id;
267267

268-
$result = $peachySql->select(new SqlParams("SELECT name, ? AS bound FROM " . self::TABLE_NAME, ['value']))
268+
$result = $peachySql->select(new SqlParams("SELECT name, ? AS bound FROM {$this->table}", ['value']))
269269
->where(['user_id' => $id])->query()->getFirst();
270270

271271
$this->assertSame(['name' => 'Test User', 'bound' => 'value'], $result);
272272

273273
// delete the inserted row
274-
$numDeleted = $peachySql->deleteFrom(self::TABLE_NAME, ['user_id' => $id]);
274+
$numDeleted = $peachySql->deleteFrom($this->table, ['user_id' => $id]);
275275
$this->assertSame(1, $numDeleted);
276276
}
277277
}

0 commit comments

Comments
 (0)