Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
/vendor
/.php-cs-fixer.cache
/tests/.phpunit.result.cache
/tests/coverage
/build
.DS_store
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
1 change: 1 addition & 0 deletions tests/SizeHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
30 changes: 30 additions & 0 deletions tests/Support/PreviewLimiter/CountLimiterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\PreviewGenerator\Tests\Support\PreviewLimiter;

use OCA\PreviewGenerator\Support\PreviewLimiter\CountLimiter;
use PHPUnit\Framework\TestCase;

class CountLimiterTest extends TestCase {
public function testNext(): void {
$limiter = new CountLimiter(3);

$this->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());
}
}
62 changes: 62 additions & 0 deletions tests/Support/PreviewLimiter/ExecutionTimeLimiterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\PreviewGenerator\Tests\Support\PreviewLimiter;

use OC\AppFramework\Utility\TimeFactory;
use OCA\PreviewGenerator\Support\PreviewLimiter\ExecutionTimeLimiter;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class ExecutionTimeLimiterTest extends TestCase {
private TimeFactory&MockObject $time;

protected function setUp(): void {
parent::setUp();

$this->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());
}
}
62 changes: 62 additions & 0 deletions tests/Support/PreviewLimiter/MultiLimiterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\PreviewGenerator\Tests\Support\PreviewLimiter;

use OCA\PreviewGenerator\Support\PreviewLimiter\MultiLimiter;
use OCA\PreviewGenerator\Support\PreviewLimiter\PreviewLimiter;
use PHPUnit\Framework\TestCase;

class MultiLimiterTest extends TestCase {
public function testNext(): void {
$limiter1 = $this->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());
}
}
38 changes: 20 additions & 18 deletions tests/phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<!--
- SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<phpunit bootstrap="bootstrap.php"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="bootstrap.php"
verbose="true"
timeoutForSmallTests="900"
timeoutForMediumTests="900"
timeoutForLargeTests="900"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
>
<testsuite name='Preview generator tests'>
<directory suffix='Test.php'>.</directory>
</testsuite>
<!-- filters for code coverage -->
<filter>
<whitelist>
<directory suffix=".php">../</directory>
<exclude>
<directory suffix=".php">../tests</directory>
</exclude>
</whitelist>
</filter>
<logging>
<!-- and this is where your report will be written -->
<log type="coverage-clover" target="./clover.xml"/>
</logging>
<coverage>
<include>
<directory suffix=".php">../</directory>
</include>
<exclude>
<directory suffix=".php">../tests</directory>
<directory suffix=".php">../vendor</directory>
<file>../.php-cs-fixer.dist.php</file>
</exclude>
<report>
<html outputDirectory="./coverage"/>
</report>
</coverage>
<testsuite name="Preview generator tests">
<directory suffix="Test.php">.</directory>
</testsuite>
</phpunit>
Loading