From 7ab7e31b8dcb4c87fa9417bb44544d2db6617ca7 Mon Sep 17 00:00:00 2001 From: Richard Steinmetz Date: Sun, 1 Feb 2026 12:12:48 +0100 Subject: [PATCH 1/2] test: update phpunit config and add some more tests Signed-off-by: Richard Steinmetz --- .gitignore | 1 + composer.json | 5 +- composer.lock | 6 +- tests/SizeHelperTest.php | 1 + .../PreviewLimiter/CountLimiterTest.php | 30 +++++++++ .../ExecutionTimeLimiterTest.php | 62 +++++++++++++++++++ .../PreviewLimiter/MultiLimiterTest.php | 62 +++++++++++++++++++ tests/phpunit.xml | 38 ++++++------ 8 files changed, 182 insertions(+), 23 deletions(-) create mode 100644 tests/Support/PreviewLimiter/CountLimiterTest.php create mode 100644 tests/Support/PreviewLimiter/ExecutionTimeLimiterTest.php create mode 100644 tests/Support/PreviewLimiter/MultiLimiterTest.php diff --git a/.gitignore b/.gitignore index 26fc041..51f3fe7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ /vendor /.php-cs-fixer.cache /tests/.phpunit.result.cache +/tests/coverage /build .DS_store diff --git a/composer.json b/composer.json index c8c2be0..f2b6401 100644 --- a/composer.json +++ b/composer.json @@ -4,14 +4,15 @@ "optimize-autoloader": true, "classmap-authoritative": true, "platform": { - "php": "7.4" + "php": "8.1" } }, "scripts": { "cs:fix": "php-cs-fixer fix", "cs:check": "php-cs-fixer fix --dry-run --diff", "lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l", - "test:unit": "phpunit -c tests/phpunit.xml tests" + "test:unit": "phpunit -c tests/phpunit.xml tests", + "test:unit:coverage": "XDEBUG_MODE=coverage phpunit -c tests/phpunit.xml tests" }, "require-dev": { "nextcloud/coding-standard": "^1.0.0", diff --git a/composer.lock b/composer.lock index 5b707f1..4ebe5d3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "39f016d7b93abbad00049069eb5d4343", + "content-hash": "c21e62c783a7e77a89d79ac843da833a", "packages": [], "packages-dev": [ { @@ -1953,7 +1953,7 @@ "platform": {}, "platform-dev": {}, "platform-overrides": { - "php": "7.4" + "php": "8.1" }, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.9.0" } diff --git a/tests/SizeHelperTest.php b/tests/SizeHelperTest.php index 1fe4816..9b95ffa 100644 --- a/tests/SizeHelperTest.php +++ b/tests/SizeHelperTest.php @@ -19,6 +19,7 @@ class SizeHelperTest extends TestCase { private SizeHelper $sizeHelper; private IConfig|MockObject $config; + private ConfigService&MockObject $configService; public function setUp(): void { parent::setUp(); diff --git a/tests/Support/PreviewLimiter/CountLimiterTest.php b/tests/Support/PreviewLimiter/CountLimiterTest.php new file mode 100644 index 0000000..7f5f495 --- /dev/null +++ b/tests/Support/PreviewLimiter/CountLimiterTest.php @@ -0,0 +1,30 @@ +assertTrue($limiter->next()); + $this->assertTrue($limiter->next()); + $this->assertTrue($limiter->next()); + $this->assertFalse($limiter->next()); + } + + public function testNextWithZeroPreviews(): void { + $limiter = new CountLimiter(0); + + $this->assertFalse($limiter->next()); + } +} diff --git a/tests/Support/PreviewLimiter/ExecutionTimeLimiterTest.php b/tests/Support/PreviewLimiter/ExecutionTimeLimiterTest.php new file mode 100644 index 0000000..45953a1 --- /dev/null +++ b/tests/Support/PreviewLimiter/ExecutionTimeLimiterTest.php @@ -0,0 +1,62 @@ +time = $this->createMock(TimeFactory::class); + } + + public function testNext(): void { + $now = 1000; + + $this->time->expects(self::exactly(4)) + ->method('getTime') + ->willReturnCallback(static function () use (&$now) { + return $now; + }); + + $limiter = new ExecutionTimeLimiter($this->time, 10); + + $this->assertTrue($limiter->next()); + + $now = 1010; + $this->assertFalse($limiter->next()); + + $now = 1100; + $this->assertFalse($limiter->next()); + } + + public function testNextWithZeroExecutionTime(): void { + $now = 1000; + + $this->time->expects(self::exactly(3)) + ->method('getTime') + ->willReturnCallback(static function () use (&$now) { + return $now; + }); + + $limiter = new ExecutionTimeLimiter($this->time, 0); + + $this->assertFalse($limiter->next()); + + $now = 1100; + $this->assertFalse($limiter->next()); + } +} diff --git a/tests/Support/PreviewLimiter/MultiLimiterTest.php b/tests/Support/PreviewLimiter/MultiLimiterTest.php new file mode 100644 index 0000000..522227e --- /dev/null +++ b/tests/Support/PreviewLimiter/MultiLimiterTest.php @@ -0,0 +1,62 @@ +createMock(PreviewLimiter::class); + $limiter2 = $this->createMock(PreviewLimiter::class); + + $limiter1Next = true; + $limiter2Next = true; + + $limiter1->expects(self::exactly(6)) + ->method('next') + ->willReturnCallback(static function () use (&$limiter1Next) { + return $limiter1Next; + }); + $limiter2->expects(self::exactly(4)) + ->method('next') + ->willReturnCallback(static function () use (&$limiter2Next) { + return $limiter2Next; + }); + + $limiter = new MultiLimiter([$limiter1, $limiter2]); + + $this->assertTrue($limiter->next()); + $this->assertTrue($limiter->next()); + + $limiter1Next = false; + $this->assertFalse($limiter->next()); + + $limiter1Next = true; + $limiter2Next = false; + $this->assertFalse($limiter->next()); + + $limiter1Next = false; + $limiter2Next = false; + $this->assertFalse($limiter->next()); + + $limiter1Next = true; + $limiter2Next = true; + $this->assertTrue($limiter->next()); + } + + public function testNextWithoutLimiters(): void { + $limiter = new MultiLimiter([]); + + $this->assertTrue($limiter->next()); + $this->assertTrue($limiter->next()); + } +} diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 87106f7..64ad7ad 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -1,28 +1,30 @@ - + - - - . - - - - - ../ - - ../tests - - - - - - - + + + ../ + + + ../tests + ../vendor + ../.php-cs-fixer.dist.php + + + + + + + . + From d64f84dce1fb36bcf2b89bcd9351694581207783 Mon Sep 17 00:00:00 2001 From: Richard Steinmetz Date: Sun, 1 Feb 2026 12:26:45 +0100 Subject: [PATCH 2/2] test: rename Test to ModuloServiceTest Signed-off-by: Richard Steinmetz --- tests/Service/{Test.php => ModuloServiceTest.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/Service/{Test.php => ModuloServiceTest.php} (93%) diff --git a/tests/Service/Test.php b/tests/Service/ModuloServiceTest.php similarity index 93% rename from tests/Service/Test.php rename to tests/Service/ModuloServiceTest.php index b8a90ab..8402782 100644 --- a/tests/Service/Test.php +++ b/tests/Service/ModuloServiceTest.php @@ -12,7 +12,7 @@ use OCA\PreviewGenerator\Service\ModuloService; use PHPUnit\Framework\TestCase; -class Test extends TestCase { +class ModuloServiceTest extends TestCase { public static function moduloDataProvider(): array { return [ [3, 10, 3],