CleanupInvitationTokenJobTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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\IExpressionBuilder;
  11. use OCP\DB\QueryBuilder\IQueryBuilder;
  12. use OCP\IDBConnection;
  13. use Test\TestCase;
  14. class CleanupInvitationTokenJobTest extends TestCase {
  15. /** @var IDBConnection | \PHPUnit\Framework\MockObject\MockObject */
  16. private $dbConnection;
  17. /** @var ITimeFactory | \PHPUnit\Framework\MockObject\MockObject */
  18. private $timeFactory;
  19. /** @var CleanupInvitationTokenJob */
  20. private $backgroundJob;
  21. protected function setUp(): void {
  22. parent::setUp();
  23. $this->dbConnection = $this->createMock(IDBConnection::class);
  24. $this->timeFactory = $this->createMock(ITimeFactory::class);
  25. $this->backgroundJob = new CleanupInvitationTokenJob(
  26. $this->dbConnection, $this->timeFactory);
  27. }
  28. public function testRun(): void {
  29. $this->timeFactory->expects($this->once())
  30. ->method('getTime')
  31. ->with()
  32. ->willReturn(1337);
  33. $queryBuilder = $this->createMock(IQueryBuilder::class);
  34. $expr = $this->createMock(IExpressionBuilder::class);
  35. $stmt = $this->createMock(\Doctrine\DBAL\Driver\Statement::class);
  36. $this->dbConnection->expects($this->once())
  37. ->method('getQueryBuilder')
  38. ->with()
  39. ->willReturn($queryBuilder);
  40. $queryBuilder->method('expr')
  41. ->willReturn($expr);
  42. $queryBuilder->method('createNamedParameter')
  43. ->willReturnMap([
  44. [1337, \PDO::PARAM_STR, null, 'namedParameter1337']
  45. ]);
  46. $function = 'function1337';
  47. $expr->expects($this->once())
  48. ->method('lt')
  49. ->with('expiration', 'namedParameter1337')
  50. ->willReturn($function);
  51. $this->dbConnection->expects($this->once())
  52. ->method('getQueryBuilder')
  53. ->with()
  54. ->willReturn($queryBuilder);
  55. $queryBuilder->expects($this->once())
  56. ->method('delete')
  57. ->with('calendar_invitations')
  58. ->willReturn($queryBuilder);
  59. $queryBuilder->expects($this->once())
  60. ->method('where')
  61. ->with($function)
  62. ->willReturn($queryBuilder);
  63. $queryBuilder->expects($this->once())
  64. ->method('execute')
  65. ->with()
  66. ->willReturn($stmt);
  67. $this->backgroundJob->run([]);
  68. }
  69. }