CleanupInvitationTokenJobTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\DAV\Tests\unit\BackgroundJob;
  8. use OCA\DAV\BackgroundJob\CleanupInvitationTokenJob;
  9. use OCP\AppFramework\Utility\ITimeFactory;
  10. use OCP\DB\QueryBuilder\IQueryBuilder;
  11. use OCP\IDBConnection;
  12. use Test\TestCase;
  13. class CleanupInvitationTokenJobTest extends TestCase {
  14. /** @var IDBConnection | \PHPUnit\Framework\MockObject\MockObject */
  15. private $dbConnection;
  16. /** @var ITimeFactory | \PHPUnit\Framework\MockObject\MockObject */
  17. private $timeFactory;
  18. /** @var \OCA\DAV\BackgroundJob\CleanupInvitationTokenJob */
  19. private $backgroundJob;
  20. protected function setUp(): void {
  21. parent::setUp();
  22. $this->dbConnection = $this->createMock(IDBConnection::class);
  23. $this->timeFactory = $this->createMock(ITimeFactory::class);
  24. $this->backgroundJob = new CleanupInvitationTokenJob(
  25. $this->dbConnection, $this->timeFactory);
  26. }
  27. public function testRun(): void {
  28. $this->timeFactory->expects($this->once())
  29. ->method('getTime')
  30. ->with()
  31. ->willReturn(1337);
  32. $queryBuilder = $this->createMock(IQueryBuilder::class);
  33. $expr = $this->createMock(\OCP\DB\QueryBuilder\IExpressionBuilder::class);
  34. $stmt = $this->createMock(\Doctrine\DBAL\Driver\Statement::class);
  35. $this->dbConnection->expects($this->once())
  36. ->method('getQueryBuilder')
  37. ->with()
  38. ->willReturn($queryBuilder);
  39. $queryBuilder->method('expr')
  40. ->willReturn($expr);
  41. $queryBuilder->method('createNamedParameter')
  42. ->willReturnMap([
  43. [1337, \PDO::PARAM_STR, null, 'namedParameter1337']
  44. ]);
  45. $function = 'function1337';
  46. $expr->expects($this->once())
  47. ->method('lt')
  48. ->with('expiration', 'namedParameter1337')
  49. ->willReturn($function);
  50. $this->dbConnection->expects($this->once())
  51. ->method('getQueryBuilder')
  52. ->with()
  53. ->willReturn($queryBuilder);
  54. $queryBuilder->expects($this->once())
  55. ->method('delete')
  56. ->with('calendar_invitations')
  57. ->willReturn($queryBuilder);
  58. $queryBuilder->expects($this->once())
  59. ->method('where')
  60. ->with($function)
  61. ->willReturn($queryBuilder);
  62. $queryBuilder->expects($this->once())
  63. ->method('execute')
  64. ->with()
  65. ->willReturn($stmt);
  66. $this->backgroundJob->run([]);
  67. }
  68. }