diff --git a/README.md b/README.md index 531af187b..8a769155b 100644 --- a/README.md +++ b/README.md @@ -21,3 +21,4 @@ You can use the `\Psr\Container\ContainerInterface`, see [dependency injection]( # Testing Front-end tests (Vitest for unit/component, Playwright for end-to-end) are documented in [TESTING.md](TESTING.md). + diff --git a/tests/stubs/doctrine_dbal_driver_exception.php b/tests/stubs/doctrine_dbal_driver_exception.php index df5e40120..cf824a5f5 100644 --- a/tests/stubs/doctrine_dbal_driver_exception.php +++ b/tests/stubs/doctrine_dbal_driver_exception.php @@ -15,7 +15,5 @@ interface Exception extends Throwable * * @return string|null */ - public function getSQLState() - { - } + public function getSQLState(); } diff --git a/tests/stubs/oc_hooks_emitter.php b/tests/stubs/oc_hooks_emitter.php index dd6f09aac..b8c00a211 100644 --- a/tests/stubs/oc_hooks_emitter.php +++ b/tests/stubs/oc_hooks_emitter.php @@ -25,9 +25,7 @@ interface Emitter { * @return void * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher::addListener */ - public function listen($scope, $method, callable $callback) - { - } + public function listen($scope, $method, callable $callback); /** * @param string $scope optional @@ -36,7 +34,5 @@ public function listen($scope, $method, callable $callback) * @return void * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher::removeListener */ - public function removeListener($scope = null, $method = null, ?callable $callback = null) - { - } + public function removeListener($scope = null, $method = null, ?callable $callback = null); } diff --git a/tests/stubs/oca_dav_carddav_contactsmanager.php b/tests/stubs/oca_dav_carddav_contactsmanager.php index 1bb5f9266..1736916e0 100644 --- a/tests/stubs/oca_dav_carddav_contactsmanager.php +++ b/tests/stubs/oca_dav_carddav_contactsmanager.php @@ -5,6 +5,7 @@ * SPDX-FileCopyrightText: 2016 ownCloud, Inc. * SPDX-License-Identifier: AGPL-3.0-only */ + namespace OCA\DAV\CardDAV; use OCA\DAV\AppInfo\Application; diff --git a/tests/stubs/oca_files_sharing_external_storage.php b/tests/stubs/oca_files_sharing_external_storage.php index 96b14c039..feb912871 100644 --- a/tests/stubs/oca_files_sharing_external_storage.php +++ b/tests/stubs/oca_files_sharing_external_storage.php @@ -6,48 +6,124 @@ * SPDX-FileCopyrightText: 2016 ownCloud, Inc. * SPDX-License-Identifier: AGPL-3.0-only */ + namespace OCA\Files_Sharing\External; +use GuzzleHttp\Exception\ClientException; +use GuzzleHttp\Exception\ConnectException; +use GuzzleHttp\Exception\RequestException; +use OC\Files\Storage\BearerAuthAwareSabreClient; +use OC\Files\Storage\DAV; +use OC\ForbiddenException; +use OCA\Files_Sharing\External\Manager as ExternalShareManager; +use OCA\Files_Sharing\ISharedStorage; +use OCP\AppFramework\Http; +use OCP\Constants; +use OCP\Federation\ICloudId; use OCP\Files\Cache\ICache; use OCP\Files\Cache\IScanner; use OCP\Files\Cache\IWatcher; +use OCP\Files\NotFoundException; use OCP\Files\Storage\IDisableEncryptionStorage; use OCP\Files\Storage\IReliableEtagStorage; use OCP\Files\Storage\IStorage; +use OCP\Files\StorageInvalidException; +use OCP\Files\StorageNotAvailableException; +use OCP\Http\Client\IClientService; +use OCP\Http\Client\LocalServerException; +use OCP\IAppConfig; +use OCP\ICacheFactory; +use OCP\IConfig; +use OCP\IUserSession; +use OCP\OCM\Exceptions\OCMArgumentException; +use OCP\OCM\Exceptions\OCMProviderException; +use OCP\OCM\IOCMDiscoveryService; +use OCP\Server; +use OCP\Share\IManager as IShareManager; +use Psr\Log\LoggerInterface; + +class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage, IReliableEtagStorage { + protected IAppConfig $appConfig; + + private const int REFRESH_MAX_ATTEMPTS = 3; + private const int REFRESH_BACKOFF_SECONDS = 5; -class Storage implements IDisableEncryptionStorage, IReliableEtagStorage { - public function getWatcher(string $path = '', ?IStorage $storage = null): IWatcher { - } - - public function getRemoteUser(): string { - } - - public function getRemote(): string { - } - - public function getMountPoint(): string { - } - - public function getToken(): string { - } - - public function getPassword(): ?string { - } - - public function getId(): string { - } - - public function getCache(string $path = '', ?IStorage $storage = null): ICache { - } - - public function getScanner(string $path = '', ?IStorage $storage = null): IScanner { - } - - public function hasUpdated(string $path, int $time): bool { - } + /** + * @param array{HttpClientService: IClientService, manager: ExternalShareManager, cloudId: ICloudId, mountpoint: string, token: string, access_token: ?string, access_token_expires: ?int}|array $options + */ + public function __construct($options) + { + } - public function test(): bool { - } + /** + * Refresh the access token. Extends parent to also persist to database. + * + * Uses expiry timestamps instead of a boolean flag so that concurrent + * processes can detect that another process already obtained a fresh token + * and reuse it rather than performing a redundant exchange. + * + * After a failed exchange, a 60-second backoff is applied so that + * subsequent file operations do not hammer the remote token endpoint. + * The DB is still consulted during backoff in case a concurrent process + * succeeded; only the outgoing exchange call is suppressed. + * + * @return string|null the access token (freshly exchanged or reused from + * DB), or null if refresh is currently not possible + */ + #[\Override] + protected function refreshAccessToken(): ?string + { + } + + #[\Override] + public function getWatcher(string $path = '', ?IStorage $storage = null): IWatcher + { + } + + public function getRemoteUser(): string + { + } + + public function getRemote(): string + { + } + + public function getMountPoint(): string + { + } + + public function getToken(): string + { + } + + public function getPassword(): ?string + { + } + + #[\Override] + public function getId(): string + { + } + + #[\Override] + public function getCache(string $path = '', ?IStorage $storage = null): ICache + { + } + + #[\Override] + public function getScanner(string $path = '', ?IStorage $storage = null): IScanner + { + } + + #[\Override] + public function hasUpdated(string $path, int $time): bool + { + } + + #[\Override] + public function test(): bool + { + } /** * Check whether this storage is permanently or temporarily @@ -56,28 +132,82 @@ public function test(): bool { * @throws StorageNotAvailableException * @throws StorageInvalidException */ - public function checkStorageAvailability(): void { - } + public function checkStorageAvailability(): void + { + } - public function file_exists(string $path): bool { - } + #[\Override] + public function file_exists(string $path): bool + { + } - public function getShareInfo(int $depth = -1) { - } - - public function getOwner(string $path): string|false { - } + /** + * Check if the configured remote is a valid-federated share provider + */ + protected function testRemote(): bool + { + } - public function isSharable(string $path): bool { - } + /** + * Check whether the remote is an ownCloud/Nextcloud. This is needed since some sharing + * features are not standardized. + * + * @throws LocalServerException + */ + public function remoteIsOwnCloud(): bool + { + } - public function getPermissions(string $path): int { - } + /** + * @return mixed + * @throws ForbiddenException + * @throws NotFoundException + * @throws \Exception + */ + public function getShareInfo(int $depth = -1) + { + } + + #[\Override] + public function getOwner(string $path): string|false + { + } + + #[\Override] + public function isSharable(string $path): bool + { + } + + #[\Override] + public function getPermissions(string $path): int + { + } + + #[\Override] + public function needsPartFile(): bool + { + } - public function needsPartFile(): bool { - return false; - } + /** + * Translate OCM Permissions to Nextcloud permissions + * + * @param string $ocmPermissions json encoded OCM permissions + * @param string $path path to file + * @return int + */ + protected function ocmPermissions2ncPermissions(string $ocmPermissions, string $path): int + { + } - public function free_space(string $path): int|float|false { - } + /** + * Calculate the default permissions in case no permissions are provided + */ + protected function getDefaultPermissions(string $path): int + { + } + + #[\Override] + public function free_space(string $path): int|float|false + { + } } diff --git a/tests/stubs/oca_user_ldap_mapping_abstractmapping.php b/tests/stubs/oca_user_ldap_mapping_abstractmapping.php index a41fe2ff2..c18a0ba14 100644 --- a/tests/stubs/oca_user_ldap_mapping_abstractmapping.php +++ b/tests/stubs/oca_user_ldap_mapping_abstractmapping.php @@ -5,10 +5,10 @@ * SPDX-FileCopyrightText: 2016 ownCloud, Inc. * SPDX-License-Identifier: AGPL-3.0-only */ + namespace OCA\User_LDAP\Mapping; use Doctrine\DBAL\Exception; -use OCP\DB\IPreparedStatement; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IAppConfig; use OCP\ICache; @@ -28,9 +28,7 @@ abstract class AbstractMapping { * * @return string */ - abstract protected function getTableName(bool $includePrefix = true) - { - } + abstract protected function getTableName(bool $includePrefix = true); /** * A month worth of cache time for as good as never changing mapping data. @@ -93,17 +91,6 @@ public function isColNameValid($col) */ protected function getXbyY($fetchCol, $compareCol, $search) { - } - - /** - * Performs a DELETE or UPDATE query to the database. - * - * @param IPreparedStatement $statement - * @param array $parameters - * @return bool true if at least one row was modified, false otherwise - */ - protected function modify(IPreparedStatement $statement, $parameters) - { } /** diff --git a/tests/stubs/oca_user_ldap_mapping_usermapping.php b/tests/stubs/oca_user_ldap_mapping_usermapping.php index 98e6d355a..5423d9954 100644 --- a/tests/stubs/oca_user_ldap_mapping_usermapping.php +++ b/tests/stubs/oca_user_ldap_mapping_usermapping.php @@ -33,7 +33,8 @@ public function __construct(IDBConnection $dbc, ICacheFactory $cacheFactory, IAp /** * @throws HintException */ - public function map($fdn, $name, $uuid): bool + #[\Override] + public function map($fdn, $name, $uuid): bool { } @@ -41,7 +42,8 @@ public function map($fdn, $name, $uuid): bool * returns the DB table name which holds the mappings * @return string */ - protected function getTableName(bool $includePrefix = true) + #[\Override] + protected function getTableName(bool $includePrefix = true) { } } diff --git a/tests/stubs/stecman_component_symfony_console_bashcompletion_completion_completionawareinterface.php b/tests/stubs/stecman_component_symfony_console_bashcompletion_completion_completionawareinterface.php index 8a4d5c439..20963cb8c 100644 --- a/tests/stubs/stecman_component_symfony_console_bashcompletion_completion_completionawareinterface.php +++ b/tests/stubs/stecman_component_symfony_console_bashcompletion_completion_completionawareinterface.php @@ -14,9 +14,7 @@ interface CompletionAwareInterface * @param CompletionContext $context * @return array */ - public function completeOptionValues($optionName, CompletionContext $context) - { - } + public function completeOptionValues($optionName, CompletionContext $context); /** * Return possible values for the named argument @@ -25,7 +23,5 @@ public function completeOptionValues($optionName, CompletionContext $context) * @param CompletionContext $context * @return array */ - public function completeArgumentValues($argumentName, CompletionContext $context) - { - } + public function completeArgumentValues($argumentName, CompletionContext $context); } diff --git a/tests/stubs/symfony_component_console_helper_helperinterface.php b/tests/stubs/symfony_component_console_helper_helperinterface.php index 350ae4ac5..8c4da3c91 100644 --- a/tests/stubs/symfony_component_console_helper_helperinterface.php +++ b/tests/stubs/symfony_component_console_helper_helperinterface.php @@ -21,21 +21,15 @@ interface HelperInterface /** * Sets the helper set associated with this helper. */ - public function setHelperSet(?HelperSet $helperSet): void - { - } + public function setHelperSet(?HelperSet $helperSet): void; /** * Gets the helper set associated with this helper. */ - public function getHelperSet(): ?HelperSet - { - } + public function getHelperSet(): ?HelperSet; /** * Returns the canonical name of this helper. */ - public function getName(): string - { - } + public function getName(): string; } diff --git a/tests/stubs/symfony_component_console_input_inputinterface.php b/tests/stubs/symfony_component_console_input_inputinterface.php index 535a97c0c..c177d960b 100644 --- a/tests/stubs/symfony_component_console_input_inputinterface.php +++ b/tests/stubs/symfony_component_console_input_inputinterface.php @@ -24,9 +24,7 @@ interface InputInterface /** * Returns the first argument from the raw parameters (not parsed). */ - public function getFirstArgument(): ?string - { - } + public function getFirstArgument(): ?string; /** * Returns true if the raw parameters (not parsed) contain a value. @@ -39,9 +37,7 @@ public function getFirstArgument(): ?string * @param string|array $values The values to look for in the raw parameters (can be an array) * @param bool $onlyParams Only check real parameters, skip those following an end of options (--) signal */ - public function hasParameterOption(string|array $values, bool $onlyParams = false): bool - { - } + public function hasParameterOption(string|array $values, bool $onlyParams = false): bool; /** * Returns the value of a raw option (not parsed). @@ -55,116 +51,88 @@ public function hasParameterOption(string|array $values, bool $onlyParams = fals * @param string|bool|int|float|array|null $default The default value to return if no result is found * @param bool $onlyParams Only check real parameters, skip those following an end of options (--) signal */ - public function getParameterOption(string|array $values, string|bool|int|float|array|null $default = false, bool $onlyParams = false): mixed - { - } + public function getParameterOption(string|array $values, string|bool|int|float|array|null $default = false, bool $onlyParams = false): mixed; /** * Binds the current Input instance with the given arguments and options. * * @throws RuntimeException */ - public function bind(InputDefinition $definition): void - { - } + public function bind(InputDefinition $definition): void; /** * Validates the input. * * @throws RuntimeException When not enough arguments are given */ - public function validate(): void - { - } + public function validate(): void; /** * Returns all the given arguments merged with the default values. * * @return array */ - public function getArguments(): array - { - } + public function getArguments(): array; /** * Returns the argument value for a given argument name. * * @throws InvalidArgumentException When argument given doesn't exist */ - public function getArgument(string $name): mixed - { - } + public function getArgument(string $name): mixed; /** * Sets an argument value by name. * * @throws InvalidArgumentException When argument given doesn't exist */ - public function setArgument(string $name, mixed $value): void - { - } + public function setArgument(string $name, mixed $value): void; /** * Returns true if an InputArgument object exists by name or position. */ - public function hasArgument(string $name): bool - { - } + public function hasArgument(string $name): bool; /** * Returns all the given options merged with the default values. * * @return array */ - public function getOptions(): array - { - } + public function getOptions(): array; /** * Returns the option value for a given option name. * * @throws InvalidArgumentException When option given doesn't exist */ - public function getOption(string $name): mixed - { - } + public function getOption(string $name): mixed; /** * Sets an option value by name. * * @throws InvalidArgumentException When option given doesn't exist */ - public function setOption(string $name, mixed $value): void - { - } + public function setOption(string $name, mixed $value): void; /** * Returns true if an InputOption object exists by name. */ - public function hasOption(string $name): bool - { - } + public function hasOption(string $name): bool; /** * Is this input means interactive? */ - public function isInteractive(): bool - { - } + public function isInteractive(): bool; /** * Sets the input interactivity. */ - public function setInteractive(bool $interactive): void - { - } + public function setInteractive(bool $interactive): void; /** * Returns a stringified representation of the args passed to the command. * * InputArguments MUST be escaped as well as the InputOption values passed to the command. */ - public function __toString(): string - { - } + public function __toString(): string; } diff --git a/tests/stubs/symfony_component_console_output_consoleoutputinterface.php b/tests/stubs/symfony_component_console_output_consoleoutputinterface.php index c6289da61..1f8f147ce 100644 --- a/tests/stubs/symfony_component_console_output_consoleoutputinterface.php +++ b/tests/stubs/symfony_component_console_output_consoleoutputinterface.php @@ -22,15 +22,9 @@ interface ConsoleOutputInterface extends OutputInterface /** * Gets the OutputInterface for errors. */ - public function getErrorOutput(): OutputInterface - { - } + public function getErrorOutput(): OutputInterface; - public function setErrorOutput(OutputInterface $error): void - { - } + public function setErrorOutput(OutputInterface $error): void; - public function section(): ConsoleSectionOutput - { - } + public function section(): ConsoleSectionOutput; } diff --git a/tests/stubs/symfony_component_console_output_output.php b/tests/stubs/symfony_component_console_output_output.php index d9c694ee1..62d3f827e 100644 --- a/tests/stubs/symfony_component_console_output_output.php +++ b/tests/stubs/symfony_component_console_output_output.php @@ -94,7 +94,5 @@ public function write(string|iterable $messages, bool $newline = false, int $opt /** * Writes a message to the output. */ - abstract protected function doWrite(string $message, bool $newline): void - { - } + abstract protected function doWrite(string $message, bool $newline): void; } diff --git a/tests/stubs/symfony_component_console_output_outputinterface.php b/tests/stubs/symfony_component_console_output_outputinterface.php index 37b29fb34..969a3b022 100644 --- a/tests/stubs/symfony_component_console_output_outputinterface.php +++ b/tests/stubs/symfony_component_console_output_outputinterface.php @@ -40,9 +40,7 @@ interface OutputInterface * @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), * 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL */ - public function write(string|iterable $messages, bool $newline = false, int $options = 0): void - { - } + public function write(string|iterable $messages, bool $newline = false, int $options = 0): void; /** * Writes a message to the output and adds a newline at the end. @@ -50,78 +48,56 @@ public function write(string|iterable $messages, bool $newline = false, int $opt * @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), * 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL */ - public function writeln(string|iterable $messages, int $options = 0): void - { - } + public function writeln(string|iterable $messages, int $options = 0): void; /** * Sets the verbosity of the output. * * @param self::VERBOSITY_* $level */ - public function setVerbosity(int $level): void - { - } + public function setVerbosity(int $level): void; /** * Gets the current verbosity of the output. * * @return self::VERBOSITY_* */ - public function getVerbosity(): int - { - } + public function getVerbosity(): int; /** * Returns whether verbosity is quiet (-q). */ - public function isQuiet(): bool - { - } + public function isQuiet(): bool; /** * Returns whether verbosity is verbose (-v). */ - public function isVerbose(): bool - { - } + public function isVerbose(): bool; /** * Returns whether verbosity is very verbose (-vv). */ - public function isVeryVerbose(): bool - { - } + public function isVeryVerbose(): bool; /** * Returns whether verbosity is debug (-vvv). */ - public function isDebug(): bool - { - } + public function isDebug(): bool; /** * Sets the decorated flag. */ - public function setDecorated(bool $decorated): void - { - } + public function setDecorated(bool $decorated): void; /** * Gets the decorated flag. */ - public function isDecorated(): bool - { - } + public function isDecorated(): bool; - public function setFormatter(OutputFormatterInterface $formatter): void - { - } + public function setFormatter(OutputFormatterInterface $formatter): void; /** * Returns current output formatter instance. */ - public function getFormatter(): OutputFormatterInterface - { - } + public function getFormatter(): OutputFormatterInterface; }