* getMock is deprecated.
* \PDOStatement mocking fails hard on phpunit 4.8
class ApiControllerTest extends \Test\TestCase {
- /** @var ChildApiController */
- protected $controller;
-
- public function testCors() {
- $request = new Request(
- ['server' => ['HTTP_ORIGIN' => 'test']],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
- );
- $this->controller = new ChildApiController('app', $request, 'verbs',
- 'headers', 100);
-
- $response = $this->controller->preflightedCors();
-
- $headers = $response->getHeaders();
-
- $this->assertEquals('test', $headers['Access-Control-Allow-Origin']);
- $this->assertEquals('verbs', $headers['Access-Control-Allow-Methods']);
- $this->assertEquals('headers', $headers['Access-Control-Allow-Headers']);
- $this->assertEquals('false', $headers['Access-Control-Allow-Credentials']);
- $this->assertEquals(100, $headers['Access-Control-Max-Age']);
- }
+ /** @var ChildApiController */
+ protected $controller;
+
+ public function testCors() {
+ $request = new Request(
+ ['server' => ['HTTP_ORIGIN' => 'test']],
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')
+ ->disableOriginalConstructor()
+ ->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock()
+ );
+ $this->controller = new ChildApiController('app', $request, 'verbs',
+ 'headers', 100);
+
+ $response = $this->controller->preflightedCors();
+
+ $headers = $response->getHeaders();
+
+ $this->assertEquals('test', $headers['Access-Control-Allow-Origin']);
+ $this->assertEquals('verbs', $headers['Access-Control-Allow-Methods']);
+ $this->assertEquals('headers', $headers['Access-Control-Allow-Headers']);
+ $this->assertEquals('false', $headers['Access-Control-Allow-Credentials']);
+ $this->assertEquals(100, $headers['Access-Control-Max-Age']);
+ }
}
'session' => ['sezession' => 'kein'],
'method' => 'hi',
],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')
+ ->disableOriginalConstructor()
+ ->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock()
);
- $this->app = $this->getMock('OC\AppFramework\DependencyInjection\DIContainer',
- array('getAppName'), array('test'));
+ $this->app = $this->getMockBuilder('OC\AppFramework\DependencyInjection\DIContainer')
+ ->setMethods(['getAppName'])
+ ->setConstructorArgs(['test'])
+ ->getMock();
$this->app->expects($this->any())
->method('getAppName')
->will($this->returnValue('apptemplate_advanced'));
class OCSControllerTest extends \Test\TestCase {
-
- private $controller;
-
public function testCors() {
$request = new Request(
[
'HTTP_ORIGIN' => 'test',
],
],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')
+ ->disableOriginalConstructor()
+ ->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock()
);
$controller = new ChildOCSController('app', $request, 'verbs',
'headers', 100);
public function testXML() {
$controller = new ChildOCSController('app', new Request(
[],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')
+ ->disableOriginalConstructor()
+ ->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock()
));
$expected = "<?xml version=\"1.0\"?>\n" .
"<ocs>\n" .
public function testXMLDataResponse() {
$controller = new ChildOCSController('app', new Request(
[],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')
+ ->disableOriginalConstructor()
+ ->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock()
));
$expected = "<?xml version=\"1.0\"?>\n" .
"<ocs>\n" .
public function testJSON() {
$controller = new ChildOCSController('app', new Request(
[],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')
+ ->disableOriginalConstructor()
+ ->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock()
));
$expected = '{"ocs":{"meta":{"status":"failure","statuscode":400,"message":"OK",' .
'"totalitems":"","itemsperpage":""},"data":{"test":"hi"}}}';
protected function setUp(){
parent::setUp();
- $this->container = $this->getMock('OC\AppFramework\DependencyInjection\DIContainer',
- ['isAdminUser'], ['name']
- );
- $this->api = $this->getMock('OC\AppFramework\Core\API', array(), array('hi'));
+ $this->container = $this->getMockBuilder('OC\AppFramework\DependencyInjection\DIContainer')
+ ->setMethods(['isAdminUser'])
+ ->setConstructorArgs(['name'])
+ ->getMock();
+ $this->api = $this->getMockBuilder('OC\AppFramework\Core\API')
+ ->setConstructorArgs(['hi'])
+ ->getMock();
}
public function testProvidesAPI(){
public function testMiddlewareDispatcherIncludesSecurityMiddleware(){
$this->container['Request'] = new Request(
['method' => 'GET'],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')
+ ->disableOriginalConstructor()
+ ->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock()
);
$security = $this->container['SecurityMiddleware'];
$dispatcher = $this->container['MiddlewareDispatcher'];
'\OC\AppFramework\Middleware\MiddlewareDispatcher')
->disableOriginalConstructor()
->getMock();
- $this->controller = $this->getMock(
- '\OCP\AppFramework\Controller',
- array($this->controllerMethod), array($app, $request));
+ $this->controller = $this->getMockBuilder(
+ '\OCP\AppFramework\Controller')
+ ->setMethods([$this->controllerMethod])
+ ->setConstructorArgs([$app, $request])
+ ->getMock();
$this->request = $this->getMockBuilder(
'\OC\AppFramework\Http\Request')
],
'method' => 'POST'
],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')
+ ->disableOriginalConstructor()
+ ->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock()
);
$this->dispatcher = new Dispatcher(
$this->http, $this->middlewareDispatcher, $this->reflector,
],
'method' => 'POST',
],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')
+ ->disableOriginalConstructor()
+ ->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock()
);
$this->dispatcher = new Dispatcher(
$this->http, $this->middlewareDispatcher, $this->reflector,
],
'method' => 'GET'
],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')
+ ->disableOriginalConstructor()
+ ->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock()
);
$this->dispatcher = new Dispatcher(
$this->http, $this->middlewareDispatcher, $this->reflector,
],
'method' => 'GET'
],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')
+ ->disableOriginalConstructor()
+ ->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock()
);
$this->dispatcher = new Dispatcher(
$this->http, $this->middlewareDispatcher, $this->reflector,
],
'method' => 'PUT'
],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')
+ ->disableOriginalConstructor()
+ ->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock()
);
$this->dispatcher = new Dispatcher(
$this->http, $this->middlewareDispatcher, $this->reflector,
],
'method' => 'POST'
],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')
+ ->disableOriginalConstructor()
+ ->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock()
);
$this->dispatcher = new Dispatcher(
$this->http, $this->middlewareDispatcher, $this->reflector,
protected function setUp() {
parent::setUp();
- $this->output = $this->getMock('OCP\\AppFramework\\Http\\IOutput');
+ $this->output = $this->getMockBuilder('OCP\\AppFramework\\Http\\IOutput')
+ ->disableOriginalConstructor()
+ ->getMock();
}
public function testOutputNotModified(){
protected function setUp() {
parent::setUp();
- $this->api = $this->getMock('OC\AppFramework\Core\API',
- array('getAppName'), array('test'));
+ $this->api = $this->getMockBuilder('OC\AppFramework\Core\API')
+ ->setMethods(['getAppName'])
+ ->setConstructorArgs(['test'])
+ ->getMock();
$this->api->expects($this->any())
->method('getAppName')
->will($this->returnValue('app'));
private function getControllerMock(){
- return $this->getMock(
- 'OCP\AppFramework\Controller',
- ['method'],
- ['app',
+ return $this->getMockBuilder('OCP\AppFramework\Controller')
+ ->setMethods(['method'])
+ ->setConstructorArgs(['app',
new Request(
['method' => 'GET'],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')->getMock()
)
- ]
- );
+ ])->getMock();
}
public function testAfterExceptionShouldReturnResponseOfMiddleware(){
$response = new Response();
- $m1 = $this->getMock('\OCP\AppFramework\Middleware',
- array('afterException', 'beforeController'));
+ $m1 = $this->getMockBuilder('\OCP\AppFramework\Middleware')
+ ->setMethods(['afterException', 'beforeController'])
+ ->getMock();
$m1->expects($this->never())
->method('afterException');
- $m2 = $this->getMock('OCP\AppFramework\Middleware',
- array('afterException', 'beforeController'));
+ $m2 = $this->getMockBuilder('OCP\AppFramework\Middleware')
+ ->setMethods(['afterException', 'beforeController'])
+ ->getMock();
$m2->expects($this->once())
->method('afterException')
->will($this->returnValue($response));
public function testExceptionShouldRunAfterExceptionOfOnlyPreviouslyExecutedMiddlewares(){
$m1 = $this->getMiddleware();
$m2 = $this->getMiddleware(true);
- $m3 = $this->getMock('\OCP\AppFramework\Middleware');
+ $m3 = $this->getMockBuilder('\OCP\AppFramework\Middleware')->getMock();
$m3->expects($this->never())
->method('afterException');
$m3->expects($this->never())
$this->middleware = new ChildMiddleware();
- $this->api = $this->getMockBuilder(
- 'OC\AppFramework\DependencyInjection\DIContainer')
+ $this->api = $this->getMockBuilder('OC\AppFramework\DependencyInjection\DIContainer')
->disableOriginalConstructor()
->getMock();
- $this->controller = $this->getMock(
- 'OCP\AppFramework\Controller',
- [],
- [
+ $this->controller = $this->getMockBuilder('OCP\AppFramework\Controller')
+ ->setMethods([])
+ ->setConstructorArgs([
$this->api,
new Request(
[],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')->getMock()
)
- ]
- );
+ ])->getMock();
$this->exception = new \Exception();
- $this->response = $this->getMock('OCP\AppFramework\Http\Response');
+ $this->response = $this->getMockBuilder('OCP\AppFramework\Http\Response')->getMock();
}
'HTTP_ORIGIN' => 'test'
]
],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')->getMock()
);
$this->reflector->reflect($this, __FUNCTION__);
$middleware = new CORSMiddleware($request, $this->reflector, $this->session);
'HTTP_ORIGIN' => 'test'
]
],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')->getMock()
);
$middleware = new CORSMiddleware($request, $this->reflector, $this->session);
public function testNoOriginHeaderNoCORSHEADER() {
$request = new Request(
[],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')->getMock()
);
$this->reflector->reflect($this, __FUNCTION__);
$middleware = new CORSMiddleware($request, $this->reflector, $this->session);
'HTTP_ORIGIN' => 'test'
]
],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')->getMock()
);
$this->reflector->reflect($this, __FUNCTION__);
$middleware = new CORSMiddleware($request, $this->reflector, $this->session);
public function testNoCORSShouldAllowCookieAuth() {
$request = new Request(
[],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')->getMock()
);
$this->reflector->reflect($this, __FUNCTION__);
$middleware = new CORSMiddleware($request, $this->reflector, $this->session);
'PHP_AUTH_USER' => 'user',
'PHP_AUTH_PW' => 'pass'
]],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')->getMock()
);
$this->session->expects($this->once())
->method('logout');
'PHP_AUTH_USER' => 'user',
'PHP_AUTH_PW' => 'pass'
]],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')->getMock()
);
$this->session->expects($this->once())
->method('logout');
'PHP_AUTH_USER' => 'user',
'PHP_AUTH_PW' => 'pass'
]],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')->getMock()
);
$this->session->expects($this->once())
->method('logout');
'PHP_AUTH_USER' => 'user',
'PHP_AUTH_PW' => 'pass'
]],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')->getMock()
);
$middleware = new CORSMiddleware($request, $this->reflector, $this->session);
$response = $middleware->afterException($this, __FUNCTION__, new SecurityException('A security exception'));
'PHP_AUTH_USER' => 'user',
'PHP_AUTH_PW' => 'pass'
]],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')->getMock()
);
$middleware = new CORSMiddleware($request, $this->reflector, $this->session);
$response = $middleware->afterException($this, __FUNCTION__, new SecurityException('A security exception', 501));
'PHP_AUTH_USER' => 'user',
'PHP_AUTH_PW' => 'pass'
]],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')->getMock()
);
$middleware = new CORSMiddleware($request, $this->reflector, $this->session);
$middleware->afterException($this, __FUNCTION__, new \Exception('A regular exception'));
'REQUEST_URI' => 'owncloud/index.php/apps/specialapp'
]
],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')->getMock()
);
$this->middleware = $this->getMiddleware(false, false);
$this->urlGenerator
'REQUEST_URI' => 'owncloud/index.php/apps/specialapp'
]
],
- $this->getMock('\OCP\Security\ISecureRandom'),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(),
+ $this->getMockBuilder('\OCP\IConfig')->getMock()
);
$this->middleware = $this->getMiddleware(false, false);
$this->logger
$this->request = new Request(
[],
$this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(),
- $this->getMock('\OCP\IConfig')
+ $this->getMockBuilder('\OCP\IConfig')->getMock()
);
$this->reflector = new ControllerMethodReflector();
}
));
// router mock
- $router = $this->getMock("\OC\Route\Router", array('create'), [\OC::$server->getLogger()]);
+ $router = $this->getMockBuilder('\OC\Route\Router')
+ ->setMethods(['create'])
+ ->setConstructorArgs([\OC::$server->getLogger()])
+ ->getMock();
// load route configuration
$container = new DIContainer('app1');
$route = $this->mockRoute($container, $verb, $controllerName, $actionName, $requirements, $defaults);
// router mock
- $router = $this->getMock("\OC\Route\Router", array('create'), [\OC::$server->getLogger()]);
+ $router = $this->getMockBuilder('\OC\Route\Router')
+ ->setMethods(['create'])
+ ->setConstructorArgs([\OC::$server->getLogger()])
+ ->getMock();
// we expect create to be called once:
$router
private function assertResource($yaml, $resourceName, $url, $controllerName, $paramName)
{
// router mock
- $router = $this->getMock("\OC\Route\Router", array('create'), [\OC::$server->getLogger()]);
+ $router = $this->getMockBuilder('\OC\Route\Router')
+ ->setMethods(['create'])
+ ->setConstructorArgs([\OC::$server->getLogger()])
+ ->getMock();
// route mocks
$container = new DIContainer('app1');
array $requirements=array(),
array $defaults=array()
) {
- $route = $this->getMock("\OC\Route\Route", array('method', 'action', 'requirements', 'defaults'), array(), '', false);
+ $route = $this->getMockBuilder('\OC\Route\Route')
+ ->setMethods(['method', 'action', 'requirements', 'defaults'])
+ ->disableOriginalConstructor()
+ ->getMock();
$route
->expects($this->exactly(1))
->method('method')