From ed066a812914b84c8f0c44e0e6be432638a3e038 Mon Sep 17 00:00:00 2001 From: anoy Date: Sat, 17 Jul 2021 19:33:36 +0200 Subject: adapt tests to QBMapper changes in NC22 Signed-off-by: anoy --- tests/Unit/Db/FeedMapperTest.php | 32 ++++++++-------- tests/Unit/Db/FolderMapperTest.php | 20 +++++----- tests/Unit/Db/ItemMapperAfterTest.php | 32 ++++++++-------- tests/Unit/Db/ItemMapperPaginatedTest.php | 64 +++++++++++++++---------------- tests/Unit/Db/ItemMapperTest.php | 32 ++++++++-------- tests/Unit/Db/MapperTestUtility.php | 19 +++------ 6 files changed, 95 insertions(+), 104 deletions(-) diff --git a/tests/Unit/Db/FeedMapperTest.php b/tests/Unit/Db/FeedMapperTest.php index ad2417b53..c42ffee67 100644 --- a/tests/Unit/Db/FeedMapperTest.php +++ b/tests/Unit/Db/FeedMapperTest.php @@ -119,8 +119,8 @@ class FeedMapperTest extends MapperTestUtility ->will($this->returnSelf()); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(3)) ->method('fetch') @@ -169,8 +169,8 @@ class FeedMapperTest extends MapperTestUtility ->will($this->returnSelf()); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -218,8 +218,8 @@ class FeedMapperTest extends MapperTestUtility ->will($this->returnSelf()); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(1)) ->method('fetch') @@ -266,8 +266,8 @@ class FeedMapperTest extends MapperTestUtility ->will($this->returnSelf()); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -316,8 +316,8 @@ class FeedMapperTest extends MapperTestUtility ->will($this->returnSelf()); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -355,8 +355,8 @@ class FeedMapperTest extends MapperTestUtility ->will($this->returnSelf()); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(3)) ->method('fetch') @@ -400,8 +400,8 @@ class FeedMapperTest extends MapperTestUtility ->will($this->returnSelf()); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(3)) ->method('fetch') @@ -440,8 +440,8 @@ class FeedMapperTest extends MapperTestUtility ->will($this->returnSelf()); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(3)) ->method('fetch') diff --git a/tests/Unit/Db/FolderMapperTest.php b/tests/Unit/Db/FolderMapperTest.php index ad44d618f..3e15e8004 100644 --- a/tests/Unit/Db/FolderMapperTest.php +++ b/tests/Unit/Db/FolderMapperTest.php @@ -81,8 +81,8 @@ class FolderMapperTest extends MapperTestUtility ->will($this->returnSelf()); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(3)) ->method('fetch') @@ -131,8 +131,8 @@ class FolderMapperTest extends MapperTestUtility ->will($this->returnSelf()); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -180,8 +180,8 @@ class FolderMapperTest extends MapperTestUtility ->will($this->returnSelf()); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(1)) ->method('fetch') @@ -229,8 +229,8 @@ class FolderMapperTest extends MapperTestUtility ->will($this->returnSelf()); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -268,8 +268,8 @@ class FolderMapperTest extends MapperTestUtility ->will($this->returnSelf()); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(3)) ->method('fetch') diff --git a/tests/Unit/Db/ItemMapperAfterTest.php b/tests/Unit/Db/ItemMapperAfterTest.php index 9b6f02655..016db1739 100644 --- a/tests/Unit/Db/ItemMapperAfterTest.php +++ b/tests/Unit/Db/ItemMapperAfterTest.php @@ -92,8 +92,8 @@ class ItemMapperAfterTest extends MapperTestUtility ->willReturnSelf(); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -163,8 +163,8 @@ class ItemMapperAfterTest extends MapperTestUtility ->willReturnSelf(); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -231,8 +231,8 @@ class ItemMapperAfterTest extends MapperTestUtility ->willReturnSelf(); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -305,8 +305,8 @@ class ItemMapperAfterTest extends MapperTestUtility ->willReturnSelf(); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -374,8 +374,8 @@ class ItemMapperAfterTest extends MapperTestUtility ->willReturnSelf(); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -443,8 +443,8 @@ class ItemMapperAfterTest extends MapperTestUtility ->willReturnSelf(); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -506,8 +506,8 @@ class ItemMapperAfterTest extends MapperTestUtility ->willReturnSelf(); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -572,8 +572,8 @@ class ItemMapperAfterTest extends MapperTestUtility ->willReturnSelf(); $this->builder->expects($this->never()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->never()) ->method('fetch') diff --git a/tests/Unit/Db/ItemMapperPaginatedTest.php b/tests/Unit/Db/ItemMapperPaginatedTest.php index 652e2fa98..9d44e0756 100644 --- a/tests/Unit/Db/ItemMapperPaginatedTest.php +++ b/tests/Unit/Db/ItemMapperPaginatedTest.php @@ -98,8 +98,8 @@ class ItemMapperPaginatedTest extends MapperTestUtility ->willReturnSelf(); $this->builder->expects($this->never()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->never()) ->method('fetch') @@ -164,8 +164,8 @@ class ItemMapperPaginatedTest extends MapperTestUtility ->willReturnSelf(); $this->builder->expects($this->exactly(1)) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -235,8 +235,8 @@ class ItemMapperPaginatedTest extends MapperTestUtility ->willReturnSelf(); $this->builder->expects($this->exactly(1)) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -304,8 +304,8 @@ class ItemMapperPaginatedTest extends MapperTestUtility ->willReturnSelf(); $this->builder->expects($this->exactly(1)) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -376,8 +376,8 @@ class ItemMapperPaginatedTest extends MapperTestUtility ->willReturnSelf(); $this->builder->expects($this->exactly(1)) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -460,8 +460,8 @@ class ItemMapperPaginatedTest extends MapperTestUtility ->willReturnSelf(); $this->builder->expects($this->exactly(1)) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -533,8 +533,8 @@ class ItemMapperPaginatedTest extends MapperTestUtility ->willReturnSelf(); $this->builder->expects($this->exactly(1)) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -604,8 +604,8 @@ class ItemMapperPaginatedTest extends MapperTestUtility ->willReturnSelf(); $this->builder->expects($this->exactly(1)) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -675,8 +675,8 @@ class ItemMapperPaginatedTest extends MapperTestUtility ->willReturnSelf(); $this->builder->expects($this->exactly(1)) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -749,8 +749,8 @@ class ItemMapperPaginatedTest extends MapperTestUtility ->willReturnSelf(); $this->builder->expects($this->exactly(1)) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -833,8 +833,8 @@ class ItemMapperPaginatedTest extends MapperTestUtility ->willReturnSelf(); $this->builder->expects($this->exactly(1)) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -918,8 +918,8 @@ class ItemMapperPaginatedTest extends MapperTestUtility ->willReturnSelf(); $this->builder->expects($this->exactly(1)) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -1001,8 +1001,8 @@ class ItemMapperPaginatedTest extends MapperTestUtility ->willReturnSelf(); $this->builder->expects($this->exactly(1)) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -1087,8 +1087,8 @@ class ItemMapperPaginatedTest extends MapperTestUtility ->willReturnSelf(); $this->builder->expects($this->exactly(1)) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -1173,8 +1173,8 @@ class ItemMapperPaginatedTest extends MapperTestUtility ->willReturnSelf(); $this->builder->expects($this->exactly(1)) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -1263,8 +1263,8 @@ class ItemMapperPaginatedTest extends MapperTestUtility ->willReturnSelf(); $this->builder->expects($this->exactly(1)) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') diff --git a/tests/Unit/Db/ItemMapperTest.php b/tests/Unit/Db/ItemMapperTest.php index 15ebbac1a..2d831e784 100644 --- a/tests/Unit/Db/ItemMapperTest.php +++ b/tests/Unit/Db/ItemMapperTest.php @@ -107,8 +107,8 @@ class ItemMapperTest extends MapperTestUtility ->will($this->returnSelf()); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(3)) ->method('fetch') @@ -168,8 +168,8 @@ class ItemMapperTest extends MapperTestUtility ->will($this->returnSelf()); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(3)) ->method('fetch') @@ -213,8 +213,8 @@ class ItemMapperTest extends MapperTestUtility ->will($this->returnSelf()); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(3)) ->method('fetch') @@ -258,8 +258,8 @@ class ItemMapperTest extends MapperTestUtility ->will($this->returnSelf()); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(3)) ->method('fetch') @@ -310,8 +310,8 @@ class ItemMapperTest extends MapperTestUtility ->will($this->returnSelf()); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -351,8 +351,8 @@ class ItemMapperTest extends MapperTestUtility ->will($this->returnSelf()); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -397,8 +397,8 @@ class ItemMapperTest extends MapperTestUtility ->will($this->returnSelf()); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') @@ -458,8 +458,8 @@ class ItemMapperTest extends MapperTestUtility ->will($this->returnSelf()); $this->builder->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->cursor)); + ->method('executeQuery') + ->willReturn($this->cursor); $this->cursor->expects($this->exactly(2)) ->method('fetch') diff --git a/tests/Unit/Db/MapperTestUtility.php b/tests/Unit/Db/MapperTestUtility.php index b5ef782c2..5c58613ee 100644 --- a/tests/Unit/Db/MapperTestUtility.php +++ b/tests/Unit/Db/MapperTestUtility.php @@ -23,11 +23,10 @@ namespace OCA\News\Tests\Unit\Db; -use Doctrine\DBAL\Driver\Statement; +use OCP\DB\IResult; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; -use PDOStatement; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -42,18 +41,13 @@ abstract class MapperTestUtility extends TestCase */ protected $db; - /** - * @var MockObject|PDOStatement - */ - protected $query; - /** * @var MockObject|IQueryBuilder */ protected $builder; /** - * @var MockObject|Statement + * @var MockObject|IResult */ protected $cursor; @@ -70,15 +64,12 @@ abstract class MapperTestUtility extends TestCase ->disableOriginalConstructor() ->getMock(); - $this->query = $this->getMockBuilder(PDOStatement::class) - ->getMock(); - $this->builder = $this->getMockBuilder(IQueryBuilder::class) ->disableOriginalConstructor() ->getMock(); - $this->cursor = $this->getMockBuilder(Statement::class) - ->addMethods(['fetch', 'closeCursor']) - ->getMockForAbstractClass(); + $this->cursor = $this->getMockBuilder(IResult::class) + ->disableOriginalConstructor() + ->getMock(); } } -- cgit v1.2.3