Skip to content

Commit 14a1b48

Browse files
committed
chore(replace-fetch-all-method-rector): Add unit test
Signed-off-by: Carl Schwan <carl.schwan@nextcloud.com>
1 parent 7470c42 commit 14a1b48

3 files changed

Lines changed: 103 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace OCP\AppFramework;
4+
5+
use OCP\IDBConnection;
6+
use PDO;
7+
8+
class SomeClass
9+
{
10+
public function __construct(IDBConnection $connection) {
11+
$qb = $connection->getQueryBuilder();
12+
$result = $qb->select('*')
13+
->from('pages')
14+
->executeQuery();
15+
16+
$result->fetchAll();
17+
$result->fetchAll(PDO::FETCH_COLUMN);
18+
$result->fetchAll(PDO::FETCH_ASSOC);
19+
$result->fetchAll(PDO::FETCH_NUM);
20+
21+
$result->fetch(PDO::FETCH_COLUMN);
22+
$result->fetch(PDO::FETCH_ASSOC);
23+
$result->fetch();
24+
$result->fetch(PDO::FETCH_NUM);
25+
}
26+
}
27+
28+
?>
29+
-----
30+
<?php
31+
32+
namespace OCP\AppFramework;
33+
34+
use OCP\IDBConnection;
35+
use PDO;
36+
37+
class SomeClass
38+
{
39+
public function __construct(IDBConnection $connection) {
40+
$qb = $connection->getQueryBuilder();
41+
$result = $qb->select('*')
42+
->from('pages')
43+
->executeQuery();
44+
45+
$result->fetchAllAssociative();
46+
$result->fetchFirstColumn();
47+
$result->fetchAllAssociative();
48+
$result->fetchAllNumeric();
49+
50+
$result->fetchOne();
51+
$result->fetchAssociative();
52+
$result->fetchAssociative();
53+
$result->fetchNumeric();
54+
}
55+
}
56+
57+
?>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace Nextcloud\Rector\Test\Rector\ReplaceFetchAllMethodCallRector;
11+
12+
use Iterator;
13+
use PHPUnit\Framework\Attributes\DataProvider;
14+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
15+
16+
final class ReplaceFetchAllMethodCallRectorTest extends AbstractRectorTestCase
17+
{
18+
#[DataProvider('provideData')]
19+
public function test(string $filePath): void
20+
{
21+
$this->doTestFile($filePath);
22+
}
23+
24+
public static function provideData(): Iterator
25+
{
26+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
27+
}
28+
29+
public function provideConfigFilePath(): string
30+
{
31+
return __DIR__ . '/config/config.php';
32+
}
33+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Nextcloud\Rector\Rector\RenameParameterRector;
6+
use Nextcloud\Rector\Rector\ReplaceFetchAllMethodCallRector;
7+
use Nextcloud\Rector\ValueObject\RenameParameter;
8+
use Rector\Config\RectorConfig;
9+
10+
return RectorConfig::configure()
11+
->withRules([
12+
ReplaceFetchAllMethodCallRector::class,
13+
]);

0 commit comments

Comments
 (0)