diff options
Diffstat (limited to 'tests/Unit/Service/ServiceTest.php')
-rw-r--r-- | tests/Unit/Service/ServiceTest.php | 66 |
1 files changed, 40 insertions, 26 deletions
diff --git a/tests/Unit/Service/ServiceTest.php b/tests/Unit/Service/ServiceTest.php index ce4e2e61f..cfaf82c95 100644 --- a/tests/Unit/Service/ServiceTest.php +++ b/tests/Unit/Service/ServiceTest.php @@ -15,6 +15,7 @@ namespace OCA\News\Tests\Unit\Service; use OCA\News\Db\Feed; use OCA\News\Db\ItemMapper; +use OCA\News\Db\ItemMapperV2; use OCA\News\Service\Exceptions\ServiceNotFoundException; use OCA\News\Service\Service; use \OCP\AppFramework\Db\DoesNotExistException; @@ -24,41 +25,24 @@ use \OCA\News\Db\Folder; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; - -class TestLegacyService extends Service -{ - public function __construct($mapper, $logger) - { - parent::__construct($mapper, $logger); - } - - public function findAllForUser(string $userId, array $params = []): array - { - // TODO: Implement findAllForUser() method. - } - - public function findAll(): array - { - // TODO: Implement findAll() method. - } -} - class ServiceTest extends TestCase { protected $mapper; protected $logger; - protected $newsService; + protected $class; protected function setUp(): void { - $this->mapper = $this->getMockBuilder(ItemMapper::class) + $this->mapper = $this->getMockBuilder(ItemMapperV2::class) ->disableOriginalConstructor() ->getMock(); $this->logger = $this->getMockBuilder(LoggerInterface::class) ->disableOriginalConstructor() ->getMock(); - $this->newsService = new TestLegacyService($this->mapper, $this->logger); + $this->class = $this->getMockBuilder(Service::class) + ->setConstructorArgs([$this->mapper, $this->logger]) + ->getMockForAbstractClass(); } @@ -77,7 +61,19 @@ class ServiceTest extends TestCase ->with($this->equalTo($user), $this->equalTo($id)) ->will($this->returnValue($folder)); - $this->newsService->delete($user, $id); + $this->class->delete($user, $id); + } + + + public function testInsert() + { + $folder = new Folder(); + + $this->mapper->expects($this->once()) + ->method('insert') + ->with($this->equalTo($folder)); + + $this->class->insert($folder); } @@ -91,7 +87,7 @@ class ServiceTest extends TestCase ->with($this->equalTo($user), $this->equalTo($id)) ->will($this->returnValue(new Feed())); - $this->newsService->find($user, $id); + $this->class->find($user, $id); } @@ -104,7 +100,7 @@ class ServiceTest extends TestCase ->will($this->throwException($ex)); $this->expectException(ServiceNotFoundException::class); - $this->newsService->find('', 1); + $this->class->find('', 1); } @@ -117,7 +113,25 @@ class ServiceTest extends TestCase ->will($this->throwException($ex)); $this->expectException(ServiceNotFoundException::class); - $this->newsService->find('', 1); + $this->class->find('', 1); + } + + + public function testDeleteUser() + { + $feed1 = Feed::fromParams(['id' => 1]); + $feed2 = Feed::fromParams(['id' => 2]); + + $this->class->expects($this->once()) + ->method('findAllForUser') + ->with('') + ->willReturn([$feed1, $feed2]); + + $this->mapper->expects($this->exactly(2)) + ->method('delete') + ->withConsecutive([$feed1], [$feed2]); + + $this->class->deleteUser(''); } } |