Browse Source

feat(CI): Allow apps to test with PHPUnit10

Signed-off-by: Joas Schilling <coding@schilljs.com>
tags/v28.0.0beta1
Joas Schilling 9 months ago
parent
commit
5e7b41086d
No account linked to committer's email address
1 changed files with 34 additions and 13 deletions
  1. 34
    13
      tests/lib/TestCase.php

+ 34
- 13
tests/lib/TestCase.php View File

use OCP\Security\ISecureRandom; use OCP\Security\ISecureRandom;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;


if (version_compare(\PHPUnit\Runner\Version::id(), 10, '>=')) {
trait OnNotSuccessfulTestTrait {
protected function onNotSuccessfulTest(\Throwable $t): never {
$this->restoreAllServices();

// restore database connection
if (!$this->IsDatabaseAccessAllowed()) {
\OC::$server->registerService(IDBConnection::class, function () {
return self::$realDatabase;
});
}

parent::onNotSuccessfulTest($t);
}
}
} else {
trait OnNotSuccessfulTestTrait {
protected function onNotSuccessfulTest(\Throwable $t): void {
$this->restoreAllServices();

// restore database connection
if (!$this->IsDatabaseAccessAllowed()) {
\OC::$server->registerService(IDBConnection::class, function () {
return self::$realDatabase;
});
}

parent::onNotSuccessfulTest($t);
}
}
}

abstract class TestCase extends \PHPUnit\Framework\TestCase { abstract class TestCase extends \PHPUnit\Framework\TestCase {
/** @var \OC\Command\QueueBus */ /** @var \OC\Command\QueueBus */
private $commandBus; private $commandBus;
/** @var array */ /** @var array */
protected $services = []; protected $services = [];


use OnNotSuccessfulTestTrait;

/** /**
* @param string $name * @param string $name
* @param mixed $newService * @param mixed $newService
} }
} }


protected function onNotSuccessfulTest(\Throwable $t): void {
$this->restoreAllServices();

// restore database connection
if (!$this->IsDatabaseAccessAllowed()) {
\OC::$server->registerService(IDBConnection::class, function () {
return self::$realDatabase;
});
}

parent::onNotSuccessfulTest($t);
}

protected function tearDown(): void { protected function tearDown(): void {
$this->restoreAllServices(); $this->restoreAllServices();



Loading…
Cancel
Save