Skip to content

Commit

Permalink
Fix silently failing tests
Browse files Browse the repository at this point in the history
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
  • Loading branch information
CarlSchwan committed Jan 12, 2022
1 parent 94c81bf commit a210765
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
39 changes: 22 additions & 17 deletions tests/TestSuiteListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@
namespace OCA\Circles\Tests;

use OCA\Circles\Model\DeprecatedCircle;

class Env implements \PHPUnit_Framework_TestListener {
use PHPUnit\Framework\TestListener;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\Warning;
use Throwable;

class Env implements TestListener {
public const ENV_TEST_OWNER1 = '_test_circles_owner1';
public const ENV_TEST_OWNER2 = '_test_circles_owner2';
public const ENV_TEST_OWNER3 = '_test_circles_owner3';
Expand All @@ -54,31 +60,31 @@ class Env implements \PHPUnit_Framework_TestListener {
/** @var array<string> */
private $users;

public function addError(\PHPUnit_Framework_Test $test, \Exception $e, $time) {
public function addError(Test $test, Throwable $e, float $time): void {
}

public function addFailure(
\PHPUnit_Framework_Test $test, \PHPUnit_Framework_AssertionFailedError $e, $time
) {
Test $test, AssertionFailedError $e, float $time
): void {
}

public function addIncompleteTest(\PHPUnit_Framework_Test $test, \Exception $e, $time) {
public function addIncompleteTest(Test $test, Throwable $e, float $time): void {
}

public function addRiskyTest(\PHPUnit_Framework_Test $test, \Exception $e, $time) {
public function addRiskyTest(Test $test, Throwable $e, float $time): void {
}

public function addSkippedTest(\PHPUnit_Framework_Test $test, \Exception $e, $time) {
public function addSkippedTest(Test $test, Throwable $e, float $time): void {
}

public function startTest(\PHPUnit_Framework_Test $test) {
public function startTest(Test $test): void {
}

public function endTest(\PHPUnit_Framework_Test $test, $time) {
public function endTest(Test $test, float $time): void {
}

public function startTestSuite(\PHPUnit_Framework_TestSuite $suite) {
if ($suite->getName() !== '.') {
public function startTestSuite(TestSuite $suite): void {
if ($suite->getName() !== 'OCA\Circles\Tests\Api\CirclesTest') {
return;
}

Expand All @@ -92,7 +98,7 @@ public function startTestSuite(\PHPUnit_Framework_TestSuite $suite) {
}
}

public function endTestSuite(\PHPUnit_Framework_TestSuite $suite) {
public function endTestSuite(TestSuite $suite): void {
if ($suite->getName() !== '.') {
return;
}
Expand All @@ -106,8 +112,8 @@ public function endTestSuite(\PHPUnit_Framework_TestSuite $suite) {
}
}

public function addWarning(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_Warning $e, $time
) {
public function addWarning(Test $test, Warning $e, float $time
): void {
}

public static function setUser($which) {
Expand All @@ -117,8 +123,7 @@ public static function setUser($which) {
->get($which)
);

return $userSession->getUser()
->getUID();
return $userSession->getUser()->getUID();
}

public static function currentUser() {
Expand Down
6 changes: 5 additions & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?php

define('PHPUNIT_RUN', 1);

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

\OC::$loader->addValidRoot(OC::$SERVERROOT . '/tests');
\OC::$composerAutoloader->addPsr4('Tests\\', OC::$SERVERROOT . '/tests/unit/', true);

\OC_App::loadApp('circles');

OC_Hook::clear();
8 changes: 5 additions & 3 deletions tests/unit/lib/Api/CirclesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
use OCA\Circles\Tests\Env;
use OCP\AppFramework\QueryException;

class CirclesTest extends \PHPUnit_Framework_TestCase {
use Test\TestCase;

class CirclesTest extends TestCase {
public const NAME_PUBLIC_CIRCLE1 = '_circleNamePublic1';
public const NAME_SECRET_CIRCLE1 = '_circleNameSecret1';
public const NAME_CLOSED_CIRCLE1 = '_circleNameClosed1';
Expand All @@ -62,7 +64,7 @@ class CirclesTest extends \PHPUnit_Framework_TestCase {
*
* @throws Exception
*/
protected function setUp() {
protected function setUp(): void {
Env::setUser(Env::ENV_TEST_OWNER1);

$this->circles = [];
Expand Down Expand Up @@ -92,7 +94,7 @@ protected function setUp() {
*
* @throws Exception
*/
protected function tearDown() {
protected function tearDown(): void {
Env::setUser(Env::ENV_TEST_OWNER1);
try {
foreach ($this->circles as $circle) {
Expand Down

0 comments on commit a210765

Please sign in to comment.