Skip to content
Open
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
2 changes: 1 addition & 1 deletion REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SPDX-FileCopyrightText = "2023-2024 Nextcloud translators"
SPDX-License-Identifier = "AGPL-3.0-or-later"

[[annotations]]
path = [".tx/config", ".tx/backport", "composer.json", "composer.lock", "package-lock.json", "package.json"]
path = [".tx/config", ".tx/backport", "composer.json", "composer.lock", "package-lock.json", "package.json", "vendor-bin/**/composer.json", "vendor-bin/**/composer.lock"]
precedence = "aggregate"
SPDX-FileCopyrightText = "2023 Nextcloud GmbH and Nextcloud contributors"
SPDX-License-Identifier = "AGPL-3.0-or-later"
Expand Down
18 changes: 15 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,32 @@
"friendsofphp/php-cs-fixer": "3.94.1"
},
"scripts": {
"lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l",
"lint": "find . -name \\*.php -not -path './vendor/*' -not -path './vendor-bin/*' -print0 | xargs -0 -n1 php -l",
"cs:check": "php-cs-fixer fix ./lib --dry-run --diff",
"cs:fix": "php-cs-fixer fix ./lib",
"psalm": "psalm.phar --threads=1",
"psalm:update-baseline": "psalm.phar --threads=1 --update-baseline",
"psalm:update-baseline:force": "psalm.phar --threads=1 --update-baseline --set-baseline=tests/psalm-baseline.xml",
"psalm:clear": "psalm.phar --clear-cache && psalm.phar --clear-global-cache",
"psalm:fix": "psalm.phar --alter --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType"
"psalm:fix": "psalm.phar --alter --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType",
"test:unit": "vendor/bin/phpunit -c tests/php/phpunit.xml --colors=always --fail-on-warning --fail-on-risky --display-deprecations --display-phpunit-deprecations",
"post-install-cmd": [
"@composer bin all install --ansi"
],
"post-update-cmd": [
"@composer bin all install --ansi"
]
Comment on lines +35 to +40
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from the server repo, this ensures the dev packages don't get installed with --no-dev option:

Suggested change
"post-install-cmd": [
"@composer bin all install --ansi"
],
"post-update-cmd": [
"@composer bin all install --ansi"
]
"post-install-cmd": [
"[ $COMPOSER_DEV_MODE -eq 0 ] || composer bin all install --ansi",
"composer dump-autoload --no-dev"
],
"post-update-cmd": [
"[ $COMPOSER_DEV_MODE -eq 0 ] || composer bin all update --ansi",
"composer dump-autoload --no-dev"
]

also:

	"extra": {
		"bamarni-bin": {
			"bin-links": true,
			"forward-command": false
		}
	}

},
"config": {
"allow-plugins": {
"bamarni/composer-bin-plugin": true
},
"optimize-autoloader": true,
"classmap-authoritative": true,
"platform": {
"php": "8.2"
}
},
"sort-packages": true
},
"autoload": {
"psr-4": {
Expand All @@ -50,6 +61,7 @@
}
},
"require": {
"bamarni/composer-bin-plugin": "^1.9",
"ext-simplexml": "*",
"php": ">=8.2.0"
}
Expand Down
381 changes: 260 additions & 121 deletions composer.lock

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion lib/DeployActions/DockerActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,16 @@ private function executeCommandInContainer(string $dockerUrl, string $containerI
return (string)$startResponse->getBody();
}

public function getDockerApiVersion(): string {
$version = $this->appConfig->getValueString(Application::APP_ID, 'docker_api_version', lazy: true);
if ($version !== '') {
return $version;
}
return self::DOCKER_API_VERSION;
}

public function buildApiUrl(string $dockerUrl, string $route): string {
return sprintf('%s/%s/%s', $dockerUrl, self::DOCKER_API_VERSION, $route);
return sprintf('%s/%s/%s', $dockerUrl, $this->getDockerApiVersion(), $route);
}

public function buildBaseImageName(array $imageParams, DaemonConfig $daemonConfig): string {
Expand Down
102 changes: 102 additions & 0 deletions tests/php/DeployActions/DockerActionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

declare(strict_types=1);

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

namespace OCA\AppAPI\Tests\php\DeployActions;

use OCA\AppAPI\AppInfo\Application;
use OCA\AppAPI\DeployActions\DockerActions;
use OCA\AppAPI\Service\AppAPICommonService;
use OCA\AppAPI\Service\ExAppDeployOptionsService;
use OCA\AppAPI\Service\ExAppService;
use OCP\App\IAppManager;
use OCP\IAppConfig;
use OCP\ICertificateManager;
use OCP\IConfig;
use OCP\ITempManager;
use OCP\IURLGenerator;
use OCP\Security\ICrypto;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;

class DockerActionsTest extends TestCase {
private DockerActions $dockerActions;
private IAppConfig&MockObject $appConfig;

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

$this->appConfig = $this->createMock(IAppConfig::class);

$this->dockerActions = new DockerActions(
$this->createMock(LoggerInterface::class),
$this->appConfig,
$this->createMock(IConfig::class),
$this->createMock(ICertificateManager::class),
$this->createMock(IAppManager::class),
$this->createMock(IURLGenerator::class),
$this->createMock(AppAPICommonService::class),
$this->createMock(ExAppService::class),
$this->createMock(ITempManager::class),
$this->createMock(ICrypto::class),
$this->createMock(ExAppDeployOptionsService::class),
);
}

public function testGetDockerApiVersionReturnsDefaultWhenNoConfigSet(): void {
$this->appConfig->expects(self::once())
->method('getValueString')
->with(Application::APP_ID, 'docker_api_version', '', true)
->willReturn('');

self::assertSame(DockerActions::DOCKER_API_VERSION, $this->dockerActions->getDockerApiVersion());
}

public function testGetDockerApiVersionReturnsCustomVersionFromConfig(): void {
$this->appConfig->expects(self::once())
->method('getValueString')
->with(Application::APP_ID, 'docker_api_version', '', true)
->willReturn('v1.43');

self::assertSame('v1.43', $this->dockerActions->getDockerApiVersion());
}

public function testBuildApiUrlUsesDefaultVersion(): void {
$this->appConfig->method('getValueString')
->with(Application::APP_ID, 'docker_api_version', '', true)
->willReturn('');

$url = $this->dockerActions->buildApiUrl('http://localhost', '_ping');

self::assertSame('http://localhost/v1.44/_ping', $url);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DockerActions::DOCKER_API_VERSION instead of v1.44

}

public function testBuildApiUrlUsesCustomVersion(): void {
$this->appConfig->method('getValueString')
->with(Application::APP_ID, 'docker_api_version', '', true)
->willReturn('v1.43');

$url = $this->dockerActions->buildApiUrl('http://localhost', '_ping');

self::assertSame('http://localhost/v1.43/_ping', $url);
}

public function testBuildApiUrlWithContainerRoute(): void {
$this->appConfig->method('getValueString')
->with(Application::APP_ID, 'docker_api_version', '', true)
->willReturn('v1.41');

$url = $this->dockerActions->buildApiUrl(
'http://localhost:8780',
sprintf('containers/%s/json', 'nc_app_test')
);

self::assertSame('http://localhost:8780/v1.41/containers/nc_app_test/json', $url);
}
}
20 changes: 20 additions & 0 deletions tests/php/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

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

use OCP\App\IAppManager;
use OCP\Server;

if (!defined('PHPUNIT_RUN')) {
define('PHPUNIT_RUN', 1);
}

require_once __DIR__ . '/../../../../lib/base.php';
require_once __DIR__ . '/../../../../tests/autoload.php';

Server::get(IAppManager::class)->loadApp('app_api');
28 changes: 28 additions & 0 deletions tests/php/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
- SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="bootstrap.php"
timeoutForSmallTests="900"
timeoutForMediumTests="900"
timeoutForLargeTests="900"
failOnDeprecation="true"
failOnIncomplete="true"
failOnRisky="true"
failOnWarning="true"
failOnEmptyTestSuite="true"
failOnNotice="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
cacheDirectory=".phpunit.result.cache"
>
<testsuite name="AppAPI Unit Tests">
<directory suffix="Test.php">.</directory>
</testsuite>
<source>
<include>
<directory suffix=".php">../../lib</directory>
</include>
</source>
</phpunit>
11 changes: 11 additions & 0 deletions vendor-bin/phpunit/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"config": {
"platform": {
"php": "8.2"
},
"sort-packages": true
},
"require-dev": {
"phpunit/phpunit": "^11.5"
}
}
Loading