Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor phpunit tests #36501

Merged
merged 8 commits into from
Dec 7, 2019
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion apps/comments/tests/unit/ActivityListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ActivityListenerTest extends \Test\TestCase {
*/
private $activityManager;

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

$this->activityManager = $this->createMock(IManager::class);
Expand Down
27 changes: 17 additions & 10 deletions apps/comments/tests/unit/Dav/CommentsNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CommentsNodeTest extends \Test\TestCase {
protected $logger;
protected $userSession;

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

$this->commentsManager = $this->createMock('\OCP\Comments\ICommentsManager');
Expand Down Expand Up @@ -84,9 +84,10 @@ public function testDelete() {
}

/**
* @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testDeleteForbidden() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

$user = $this->createMock('\OCP\IUser');

$user->expects($this->once())
Expand Down Expand Up @@ -124,9 +125,10 @@ public function testGetName() {
}

/**
* @expectedException \Sabre\DAV\Exception\MethodNotAllowed
*/
public function testSetName() {
$this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class);

$this->node->setName('666');
}

Expand Down Expand Up @@ -167,10 +169,11 @@ public function testUpdateComment() {
}

/**
* @expectedException Exception
* @expectedExceptionMessage buh!
*/
public function testUpdateCommentLogException() {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('buh!');

$msg = null;

$user = $this->createMock('\OCP\IUser');
Expand Down Expand Up @@ -206,10 +209,11 @@ public function testUpdateCommentLogException() {
}

/**
* @expectedException \Sabre\DAV\Exception\BadRequest
* @expectedExceptionMessage Message exceeds allowed character limit of
*/
public function testUpdateCommentMessageTooLongException() {
$this->expectException(\Sabre\DAV\Exception\BadRequest::class);
$this->expectExceptionMessage('Message exceeds allowed character limit of');

$user = $this->createMock('\OCP\IUser');

$user->expects($this->once())
Expand Down Expand Up @@ -243,9 +247,10 @@ public function testUpdateCommentMessageTooLongException() {
}

/**
* @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testUpdateForbiddenByUser() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

$msg = 'HaXX0r';

$user = $this->createMock('\OCP\IUser');
Expand Down Expand Up @@ -276,9 +281,10 @@ public function testUpdateForbiddenByUser() {
}

/**
* @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testUpdateForbiddenByType() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

$msg = 'HaXX0r';

$user = $this->createMock('\OCP\IUser');
Expand All @@ -304,9 +310,10 @@ public function testUpdateForbiddenByType() {
}

/**
* @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testUpdateForbiddenByNotLoggedIn() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

$msg = 'HaXX0r';

$this->userSession->expects($this->once())
Expand Down
25 changes: 16 additions & 9 deletions apps/comments/tests/unit/Dav/CommentsPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class CommentsPluginTest extends \Test\TestCase {
/** @var CommentsPluginImplementation */
private $plugin;

public function setUp() {
public function setUp(): void {
parent::setUp();
$this->tree = $this->getMockBuilder('\Sabre\DAV\Tree')
->disableOriginalConstructor()
Expand Down Expand Up @@ -155,9 +155,10 @@ public function testCreateComment() {
}

/**
* @expectedException \Sabre\DAV\Exception\NotFound
*/
public function testCreateCommentInvalidObject() {
$this->expectException(\Sabre\DAV\Exception\NotFound::class);

$commentData = [
'actorType' => 'users',
'verb' => 'comment',
Expand Down Expand Up @@ -235,9 +236,10 @@ public function testCreateCommentInvalidObject() {
}

/**
* @expectedException \Sabre\DAV\Exception\BadRequest
*/
public function testCreateCommentInvalidActor() {
$this->expectException(\Sabre\DAV\Exception\BadRequest::class);

$commentData = [
'actorType' => 'robots',
'verb' => 'comment',
Expand Down Expand Up @@ -321,9 +323,10 @@ public function testCreateCommentInvalidActor() {
}

/**
* @expectedException \Sabre\DAV\Exception\UnsupportedMediaType
*/
public function testCreateCommentUnsupportedMediaType() {
$this->expectException(\Sabre\DAV\Exception\UnsupportedMediaType::class);

$commentData = [
'actorType' => 'users',
'verb' => 'comment',
Expand Down Expand Up @@ -407,9 +410,10 @@ public function testCreateCommentUnsupportedMediaType() {
}

/**
* @expectedException \Sabre\DAV\Exception\BadRequest
*/
public function testCreateCommentInvalidPayload() {
$this->expectException(\Sabre\DAV\Exception\BadRequest::class);

$commentData = [
'actorType' => 'users',
'verb' => '',
Expand Down Expand Up @@ -499,10 +503,11 @@ public function testCreateCommentInvalidPayload() {
}

/**
* @expectedException \Sabre\DAV\Exception\BadRequest
* @expectedExceptionMessage Message exceeds allowed character limit of
*/
public function testCreateCommentMessageTooLong() {
$this->expectException(\Sabre\DAV\Exception\BadRequest::class);
$this->expectExceptionMessage('Message exceeds allowed character limit of');

$commentData = [
'actorType' => 'users',
'verb' => 'comment',
Expand Down Expand Up @@ -591,9 +596,10 @@ public function testCreateCommentMessageTooLong() {
}

/**
* @expectedException \Sabre\DAV\Exception\ReportNotSupported
*/
public function testOnReportInvalidNode() {
$this->expectException(\Sabre\DAV\Exception\ReportNotSupported::class);

$path = 'totally/unrelated/13';

$this->tree->expects($this->any())
Expand All @@ -610,9 +616,10 @@ public function testOnReportInvalidNode() {
}

/**
* @expectedException \Sabre\DAV\Exception\ReportNotSupported
*/
public function testOnReportInvalidReportName() {
$this->expectException(\Sabre\DAV\Exception\ReportNotSupported::class);

$path = 'comments/files/42';

$this->tree->expects($this->any())
Expand Down
5 changes: 3 additions & 2 deletions apps/comments/tests/unit/Dav/EntityCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class EntityCollectionTest extends \Test\TestCase {
/** @var EventDispatcherInterface | \PHPUnit_Framework_MockObject_MockObject */
private $dispatcher;

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

$this->commentsManager = $this->createMock(ICommentsManager::class);
Expand Down Expand Up @@ -81,9 +81,10 @@ public function testGetChild(): void {
}

/**
* @expectedException \Sabre\DAV\Exception\NotFound
*/
public function testGetChildException(): void {
$this->expectException(\Sabre\DAV\Exception\NotFound::class);

$this->commentsManager->expects($this->once())
->method('get')
->with('55')
Expand Down
8 changes: 5 additions & 3 deletions apps/comments/tests/unit/Dav/EntityTypeCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class EntityTypeCollectionTest extends \Test\TestCase {
/** @var EventDispatcherInterface | \PHPUnit_Framework_MockObject_MockObject */
private $dispatcher;

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

$this->commentsManager = $this->createMock(ICommentsManager::class);
Expand Down Expand Up @@ -89,16 +89,18 @@ public function testGetChild() {
}

/**
* @expectedException \Sabre\DAV\Exception\NotFound
*/
public function testGetChildException() {
$this->expectException(\Sabre\DAV\Exception\NotFound::class);

$this->collection->getChild('17');
}

/**
* @expectedException \Sabre\DAV\Exception\MethodNotAllowed
*/
public function testGetChildren() {
$this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class);

$this->collection->getChildren();
}
}
26 changes: 17 additions & 9 deletions apps/comments/tests/unit/Dav/RootCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class RootCollectionTest extends \Test\TestCase {
/** @var \OCP\IUser|\PHPUnit\Framework\MockObject\MockObject */
protected $user;

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

$this->user = $this->createMock('\OCP\IUser');
Expand Down Expand Up @@ -82,16 +82,18 @@ protected function prepareForInitCollections() {
}

/**
* @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testCreateFile() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

$this->collection->createFile('foo');
}

/**
* @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testCreateDirectory() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

$this->collection->createDirectory('foo');
}

Expand All @@ -102,17 +104,19 @@ public function testGetChild() {
}

/**
* @expectedException \Sabre\DAV\Exception\NotFound
*/
public function testGetChildInvalid() {
$this->expectException(\Sabre\DAV\Exception\NotFound::class);

$this->prepareForInitCollections();
$this->collection->getChild('robots');
}

/**
* @expectedException \Sabre\DAV\Exception\NotAuthenticated
*/
public function testGetChildNoAuth() {
$this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class);

$this->collection->getChild('files');
}

Expand All @@ -126,9 +130,10 @@ public function testGetChildren() {
}

/**
* @expectedException \Sabre\DAV\Exception\NotAuthenticated
*/
public function testGetChildrenNoAuth() {
$this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class);

$this->collection->getChildren();
}

Expand All @@ -143,16 +148,18 @@ public function testChildExistsNo() {
}

/**
* @expectedException \Sabre\DAV\Exception\NotAuthenticated
*/
public function testChildExistsNoAuth() {
$this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class);

$this->collection->childExists('files');
}

/**
* @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testDelete() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

$this->collection->delete();
}

Expand All @@ -161,9 +168,10 @@ public function testGetName() {
}

/**
* @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testSetName() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

$this->collection->setName('foobar');
}

Expand Down
5 changes: 3 additions & 2 deletions apps/dav/tests/unit/Avatars/AvatarHomeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ class AvatarHomeTest extends TestCase {
/** @var IAvatarManager | \PHPUnit\Framework\MockObject\MockObject */
private $avatarManager;

public function setUp() {
public function setUp(): void {
$this->avatarManager = $this->createMock(IAvatarManager::class);
$this->home = new AvatarHome(['uri' => 'principals/users/admin'], $this->avatarManager);
}

/**
* @expectedException \Sabre\DAV\Exception\Forbidden
* @dataProvider providesForbiddenMethods
*/
public function testForbiddenMethods($method) {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

$this->home->$method('');
}

Expand Down
2 changes: 1 addition & 1 deletion apps/dav/tests/unit/BackgroundJob/CleanPropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class CleanPropertiesTest extends TestCase {
/** @var string */
private $username;

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

$this->connection = \OC::$server->getDatabaseConnection();
Expand Down
4 changes: 2 additions & 2 deletions apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ abstract class AbstractCalDavBackendTest extends TestCase {
/** @var ISecureRandom */
private $random;

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

$this->principal = $this->getMockBuilder(Principal::class)
Expand All @@ -83,7 +83,7 @@ public function setUp() {
$this->tearDown();
}

public function tearDown() {
public function tearDown(): void {
parent::tearDown();

if ($this->backend === null) {
Expand Down
Loading