Skip to content

Commit 4619ec0

Browse files
vjikrustamwin
andauthored
Adapt to Yii DB 2 (#88)
Co-authored-by: Rustam Mamadaminov <rmamdaminov@gmail.com>
1 parent effd280 commit 4619ec0

12 files changed

Lines changed: 66 additions & 53 deletions

.github/workflows/mssql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ jobs:
9494
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
9595

9696
- name: Install db-mssql
97-
run: composer require --dev "yiisoft/db-mssql:^1.1" --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
97+
run: composer require --dev "yiisoft/db-mssql:^2.0" --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
9898

9999
- name: Run tests with phpunit
100100
run: vendor/bin/phpunit --testsuite Mssql --coverage-clover=coverage.xml --colors=always

.github/workflows/mysql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
8686

8787
- name: Install db-mysql
88-
run: composer require --dev "yiisoft/db-mysql:^1.1" --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
88+
run: composer require --dev "yiisoft/db-mysql:^2.0" --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
8989

9090
- name: Run tests with phpunit
9191
run: vendor/bin/phpunit --testsuite Mysql --coverage-clover=coverage.xml --colors=always

.github/workflows/oracle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ jobs:
9191
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
9292

9393
- name: Install db-oracle
94-
run: composer require --dev "yiisoft/db-oracle:^1.2" --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
94+
run: composer require --dev "yiisoft/db-oracle:^2.0" --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
9595

9696
- name: Run tests with phpunit
9797
run: vendor/bin/phpunit --testsuite Oracle --coverage-clover=coverage.xml --colors=always

.github/workflows/pgsql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
9191

9292
- name: Install db-pgsql
93-
run: composer require --dev "yiisoft/db-pgsql:^1.2" --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
93+
run: composer require --dev "yiisoft/db-pgsql:^2.0" --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
9494

9595
- name: Run tests with phpunit
9696
run: vendor/bin/phpunit --testsuite Pgsql --coverage-clover=coverage.xml --colors=always

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 2.0.1 under development
44

55
- Enh #85: Refactor `AssignmentStorage::filterUserItemNames()` method (@vjik)
6+
- Chg #88: Adapt to Yii DB 2 (@vjik)
67
- Enh #91: Bump `yiisoft/rbac` version to `^2.1` (@vjik)
78
- Chg #92: Change PHP constraint in `composer.json` to `8.1 - 8.4` (@vjik)
89
- Enh #92: Mark internal class `ItemTreeTraversalFactory` as final (@vjik)

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
"require": {
3232
"php": "8.1 - 8.4",
3333
"ext-pdo": "*",
34-
"yiisoft/db": "^1.2",
35-
"yiisoft/db-migration": "^1.1",
34+
"yiisoft/db": "^2.0",
35+
"yiisoft/db-migration": "^2.0",
3636
"yiisoft/friendly-exception": "^1.1",
3737
"yiisoft/rbac": "^2.1"
3838
},
@@ -46,15 +46,15 @@
4646
"spatie/phpunit-watcher": "^1.24",
4747
"vimeo/psalm": "^5.26.1 || ^6.10",
4848
"yiisoft/cache": "^3.0",
49-
"yiisoft/db-sqlite": "^1.2"
49+
"yiisoft/db-sqlite": "^2.0"
5050
},
5151
"suggest": {
5252
"yiisoft/db-sqlite": "For using with SQLite",
5353
"yiisoft/db-mysql": "For using with MySQL",
5454
"yiisoft/db-pgsql": "For using with PosgtgreSQL",
5555
"yiisoft/db-mssql": "For using with Microsoft SQL Server",
5656
"yiisoft/db-oracle": "For using with Oracle",
57-
"yiisoft/yii-db-migration": "For automating schema migration"
57+
"yiisoft/db-migration": "For automating schema migration"
5858
},
5959
"autoload": {
6060
"psr-4": {

src/AssignmentsStorage.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public function getByUserId(string $userId): array
7676
public function getByItemNames(array $itemNames): array
7777
{
7878
if (empty($itemNames)) {
79+
/** @infection-ignore-all */
7980
return [];
8081
}
8182

@@ -123,6 +124,7 @@ public function exists(string $itemName, string $userId): bool
123124
public function userHasItem(string $userId, array $itemNames): bool
124125
{
125126
if (empty($itemNames)) {
127+
/** @infection-ignore-all */
126128
return false;
127129
}
128130

src/ItemsStorage.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public function getAll(): array
110110
public function getByNames(array $names): array
111111
{
112112
if (empty($names)) {
113+
/** @infection-ignore-all */
113114
return [];
114115
}
115116

@@ -167,6 +168,9 @@ public function update(string $name, Item $item): void
167168
$this
168169
->database
169170
->transaction(static function (ConnectionInterface $database) use ($itemsStorage, $name, $item): void {
171+
/**
172+
* @var array[] $itemsChildren We assume that arrays are returned here, not objects.
173+
*/
170174
$itemsChildren = (new Query($database))
171175
->from($itemsStorage->childrenTableName)
172176
->where(['parent' => $name])
@@ -198,7 +202,7 @@ static function (array $itemChild) use ($name, $item): array {
198202
);
199203
$database
200204
->createCommand()
201-
->batchInsert($itemsStorage->childrenTableName, ['parent', 'child'], $itemsChildren)
205+
->insertBatch($itemsStorage->childrenTableName, $itemsChildren, ['parent', 'child'])
202206
->execute();
203207
}
204208
});
@@ -224,6 +228,7 @@ public function getRoles(): array
224228
public function getRolesByNames(array $names): array
225229
{
226230
if (empty($names)) {
231+
/** @infection-ignore-all */
227232
return [];
228233
}
229234

@@ -255,6 +260,7 @@ public function getPermissions(): array
255260
public function getPermissionsByNames(array $names): array
256261
{
257262
if (empty($names)) {
263+
/** @infection-ignore-all */
258264
return [];
259265
}
260266

tests/Base/AssignmentsStorageTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ protected function populateItemsStorage(): void
3333
{
3434
$this->getDatabase()
3535
->createCommand()
36-
->batchInsert(
36+
->insertBatch(
3737
self::$itemsTable,
38-
['name', 'type', 'created_at', 'updated_at'],
3938
$this->getFixtures()['items'],
39+
['name', 'type', 'created_at', 'updated_at'],
4040
)
4141
->execute();
4242
}
@@ -45,10 +45,10 @@ protected function populateAssignmentsStorage(): void
4545
{
4646
$this->getDatabase()
4747
->createCommand()
48-
->batchInsert(
48+
->insertBatch(
4949
self::$assignmentsTable,
50-
['item_name', 'user_id', 'created_at'],
5150
$this->getFixtures()['assignments'],
51+
['item_name', 'user_id', 'created_at'],
5252
)
5353
->execute();
5454
}

tests/Base/ItemsStorageTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ protected function populateItemsStorage(): void
154154
$this
155155
->getDatabase()
156156
->createCommand()
157-
->batchInsert(self::$itemsTable, ['name', 'type', 'created_at', 'updated_at'], $fixtures['items'])
157+
->insertBatch(self::$itemsTable, $fixtures['items'], ['name', 'type', 'created_at', 'updated_at'])
158158
->execute();
159159
$this
160160
->getDatabase()
161161
->createCommand()
162-
->batchInsert(self::$itemsChildrenTable, ['parent', 'child'], $fixtures['itemsChildren'])
162+
->insertBatch(self::$itemsChildrenTable, $fixtures['itemsChildren'], ['parent', 'child'])
163163
->execute();
164164
}
165165

0 commit comments

Comments
 (0)