Move Provisioning api to PSR-4 (#24510)

* Move app to PSR-4

* Fix setUp method

* Fix the tests
This commit is contained in:
Joas Schilling 2016-05-11 19:38:49 +02:00 committed by Thomas Müller
parent e03f9e8103
commit 2a05035339
8 changed files with 194 additions and 176 deletions

View File

@ -18,6 +18,7 @@
<admin>admin-provisioning-api</admin>
</documentation>
<version>0.5.0</version>
<namespace>Provisioning_API</namespace>
<types>
<prevent_group_restriction/>
</types>

View File

@ -43,7 +43,7 @@ class Users {
private $userManager;
/** @var IConfig */
private $config;
/** @var IGroupManager */
/** @var IGroupManager|\OC\Group\Manager */ // FIXME Requires a method that is not on the interface
private $groupManager;
/** @var IUserSession */
private $userSession;

View File

@ -25,6 +25,8 @@
*/
namespace OCA\Provisioning_API\Tests;
use OC\OCSClient;
use OCA\Provisioning_API\Apps;
use OCP\API;
@ -45,16 +47,19 @@ class AppsTest extends TestCase {
private $api;
/** @var IUserSession */
private $userSession;
/** @var OCSClient */
/** @var OCSClient|\PHPUnit_Framework_MockObject_MockObject */
private $ocsClient;
public function setup() {
parent::setup();
protected function setUp() {
parent::setUp();
$this->appManager = \OC::$server->getAppManager();
$this->groupManager = \OC::$server->getGroupManager();
$this->userSession = \OC::$server->getUserSession();
$this->ocsClient = $this->getMockBuilder('\OC\OCSClient')
->disableOriginalConstructor()->getMock();
$this->ocsClient = $this->getMockBuilder('OC\OCSClient')
->disableOriginalConstructor()
->getMock();
$this->api = new Apps($this->appManager, $this->ocsClient);
}

View File

@ -25,6 +25,8 @@
namespace OCA\Provisioning_API\Tests;
use OCA\Provisioning_API\Groups;
use OCP\API;
use OCP\IGroupManager;
use OCP\IUserSession;
use OCP\IRequest;
@ -38,20 +40,26 @@ class GroupsTest extends \Test\TestCase {
protected $request;
/** @var \OC\SubAdmin|\PHPUnit_Framework_MockObject_MockObject */
protected $subAdminManager;
/** @var \OCA\Provisioning_API\Groups */
/** @var Groups */
protected $api;
protected function setup() {
$this->subAdminManager = $this->getMockBuilder('OC\SubAdmin')->disableOriginalConstructor()->getMock();
protected function setUp() {
parent::setUp();
$this->groupManager = $this->getMockBuilder('OC\Group\Manager')->disableOriginalConstructor()->getMock();
$this->subAdminManager = $this->getMockBuilder('OC\SubAdmin')
->disableOriginalConstructor()
->getMock();
$this->groupManager = $this->getMockBuilder('OC\Group\Manager')
->disableOriginalConstructor()
->getMock();
$this->groupManager
->method('getSubAdmin')
->willReturn($this->subAdminManager);
$this->userSession = $this->getMock('OCP\IUserSession');
$this->request = $this->getMock('OCP\IRequest');
$this->api = new \OCA\Provisioning_API\Groups(
$this->api = new Groups(
$this->groupManager,
$this->userSession,
$this->request
@ -129,6 +137,10 @@ class GroupsTest extends \Test\TestCase {
/**
* @dataProvider dataGetGroups
*
* @param string|null $search
* @param int|null $limit
* @param int|null $offset
*/
public function testGetGroups($search, $limit, $offset) {
$this->request
@ -161,7 +173,7 @@ class GroupsTest extends \Test\TestCase {
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertFalse($result->succeeded());
$this->assertEquals(\OCP\API::RESPOND_UNAUTHORISED, $result->getStatusCode());
$this->assertEquals(API::RESPOND_UNAUTHORISED, $result->getStatusCode());
}
@ -215,7 +227,7 @@ class GroupsTest extends \Test\TestCase {
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertFalse($result->succeeded());
$this->assertEquals(\OCP\API::RESPOND_UNAUTHORISED, $result->getStatusCode());
$this->assertEquals(API::RESPOND_UNAUTHORISED, $result->getStatusCode());
}
public function testGetGroupAsAdmin() {
@ -252,12 +264,12 @@ class GroupsTest extends \Test\TestCase {
$this->asUser();
$result = $this->api->getGroup([
'groupid' => $this->getUniqueId()
'groupid' => $this->getUniqueID()
]);
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertFalse($result->succeeded());
$this->assertEquals(\OCP\API::RESPOND_NOT_FOUND, $result->getStatusCode());
$this->assertEquals(API::RESPOND_NOT_FOUND, $result->getStatusCode());
$this->assertEquals('The requested group could not be found', $result->getMeta()['message']);
}