diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2019-11-27 15:27:18 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2019-11-27 15:27:18 +0100 |
commit | 3a7cf40aaa678bea1df143d2982d603b7a334eec (patch) | |
tree | 63c1e3ad7f7f401d14411a4d44c523632906afc9 /tests/lib/AppFramework | |
parent | 0568b012672d650c6b5a49e72c4028dde5463c60 (diff) | |
download | nextcloud-server-3a7cf40aaa678bea1df143d2982d603b7a334eec.tar.gz nextcloud-server-3a7cf40aaa678bea1df143d2982d603b7a334eec.zip |
Mode to modern phpunit
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'tests/lib/AppFramework')
19 files changed, 85 insertions, 85 deletions
diff --git a/tests/lib/AppFramework/Controller/ControllerTest.php b/tests/lib/AppFramework/Controller/ControllerTest.php index d239cacf633..b1cb1ceab6f 100644 --- a/tests/lib/AppFramework/Controller/ControllerTest.php +++ b/tests/lib/AppFramework/Controller/ControllerTest.php @@ -94,10 +94,10 @@ class ControllerTest extends \Test\TestCase { $this->controller = new ChildController($this->app, $request); } - /** - * @expectedException \DomainException - */ + public function testFormatResonseInvalidFormat() { + $this->expectException(\DomainException::class); + $this->controller->buildResponse(null, 'test'); } diff --git a/tests/lib/AppFramework/Db/EntityTest.php b/tests/lib/AppFramework/Db/EntityTest.php index 3eb9f6eef51..c8ebda55a86 100644 --- a/tests/lib/AppFramework/Db/EntityTest.php +++ b/tests/lib/AppFramework/Db/EntityTest.php @@ -129,25 +129,25 @@ class EntityTest extends \Test\TestCase { } - /** - * @expectedException \BadFunctionCallException - */ + public function testCallShouldOnlyWorkForGetterSetter(){ + $this->expectException(\BadFunctionCallException::class); + $this->entity->something(); } - /** - * @expectedException \BadFunctionCallException - */ + public function testGetterShouldFailIfAttributeNotDefined(){ + $this->expectException(\BadFunctionCallException::class); + $this->entity->getTest(); } - /** - * @expectedException \BadFunctionCallException - */ + public function testSetterShouldFailIfAttributeNotDefined(){ + $this->expectException(\BadFunctionCallException::class); + $this->entity->setTest(); } @@ -245,10 +245,10 @@ class EntityTest extends \Test\TestCase { $this->assertThat($entity->isAnotherBool(), new IsType(IsType::TYPE_BOOL)); } - /** - * @expectedException BadFunctionCallException - */ + public function testIsGetterShoudFailForOtherType() { + $this->expectException(\BadFunctionCallException::class); + $entity = new TestEntity(); $entity->setName('hello'); $this->assertThat($entity->isName(), new IsType(IsType::TYPE_BOOL)); diff --git a/tests/lib/AppFramework/Db/QBMapperTest.php b/tests/lib/AppFramework/Db/QBMapperTest.php index da4102396de..6fa0fe10d88 100644 --- a/tests/lib/AppFramework/Db/QBMapperTest.php +++ b/tests/lib/AppFramework/Db/QBMapperTest.php @@ -127,9 +127,7 @@ class QBMapperTest extends \Test\TestCase { $this->mapper = new QBTestMapper($this->db); } - /** - * - */ + public function testInsertEntityParameterTypeMapping() { $entity = new QBTestEntity(); $entity->setIntProp(123); @@ -166,9 +164,7 @@ class QBMapperTest extends \Test\TestCase { $this->mapper->insert($entity); } - /** - * - */ + public function testUpdateEntityParameterTypeMapping() { $entity = new QBTestEntity(); $entity->setId(789); @@ -214,9 +210,7 @@ class QBMapperTest extends \Test\TestCase { $this->mapper->update($entity); } - /** - * - */ + public function testGetParameterTypeForProperty() { $entity = new QBTestEntity(); diff --git a/tests/lib/AppFramework/DependencyInjection/DIIntergrationTests.php b/tests/lib/AppFramework/DependencyInjection/DIIntergrationTests.php index a0783474df3..669063f4d18 100644 --- a/tests/lib/AppFramework/DependencyInjection/DIIntergrationTests.php +++ b/tests/lib/AppFramework/DependencyInjection/DIIntergrationTests.php @@ -56,7 +56,7 @@ class DIIntergrationTests extends TestCase { /** @var ServerContainer */ private $server; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->server = new ServerContainer(); diff --git a/tests/lib/AppFramework/Http/ContentSecurityPolicyTest.php b/tests/lib/AppFramework/Http/ContentSecurityPolicyTest.php index 1f687b1f7cc..6acc21550d1 100644 --- a/tests/lib/AppFramework/Http/ContentSecurityPolicyTest.php +++ b/tests/lib/AppFramework/Http/ContentSecurityPolicyTest.php @@ -21,7 +21,7 @@ class ContentSecurityPolicyTest extends \Test\TestCase { /** @var ContentSecurityPolicy */ private $contentSecurityPolicy; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->contentSecurityPolicy = new ContentSecurityPolicy(); } diff --git a/tests/lib/AppFramework/Http/EmptyContentSecurityPolicyTest.php b/tests/lib/AppFramework/Http/EmptyContentSecurityPolicyTest.php index 86de705a80c..c19caad23c7 100644 --- a/tests/lib/AppFramework/Http/EmptyContentSecurityPolicyTest.php +++ b/tests/lib/AppFramework/Http/EmptyContentSecurityPolicyTest.php @@ -21,7 +21,7 @@ class EmptyContentSecurityPolicyTest extends \Test\TestCase { /** @var EmptyContentSecurityPolicy */ private $contentSecurityPolicy; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->contentSecurityPolicy = new EmptyContentSecurityPolicy(); } diff --git a/tests/lib/AppFramework/Http/EmptyFeaturePolicyTest.php b/tests/lib/AppFramework/Http/EmptyFeaturePolicyTest.php index 0321d700cd7..1cebc9ef0f2 100644 --- a/tests/lib/AppFramework/Http/EmptyFeaturePolicyTest.php +++ b/tests/lib/AppFramework/Http/EmptyFeaturePolicyTest.php @@ -31,7 +31,7 @@ class EmptyFeaturePolicyTest extends \Test\TestCase { /** @var EmptyFeaturePolicy */ private $policy; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->policy = new EmptyFeaturePolicy(); } diff --git a/tests/lib/AppFramework/Http/FeaturePolicyTest.php b/tests/lib/AppFramework/Http/FeaturePolicyTest.php index 45d7ff0c558..af21457bf0a 100644 --- a/tests/lib/AppFramework/Http/FeaturePolicyTest.php +++ b/tests/lib/AppFramework/Http/FeaturePolicyTest.php @@ -31,7 +31,7 @@ class FeaturePolicyTest extends \Test\TestCase { /** @var EmptyFeaturePolicy */ private $policy; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->policy = new FeaturePolicy(); } diff --git a/tests/lib/AppFramework/Http/FileDisplayResponseTest.php b/tests/lib/AppFramework/Http/FileDisplayResponseTest.php index d7c8b384bf5..5ca7635614c 100644 --- a/tests/lib/AppFramework/Http/FileDisplayResponseTest.php +++ b/tests/lib/AppFramework/Http/FileDisplayResponseTest.php @@ -34,7 +34,7 @@ class FileDisplayResponseTest extends \Test\TestCase { /** @var FileDisplayResponse */ private $response; - public function setUp(): void { + protected function setUp(): void { $this->file = $this->getMockBuilder('OCP\Files\File') ->getMock(); diff --git a/tests/lib/AppFramework/Http/JSONResponseTest.php b/tests/lib/AppFramework/Http/JSONResponseTest.php index 4981313c32a..95d2e2a0a4c 100644 --- a/tests/lib/AppFramework/Http/JSONResponseTest.php +++ b/tests/lib/AppFramework/Http/JSONResponseTest.php @@ -89,11 +89,11 @@ class JSONResponseTest extends \Test\TestCase { $this->assertEquals($expected, $this->json->render()); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Could not json_encode due to invalid non UTF-8 characters in the array: array ( - */ + public function testRenderWithNonUtf8Encoding() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Could not json_encode due to invalid non UTF-8 characters in the array: array ('); + $params = ['test' => hex2bin('e9')]; $this->json->setData($params); $this->json->render(); diff --git a/tests/lib/AppFramework/Http/RequestTest.php b/tests/lib/AppFramework/Http/RequestTest.php index 7ca09cf33da..000a05f7913 100644 --- a/tests/lib/AppFramework/Http/RequestTest.php +++ b/tests/lib/AppFramework/Http/RequestTest.php @@ -103,10 +103,10 @@ class RequestTest extends \Test\TestCase { } - /** - * @expectedException \RuntimeException - */ + public function testImmutableArrayAccess() { + $this->expectException(\RuntimeException::class); + $vars = array( 'get' => array('name' => 'John Q. Public', 'nickname' => 'Joey'), 'method' => 'GET' @@ -123,10 +123,10 @@ class RequestTest extends \Test\TestCase { $request['nickname'] = 'Janey'; } - /** - * @expectedException \RuntimeException - */ + public function testImmutableMagicAccess() { + $this->expectException(\RuntimeException::class); + $vars = array( 'get' => array('name' => 'John Q. Public', 'nickname' => 'Joey'), 'method' => 'GET' @@ -143,10 +143,10 @@ class RequestTest extends \Test\TestCase { $request->{'nickname'} = 'Janey'; } - /** - * @expectedException \LogicException - */ + public function testGetTheMethodRight() { + $this->expectException(\LogicException::class); + $vars = array( 'get' => array('name' => 'John Q. Public', 'nickname' => 'Joey'), 'method' => 'GET', @@ -1246,11 +1246,11 @@ class RequestTest extends \Test\TestCase { $this->assertSame('www.owncloud.org', self::invokePrivate($request, 'getOverwriteHost')); } - /** - * @expectedException \Exception - * @expectedExceptionMessage The requested uri(/foo.php) cannot be processed by the script '/var/www/index.php') - */ + public function testGetPathInfoNotProcessible() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('The requested uri(/foo.php) cannot be processed by the script \'/var/www/index.php\')'); + $request = new Request( [ 'server' => [ @@ -1267,11 +1267,11 @@ class RequestTest extends \Test\TestCase { $request->getPathInfo(); } - /** - * @expectedException \Exception - * @expectedExceptionMessage The requested uri(/foo.php) cannot be processed by the script '/var/www/index.php') - */ + public function testGetRawPathInfoNotProcessible() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('The requested uri(/foo.php) cannot be processed by the script \'/var/www/index.php\')'); + $request = new Request( [ 'server' => [ diff --git a/tests/lib/AppFramework/Middleware/AdditionalScriptsMiddlewareTest.php b/tests/lib/AppFramework/Middleware/AdditionalScriptsMiddlewareTest.php index 3174971032b..8971fe4df06 100644 --- a/tests/lib/AppFramework/Middleware/AdditionalScriptsMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/AdditionalScriptsMiddlewareTest.php @@ -47,7 +47,7 @@ class AdditionalScriptsMiddlewareTest extends \Test\TestCase { /** @var AdditionalScriptsMiddleware */ private $middleWare; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->dispatcher = $this->createMock(EventDispatcherInterface::class); diff --git a/tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php index 6d464a66177..f6ce5c27b22 100644 --- a/tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php @@ -40,7 +40,7 @@ class BruteForceMiddlewareTest extends TestCase { /** @var BruteForceMiddleware */ private $bruteForceMiddleware; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->reflector = $this->createMock(ControllerMethodReflector::class); diff --git a/tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php index e022770a8cf..1c12a4aa153 100644 --- a/tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php @@ -102,9 +102,10 @@ class CORSMiddlewareTest extends \Test\TestCase { /** * @CORS - * @expectedException \OC\AppFramework\Middleware\Security\Exceptions\SecurityException */ public function testCorsIgnoredIfWithCredentialsHeaderPresent() { + $this->expectException(\OC\AppFramework\Middleware\Security\Exceptions\SecurityException::class); + $request = new Request( [ 'server' => [ @@ -171,9 +172,10 @@ class CORSMiddlewareTest extends \Test\TestCase { /** * @CORS - * @expectedException \OC\AppFramework\Middleware\Security\Exceptions\SecurityException */ public function testCORSShouldFailIfPasswordLoginIsForbidden() { + $this->expectException(\OC\AppFramework\Middleware\Security\Exceptions\SecurityException::class); + $request = new Request( ['server' => [ 'PHP_AUTH_USER' => 'user', @@ -196,9 +198,10 @@ class CORSMiddlewareTest extends \Test\TestCase { /** * @CORS - * @expectedException \OC\AppFramework\Middleware\Security\Exceptions\SecurityException */ public function testCORSShouldNotAllowCookieAuth() { + $this->expectException(\OC\AppFramework\Middleware\Security\Exceptions\SecurityException::class); + $request = new Request( ['server' => [ 'PHP_AUTH_USER' => 'user', @@ -251,11 +254,11 @@ class CORSMiddlewareTest extends \Test\TestCase { $this->assertEquals($expected, $response); } - /** - * @expectedException \Exception - * @expectedExceptionMessage A regular exception - */ + public function testAfterExceptionWithRegularException() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('A regular exception'); + $request = new Request( ['server' => [ 'PHP_AUTH_USER' => 'user', diff --git a/tests/lib/AppFramework/Middleware/Security/RateLimitingMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/RateLimitingMiddlewareTest.php index 89e396fcee3..3a06531eefd 100644 --- a/tests/lib/AppFramework/Middleware/Security/RateLimitingMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/Security/RateLimitingMiddlewareTest.php @@ -45,7 +45,7 @@ class RateLimitingMiddlewareTest extends TestCase { /** @var RateLimitingMiddleware */ private $rateLimitingMiddleware; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->request = $this->createMock(IRequest::class); @@ -229,11 +229,11 @@ class RateLimitingMiddlewareTest extends TestCase { $this->rateLimitingMiddleware->beforeController($controller, 'testMethod'); } - /** - * @expectedException \Exception - * @expectedExceptionMessage My test exception - */ + public function testAfterExceptionWithOtherException() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('My test exception'); + /** @var Controller|\PHPUnit_Framework_MockObject_MockObject $controller */ $controller = $this->createMock(Controller::class); diff --git a/tests/lib/AppFramework/Middleware/Security/SameSiteCookieMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/SameSiteCookieMiddlewareTest.php index c30d2760886..6f3c3f32adc 100644 --- a/tests/lib/AppFramework/Middleware/Security/SameSiteCookieMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/Security/SameSiteCookieMiddlewareTest.php @@ -43,7 +43,7 @@ class SameSiteCookieMiddlewareTest extends TestCase { /** @var ControllerMethodReflector|\PHPUnit_Framework_MockObject_MockObject */ private $reflector; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->request = $this->createMock(Request::class); diff --git a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php index 26d09af9003..ae0e6ff484d 100644 --- a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php @@ -256,9 +256,10 @@ class SecurityMiddlewareTest extends \Test\TestCase { /** * @PublicPage - * @expectedException \OC\AppFramework\Middleware\Security\Exceptions\CrossSiteRequestForgeryException */ public function testCsrfCheck(){ + $this->expectException(\OC\AppFramework\Middleware\Security\Exceptions\CrossSiteRequestForgeryException::class); + $this->request->expects($this->once()) ->method('passesCSRFCheck') ->will($this->returnValue(false)); @@ -300,9 +301,10 @@ class SecurityMiddlewareTest extends \Test\TestCase { /** * @PublicPage - * @expectedException \OC\AppFramework\Middleware\Security\Exceptions\CrossSiteRequestForgeryException */ public function testFailCsrfCheck(){ + $this->expectException(\OC\AppFramework\Middleware\Security\Exceptions\CrossSiteRequestForgeryException::class); + $this->request->expects($this->once()) ->method('passesCSRFCheck') ->will($this->returnValue(false)); @@ -317,9 +319,10 @@ class SecurityMiddlewareTest extends \Test\TestCase { /** * @PublicPage * @StrictCookieRequired - * @expectedException \OC\Appframework\Middleware\Security\Exceptions\StrictCookieMissingException */ public function testStrictCookieRequiredCheck() { + $this->expectException(\OC\Appframework\Middleware\Security\Exceptions\StrictCookieMissingException::class); + $this->request->expects($this->never()) ->method('passesCSRFCheck'); $this->request->expects($this->once()) diff --git a/tests/lib/AppFramework/Routing/RoutingTest.php b/tests/lib/AppFramework/Routing/RoutingTest.php index 559561a8ccd..1b7ab054a0f 100644 --- a/tests/lib/AppFramework/Routing/RoutingTest.php +++ b/tests/lib/AppFramework/Routing/RoutingTest.php @@ -122,11 +122,11 @@ class RoutingTest extends \Test\TestCase $this->assertSimpleOCSRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open', [], [], '_something'); } - /** - * @expectedException \UnexpectedValueException - */ + public function testSimpleRouteWithBrokenName() { + $this->expectException(\UnexpectedValueException::class); + $routes = array('routes' => array( array('name' => 'folders_open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete') )); @@ -144,10 +144,10 @@ class RoutingTest extends \Test\TestCase $config->register(); } - /** - * @expectedException \UnexpectedValueException - */ + public function testSimpleOCSRouteWithBrokenName() { + $this->expectException(\UnexpectedValueException::class); + $routes = ['ocs' => [ ['name' => 'folders_open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete'] ]]; diff --git a/tests/lib/AppFramework/Utility/SimpleContainerTest.php b/tests/lib/AppFramework/Utility/SimpleContainerTest.php index cfd55d8d6d8..0341be14af9 100644 --- a/tests/lib/AppFramework/Utility/SimpleContainerTest.php +++ b/tests/lib/AppFramework/Utility/SimpleContainerTest.php @@ -61,7 +61,7 @@ class SimpleContainerTest extends \Test\TestCase { private $container; - public function setUp(): void { + protected function setUp(): void { $this->container = new SimpleContainer(); } @@ -72,18 +72,18 @@ class SimpleContainerTest extends \Test\TestCase { } - /** - * @expectedException \OCP\AppFramework\QueryException - */ + public function testNothingRegistered() { + $this->expectException(\OCP\AppFramework\QueryException::class); + $this->container->query('something really hard'); } - /** - * @expectedException \OCP\AppFramework\QueryException - */ + public function testNotAClass() { + $this->expectException(\OCP\AppFramework\QueryException::class); + $this->container->query('Test\AppFramework\Utility\TestInterface'); } @@ -189,10 +189,10 @@ class SimpleContainerTest extends \Test\TestCase { $this->assertEquals('abc', $this->container->query($query)); } - /** - * @expectedException \OCP\AppFramework\QueryException - */ + public function testConstructorComplexNoTestParameterFound() { + $this->expectException(\OCP\AppFramework\QueryException::class); + $object = $this->container->query( 'Test\AppFramework\Utility\ClassComplexConstructor' ); |