|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 7 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 8 | + */ |
| 9 | + |
| 10 | +namespace OCA\PreviewGenerator\Tests\Support\PreviewLimiter; |
| 11 | + |
| 12 | +use OCA\PreviewGenerator\Support\PreviewLimiter\MultiLimiter; |
| 13 | +use OCA\PreviewGenerator\Support\PreviewLimiter\PreviewLimiter; |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | + |
| 16 | +class MultiLimiterTest extends TestCase { |
| 17 | + public function testNext(): void { |
| 18 | + $limiter1 = $this->createMock(PreviewLimiter::class); |
| 19 | + $limiter2 = $this->createMock(PreviewLimiter::class); |
| 20 | + |
| 21 | + $limiter1Next = true; |
| 22 | + $limiter2Next = true; |
| 23 | + |
| 24 | + $limiter1->expects(self::exactly(6)) |
| 25 | + ->method('next') |
| 26 | + ->willReturnCallback(static function () use (&$limiter1Next) { |
| 27 | + return $limiter1Next; |
| 28 | + }); |
| 29 | + $limiter2->expects(self::exactly(4)) |
| 30 | + ->method('next') |
| 31 | + ->willReturnCallback(static function () use (&$limiter2Next) { |
| 32 | + return $limiter2Next; |
| 33 | + }); |
| 34 | + |
| 35 | + $limiter = new MultiLimiter([$limiter1, $limiter2]); |
| 36 | + |
| 37 | + $this->assertTrue($limiter->next()); |
| 38 | + $this->assertTrue($limiter->next()); |
| 39 | + |
| 40 | + $limiter1Next = false; |
| 41 | + $this->assertFalse($limiter->next()); |
| 42 | + |
| 43 | + $limiter1Next = true; |
| 44 | + $limiter2Next = false; |
| 45 | + $this->assertFalse($limiter->next()); |
| 46 | + |
| 47 | + $limiter1Next = false; |
| 48 | + $limiter2Next = false; |
| 49 | + $this->assertFalse($limiter->next()); |
| 50 | + |
| 51 | + $limiter1Next = true; |
| 52 | + $limiter2Next = true; |
| 53 | + $this->assertTrue($limiter->next()); |
| 54 | + } |
| 55 | + |
| 56 | + public function testNextWithoutLimiters(): void { |
| 57 | + $limiter = new MultiLimiter([]); |
| 58 | + |
| 59 | + $this->assertTrue($limiter->next()); |
| 60 | + $this->assertTrue($limiter->next()); |
| 61 | + } |
| 62 | +} |
0 commit comments