Merge pull request #4783 from nextcloud/lite-application-classes

Use automatic injection for appdata folders
This commit is contained in:
Morris Jobke 2017-05-10 17:31:05 -05:00 committed by GitHub
commit 167013dbf9
19 changed files with 87 additions and 128 deletions

View File

@ -22,30 +22,10 @@
$dispatcher = \OC::$server->getEventDispatcher(); $dispatcher = \OC::$server->getEventDispatcher();
$dispatcher->addListener('OC\AccountManager::userUpdated', function(\Symfony\Component\EventDispatcher\GenericEvent $event) { $dispatcher->addListener('OC\AccountManager::userUpdated', function(\Symfony\Component\EventDispatcher\GenericEvent $event) {
/** @var \OCP\IUser $user */
$user = $event->getSubject(); $user = $event->getSubject();
$keyManager = new \OC\Security\IdentityProof\Manager( /** @var \OCA\LookupServerConnector\UpdateLookupServer $updateLookupServer */
\OC::$server->getAppDataDir('identityproof'), $updateLookupServer = \OC::$server->query(\OCA\LookupServerConnector\UpdateLookupServer::class);
\OC::$server->getCrypto()
);
$config = \OC::$server->getConfig();
$lookupServer = $config->getSystemValue('lookup_server', '');
$updateLookupServer = new \OCA\LookupServerConnector\UpdateLookupServer(
new \OC\Accounts\AccountManager(
\OC::$server->getDatabaseConnection(),
\OC::$server->getEventDispatcher(),
\OC::$server->getJobList()
),
\OC::$server->getHTTPClientService(),
new \OC\Security\IdentityProof\Signer(
$keyManager,
new \OC\AppFramework\Utility\TimeFactory(),
\OC::$server->getUserManager()
),
\OC::$server->getJobList(),
$lookupServer
);
$updateLookupServer->userUpdated($user); $updateLookupServer->userUpdated($user);
}); });

View File

@ -27,6 +27,7 @@ use OC\Security\IdentityProof\Signer;
use OCA\LookupServerConnector\BackgroundJobs\RetryJob; use OCA\LookupServerConnector\BackgroundJobs\RetryJob;
use OCP\BackgroundJob\IJobList; use OCP\BackgroundJob\IJobList;
use OCP\Http\Client\IClientService; use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\IUser; use OCP\IUser;
/** /**
@ -44,27 +45,26 @@ class UpdateLookupServer {
/** @var IJobList */ /** @var IJobList */
private $jobList; private $jobList;
/** @var string URL point to lookup server */ /** @var string URL point to lookup server */
private $lookupServer = 'https://lookup.nextcloud.com'; private $lookupServer;
/** /**
* @param AccountManager $accountManager * @param AccountManager $accountManager
* @param IClientService $clientService * @param IClientService $clientService
* @param Signer $signer * @param Signer $signer
* @param IJobList $jobList * @param IJobList $jobList
* @param string $lookupServer if nothing is given we use the default lookup server * @param IConfig $config
*/ */
public function __construct(AccountManager $accountManager, public function __construct(AccountManager $accountManager,
IClientService $clientService, IClientService $clientService,
Signer $signer, Signer $signer,
IJobList $jobList, IJobList $jobList,
$lookupServer = '') { IConfig $config) {
$this->accountManager = $accountManager; $this->accountManager = $accountManager;
$this->clientService = $clientService; $this->clientService = $clientService;
$this->signer = $signer; $this->signer = $signer;
$this->jobList = $jobList; $this->jobList = $jobList;
if ($lookupServer !== '') {
$this->lookupServer = $lookupServer; $this->lookupServer = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com');
}
$this->lookupServer = rtrim($this->lookupServer, '/'); $this->lookupServer = rtrim($this->lookupServer, '/');
$this->lookupServer .= '/users'; $this->lookupServer .= '/users';
} }

View File

@ -30,12 +30,7 @@
namespace OC\Core; namespace OC\Core;
use OC\Core\Controller\JsController;
use OC\Security\IdentityProof\Manager;
use OCP\AppFramework\App; use OCP\AppFramework\App;
use OC\Core\Controller\CssController;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IRequest;
use OCP\Util; use OCP\Util;
/** /**
@ -53,27 +48,5 @@ class Application extends App {
$container->registerService('defaultMailAddress', function () { $container->registerService('defaultMailAddress', function () {
return Util::getDefaultEmailAddress('lostpassword-noreply'); return Util::getDefaultEmailAddress('lostpassword-noreply');
}); });
$container->registerService(Manager::class, function () {
return new Manager(
\OC::$server->getAppDataDir('identityproof'),
\OC::$server->getCrypto()
);
});
$container->registerService(CssController::class, function () use ($container) {
return new CssController(
$container->query('appName'),
$container->query(IRequest::class),
\OC::$server->getAppDataDir('css'),
$container->query(ITimeFactory::class)
);
});
$container->registerService(JsController::class, function () use ($container) {
return new JsController(
$container->query('AppName'),
$container->query(IRequest::class),
$container->getServer()->getAppDataDir('js'),
$container->query(ITimeFactory::class)
);
});
} }
} }

View File

@ -21,6 +21,7 @@
namespace OC\Core\Controller; namespace OC\Core\Controller;
use OC\Files\AppData\Factory;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use OCP\AppFramework\Http\NotFoundResponse; use OCP\AppFramework\Http\NotFoundResponse;
@ -43,13 +44,13 @@ class CssController extends Controller {
/** /**
* @param string $appName * @param string $appName
* @param IRequest $request * @param IRequest $request
* @param IAppData $appData * @param Factory $appDataFactory
* @param ITimeFactory $timeFactory * @param ITimeFactory $timeFactory
*/ */
public function __construct($appName, IRequest $request, IAppData $appData, ITimeFactory $timeFactory) { public function __construct($appName, IRequest $request, Factory $appDataFactory, ITimeFactory $timeFactory) {
parent::__construct($appName, $request); parent::__construct($appName, $request);
$this->appData = $appData; $this->appData = $appDataFactory->get('css');
$this->timeFactory = $timeFactory; $this->timeFactory = $timeFactory;
} }

View File

@ -22,6 +22,7 @@
*/ */
namespace OC\Core\Controller; namespace OC\Core\Controller;
use OC\Files\AppData\Factory;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use OCP\AppFramework\Http\NotFoundResponse; use OCP\AppFramework\Http\NotFoundResponse;
@ -44,13 +45,13 @@ class JsController extends Controller {
/** /**
* @param string $appName * @param string $appName
* @param IRequest $request * @param IRequest $request
* @param IAppData $appData * @param Factory $appDataFactory
* @param ITimeFactory $timeFactory * @param ITimeFactory $timeFactory
*/ */
public function __construct($appName, IRequest $request, IAppData $appData, ITimeFactory $timeFactory) { public function __construct($appName, IRequest $request, Factory $appDataFactory, ITimeFactory $timeFactory) {
parent::__construct($appName, $request); parent::__construct($appName, $request);
$this->appData = $appData; $this->appData = $appDataFactory->get('js');
$this->timeFactory = $timeFactory; $this->timeFactory = $timeFactory;
} }

View File

@ -22,24 +22,24 @@
namespace OC\App\AppStore\Fetcher; namespace OC\App\AppStore\Fetcher;
use OC\App\AppStore\Version\VersionParser; use OC\App\AppStore\Version\VersionParser;
use OC\Files\AppData\Factory;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IAppData;
use OCP\Http\Client\IClientService; use OCP\Http\Client\IClientService;
use OCP\IConfig; use OCP\IConfig;
class AppFetcher extends Fetcher { class AppFetcher extends Fetcher {
/** /**
* @param IAppData $appData * @param Factory $appDataFactory
* @param IClientService $clientService * @param IClientService $clientService
* @param ITimeFactory $timeFactory * @param ITimeFactory $timeFactory
* @param IConfig $config; * @param IConfig $config;
*/ */
public function __construct(IAppData $appData, public function __construct(Factory $appDataFactory,
IClientService $clientService, IClientService $clientService,
ITimeFactory $timeFactory, ITimeFactory $timeFactory,
IConfig $config) { IConfig $config) {
parent::__construct( parent::__construct(
$appData, $appDataFactory,
$clientService, $clientService,
$timeFactory, $timeFactory,
$config $config

View File

@ -21,24 +21,24 @@
namespace OC\App\AppStore\Fetcher; namespace OC\App\AppStore\Fetcher;
use OC\Files\AppData\Factory;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IAppData;
use OCP\Http\Client\IClientService; use OCP\Http\Client\IClientService;
use OCP\IConfig; use OCP\IConfig;
class CategoryFetcher extends Fetcher { class CategoryFetcher extends Fetcher {
/** /**
* @param IAppData $appData * @param Factory $appDataFactory
* @param IClientService $clientService * @param IClientService $clientService
* @param ITimeFactory $timeFactory * @param ITimeFactory $timeFactory
* @param IConfig $config * @param IConfig $config
*/ */
public function __construct(IAppData $appData, public function __construct(Factory $appDataFactory,
IClientService $clientService, IClientService $clientService,
ITimeFactory $timeFactory, ITimeFactory $timeFactory,
IConfig $config) { IConfig $config) {
parent::__construct( parent::__construct(
$appData, $appDataFactory,
$clientService, $clientService,
$timeFactory, $timeFactory,
$config $config

View File

@ -21,6 +21,7 @@
namespace OC\App\AppStore\Fetcher; namespace OC\App\AppStore\Fetcher;
use OC\Files\AppData\Factory;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IAppData; use OCP\Files\IAppData;
@ -47,16 +48,16 @@ abstract class Fetcher {
protected $version; protected $version;
/** /**
* @param IAppData $appData * @param Factory $appDataFactory
* @param IClientService $clientService * @param IClientService $clientService
* @param ITimeFactory $timeFactory * @param ITimeFactory $timeFactory
* @param IConfig $config * @param IConfig $config
*/ */
public function __construct(IAppData $appData, public function __construct(Factory $appDataFactory,
IClientService $clientService, IClientService $clientService,
ITimeFactory $timeFactory, ITimeFactory $timeFactory,
IConfig $config) { IConfig $config) {
$this->appData = $appData; $this->appData = $appDataFactory->get('appstore');
$this->clientService = $clientService; $this->clientService = $clientService;
$this->timeFactory = $timeFactory; $this->timeFactory = $timeFactory;
$this->config = $config; $this->config = $config;

View File

@ -165,7 +165,7 @@ class DIContainer extends SimpleContainer implements IAppContainer {
$this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) { $this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) {
return new \OC\Security\IdentityProof\Manager( return new \OC\Security\IdentityProof\Manager(
$this->getServer()->getAppDataDir('identityproof'), $this->getServer()->query(\OC\Files\AppData\Factory::class),
$this->getServer()->getCrypto() $this->getServer()->getCrypto()
); );
}); });

View File

@ -21,6 +21,7 @@
namespace OC\Security\IdentityProof; namespace OC\Security\IdentityProof;
use OC\Files\AppData\Factory;
use OCP\Files\IAppData; use OCP\Files\IAppData;
use OCP\IUser; use OCP\IUser;
use OCP\Security\ICrypto; use OCP\Security\ICrypto;
@ -32,12 +33,12 @@ class Manager {
private $crypto; private $crypto;
/** /**
* @param IAppData $appData * @param Factory $appDataFactory
* @param ICrypto $crypto * @param ICrypto $crypto
*/ */
public function __construct(IAppData $appData, public function __construct(Factory $appDataFactory,
ICrypto $crypto) { ICrypto $crypto) {
$this->appData = $appData; $this->appData = $appDataFactory->get('identityproof');
$this->crypto = $crypto; $this->crypto = $crypto;
} }

View File

@ -420,24 +420,8 @@ class Server extends ServerContainer implements IServerContainer {
$this->registerService('AppHelper', function ($c) { $this->registerService('AppHelper', function ($c) {
return new \OC\AppHelper(); return new \OC\AppHelper();
}); });
$this->registerService(AppFetcher::class, function ($c) {
return new AppFetcher(
$this->getAppDataDir('appstore'),
$this->getHTTPClientService(),
$this->query(TimeFactory::class),
$this->getConfig()
);
});
$this->registerAlias('AppFetcher', AppFetcher::class); $this->registerAlias('AppFetcher', AppFetcher::class);
$this->registerAlias('CategoryFetcher', CategoryFetcher::class);
$this->registerService('CategoryFetcher', function ($c) {
return new CategoryFetcher(
$this->getAppDataDir('appstore'),
$this->getHTTPClientService(),
$this->query(TimeFactory::class),
$this->getConfig()
);
});
$this->registerService(\OCP\ICache::class, function ($c) { $this->registerService(\OCP\ICache::class, function ($c) {
return new Cache\File(); return new Cache\File();
@ -1290,7 +1274,7 @@ class Server extends ServerContainer implements IServerContainer {
* @return AppFetcher * @return AppFetcher
*/ */
public function getAppFetcher() { public function getAppFetcher() {
return $this->query('AppFetcher'); return $this->query(AppFetcher::class);
} }
/** /**

View File

@ -32,7 +32,6 @@
namespace OC; namespace OC;
use OC\App\AppStore\Fetcher\AppFetcher;
use OC\Hooks\BasicEmitter; use OC\Hooks\BasicEmitter;
use OC\IntegrityCheck\Checker; use OC\IntegrityCheck\Checker;
use OC_App; use OC_App;

View File

@ -30,8 +30,6 @@
namespace OC\Settings; namespace OC\Settings;
use OC\App\AppStore\Fetcher\AppFetcher;
use OC\App\AppStore\Fetcher\CategoryFetcher;
use OC\AppFramework\Utility\TimeFactory; use OC\AppFramework\Utility\TimeFactory;
use OC\Authentication\Token\IProvider; use OC\Authentication\Token\IProvider;
use OC\Server; use OC\Server;
@ -110,26 +108,6 @@ class Application extends App {
Util::getDefaultEmailAddress('no-reply') Util::getDefaultEmailAddress('no-reply')
); );
}); });
$container->registerService(AppFetcher::class, function (IContainer $c) {
/** @var Server $server */
$server = $c->query('ServerContainer');
return new AppFetcher(
$server->getAppDataDir('appstore'),
$server->getHTTPClientService(),
$server->query(TimeFactory::class),
$server->getConfig()
);
});
$container->registerService(CategoryFetcher::class, function (IContainer $c) {
/** @var Server $server */
$server = $c->query('ServerContainer');
return new CategoryFetcher(
$server->getAppDataDir('appstore'),
$server->getHTTPClientService(),
$server->query(TimeFactory::class),
$server->getConfig()
);
});
} }
public function register() { public function register() {

View File

@ -23,7 +23,7 @@
namespace Tests\Core\Controller; namespace Tests\Core\Controller;
use OC\Core\Controller\CssController; use OC\Core\Controller\CssController;
use OC\HintException; use OC\Files\AppData\Factory;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use OCP\AppFramework\Http\FileDisplayResponse; use OCP\AppFramework\Http\FileDisplayResponse;
use OCP\AppFramework\Http\NotFoundResponse; use OCP\AppFramework\Http\NotFoundResponse;
@ -40,7 +40,7 @@ class CssControllerTest extends TestCase {
/** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */ /** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */
private $appData; private $appData;
/** @var IRequests|\PHPUnit_Framework_MockObject_MockObject */ /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
private $request; private $request;
/** @var CssController */ /** @var CssController */
@ -49,8 +49,15 @@ class CssControllerTest extends TestCase {
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
/** @var Factory|\PHPUnit_Framework_MockObject_MockObject $factory */
$factory = $this->createMock(Factory::class);
$this->appData = $this->createMock(IAppData::class); $this->appData = $this->createMock(IAppData::class);
$factory->expects($this->once())
->method('get')
->with('css')
->willReturn($this->appData);
/** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject $timeFactory */
$timeFactory = $this->createMock(ITimeFactory::class); $timeFactory = $this->createMock(ITimeFactory::class);
$timeFactory->method('getTime') $timeFactory->method('getTime')
->willReturn(1337); ->willReturn(1337);
@ -60,7 +67,7 @@ class CssControllerTest extends TestCase {
$this->controller = new CssController( $this->controller = new CssController(
'core', 'core',
$this->request, $this->request,
$this->appData, $factory,
$timeFactory $timeFactory
); );
} }

View File

@ -23,6 +23,7 @@
namespace Tests\Core\Controller; namespace Tests\Core\Controller;
use OC\Core\Controller\JsController; use OC\Core\Controller\JsController;
use OC\Files\AppData\Factory;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use OCP\AppFramework\Http\FileDisplayResponse; use OCP\AppFramework\Http\FileDisplayResponse;
use OCP\AppFramework\Http\NotFoundResponse; use OCP\AppFramework\Http\NotFoundResponse;
@ -48,8 +49,15 @@ class JsControllerTest extends TestCase {
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
/** @var Factory|\PHPUnit_Framework_MockObject_MockObject $factory */
$factory = $this->createMock(Factory::class);
$this->appData = $this->createMock(IAppData::class); $this->appData = $this->createMock(IAppData::class);
$factory->expects($this->once())
->method('get')
->with('js')
->willReturn($this->appData);
/** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject $timeFactory */
$timeFactory = $this->createMock(ITimeFactory::class); $timeFactory = $this->createMock(ITimeFactory::class);
$timeFactory->method('getTime') $timeFactory->method('getTime')
->willReturn(1337); ->willReturn(1337);
@ -59,7 +67,7 @@ class JsControllerTest extends TestCase {
$this->controller = new JsController( $this->controller = new JsController(
'core', 'core',
$this->request, $this->request,
$this->appData, $factory,
$timeFactory $timeFactory
); );
} }

View File

@ -22,6 +22,7 @@
namespace Test\App\AppStore\Fetcher; namespace Test\App\AppStore\Fetcher;
use OC\App\AppStore\Fetcher\AppFetcher; use OC\App\AppStore\Fetcher\AppFetcher;
use OC\Files\AppData\Factory;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IAppData; use OCP\Files\IAppData;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
@ -53,7 +54,13 @@ EOD;
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
/** @var Factory|\PHPUnit_Framework_MockObject_MockObject $factory */
$factory = $this->createMock(Factory::class);
$this->appData = $this->createMock(IAppData::class); $this->appData = $this->createMock(IAppData::class);
$factory->expects($this->once())
->method('get')
->with('appstore')
->willReturn($this->appData);
$this->clientService = $this->createMock(IClientService::class); $this->clientService = $this->createMock(IClientService::class);
$this->timeFactory = $this->createMock(ITimeFactory::class); $this->timeFactory = $this->createMock(ITimeFactory::class);
$this->config = $this->createMock(IConfig::class); $this->config = $this->createMock(IConfig::class);
@ -64,7 +71,7 @@ EOD;
->with('version') ->with('version')
->willReturn('11.0.0.2'); ->willReturn('11.0.0.2');
$this->fetcher = new AppFetcher( $this->fetcher = new AppFetcher(
$this->appData, $factory,
$this->clientService, $this->clientService,
$this->timeFactory, $this->timeFactory,
$this->config $this->config

View File

@ -23,14 +23,14 @@ namespace Test\App\AppStore\Fetcher;
use OC\App\AppStore\Fetcher\CategoryFetcher; use OC\App\AppStore\Fetcher\CategoryFetcher;
class CategoryFetcherTest extends FetcherBase { class CategoryFetcherTest extends FetcherBase {
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$this->fileName = 'categories.json'; $this->fileName = 'categories.json';
$this->endpoint = 'https://apps.nextcloud.com/api/v1/categories.json'; $this->endpoint = 'https://apps.nextcloud.com/api/v1/categories.json';
$this->fetcher = new CategoryFetcher( $this->fetcher = new CategoryFetcher(
$this->appData, $this->appDataFactory,
$this->clientService, $this->clientService,
$this->timeFactory, $this->timeFactory,
$this->config $this->config

View File

@ -22,6 +22,7 @@
namespace Test\App\AppStore\Fetcher; namespace Test\App\AppStore\Fetcher;
use OC\App\AppStore\Fetcher\Fetcher; use OC\App\AppStore\Fetcher\Fetcher;
use OC\Files\AppData\Factory;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IAppData; use OCP\Files\IAppData;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
@ -34,6 +35,8 @@ use OCP\IConfig;
use Test\TestCase; use Test\TestCase;
abstract class FetcherBase extends TestCase { abstract class FetcherBase extends TestCase {
/** @var Factory|\PHPUnit_Framework_MockObject_MockObject */
protected $appDataFactory;
/** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */ /** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */
protected $appData; protected $appData;
/** @var IClientService|\PHPUnit_Framework_MockObject_MockObject */ /** @var IClientService|\PHPUnit_Framework_MockObject_MockObject */
@ -51,7 +54,12 @@ abstract class FetcherBase extends TestCase {
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$this->appDataFactory = $this->createMock(Factory::class);
$this->appData = $this->createMock(IAppData::class); $this->appData = $this->createMock(IAppData::class);
$this->appDataFactory->expects($this->once())
->method('get')
->with('appstore')
->willReturn($this->appData);
$this->clientService = $this->createMock(IClientService::class); $this->clientService = $this->createMock(IClientService::class);
$this->timeFactory = $this->createMock(ITimeFactory::class); $this->timeFactory = $this->createMock(ITimeFactory::class);
$this->config = $this->createMock(IConfig::class); $this->config = $this->createMock(IConfig::class);

View File

@ -21,6 +21,7 @@
namespace Test\Security\IdentityProof; namespace Test\Security\IdentityProof;
use OC\Files\AppData\Factory;
use OC\Security\IdentityProof\Key; use OC\Security\IdentityProof\Key;
use OC\Security\IdentityProof\Manager; use OC\Security\IdentityProof\Manager;
use OCP\Files\IAppData; use OCP\Files\IAppData;
@ -31,6 +32,8 @@ use OCP\Security\ICrypto;
use Test\TestCase; use Test\TestCase;
class ManagerTest extends TestCase { class ManagerTest extends TestCase {
/** @var Factory|\PHPUnit_Framework_MockObject_MockObject */
private $factory;
/** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */ /** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */
private $appData; private $appData;
/** @var ICrypto|\PHPUnit_Framework_MockObject_MockObject */ /** @var ICrypto|\PHPUnit_Framework_MockObject_MockObject */
@ -40,11 +43,19 @@ class ManagerTest extends TestCase {
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
/** @var Factory|\PHPUnit_Framework_MockObject_MockObject $factory */
$this->factory = $this->createMock(Factory::class);
$this->appData = $this->createMock(IAppData::class); $this->appData = $this->createMock(IAppData::class);
$this->factory->expects($this->any())
->method('get')
->with('identityproof')
->willReturn($this->appData);
$this->crypto = $this->createMock(ICrypto::class); $this->crypto = $this->createMock(ICrypto::class);
$this->manager = $this->getMockBuilder(Manager::class) $this->manager = $this->getMockBuilder(Manager::class)
->setConstructorArgs([ ->setConstructorArgs([
$this->appData, $this->factory,
$this->crypto $this->crypto
]) ])
->setMethods(['generateKeyPair']) ->setMethods(['generateKeyPair'])
@ -151,12 +162,12 @@ class ManagerTest extends TestCase {
public function testGenerateKeyPair() { public function testGenerateKeyPair() {
$manager = new Manager( $manager = new Manager(
$this->appData, $this->factory,
$this->crypto $this->crypto
); );
$data = 'MyTestData'; $data = 'MyTestData';
list($resultPublicKey, $resultPrivateKey) = $this->invokePrivate($manager, 'generateKeyPair'); list($resultPublicKey, $resultPrivateKey) = self::invokePrivate($manager, 'generateKeyPair');
openssl_sign($data, $signature, $resultPrivateKey); openssl_sign($data, $signature, $resultPrivateKey);
$details = openssl_pkey_get_details(openssl_pkey_get_public($resultPublicKey)); $details = openssl_pkey_get_details(openssl_pkey_get_public($resultPublicKey));