Fix "Undefined method setExpectedException()"

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2018-01-24 18:10:16 +01:00
parent c3424df1f0
commit 870023365c
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
19 changed files with 50 additions and 58 deletions

View File

@ -22,8 +22,8 @@
namespace OCA\DAV\Tests\unit\AppInfo; namespace OCA\DAV\Tests\unit\AppInfo;
use OC\App\AppManager;
use Test\TestCase; use Test\TestCase;
use OCP\App\IAppManager;
use OC\ServerContainer; use OC\ServerContainer;
use OCA\DAV\AppInfo\PluginManager; use OCA\DAV\AppInfo\PluginManager;
@ -37,7 +37,7 @@ class PluginManagerTest extends TestCase {
$server = $this->createMock(ServerContainer::class); $server = $this->createMock(ServerContainer::class);
$appManager = $this->createMock(IAppManager::class); $appManager = $this->createMock(AppManager::class);
$appManager->method('getInstalledApps') $appManager->method('getInstalledApps')
->willReturn(['adavapp', 'adavapp2']); ->willReturn(['adavapp', 'adavapp2']);

View File

@ -36,6 +36,7 @@ use OCP\IL10N;
use Sabre\DAV\PropPatch; use Sabre\DAV\PropPatch;
use Sabre\DAV\Xml\Property\Href; use Sabre\DAV\Xml\Property\Href;
use Sabre\DAVACL\IACL; use Sabre\DAVACL\IACL;
use Sabre\DAV\Exception\NotFound;
/** /**
* Class CalDavBackendTest * Class CalDavBackendTest
@ -526,7 +527,7 @@ EOD;
$calendar->setPublishStatus(false); $calendar->setPublishStatus(false);
$this->assertEquals(false, $calendar->getPublishStatus()); $this->assertEquals(false, $calendar->getPublishStatus());
$this->setExpectedException('Sabre\DAV\Exception\NotFound'); $this->expectException(NotFound::class);
$this->backend->getPublicCalendar($publicCalendarURI); $this->backend->getPublicCalendar($publicCalendarURI);
} }

View File

@ -29,6 +29,7 @@
namespace OCA\DAV\Tests\unit\Connector\Sabre; namespace OCA\DAV\Tests\unit\Connector\Sabre;
use OC\User\User; use OC\User\User;
use OCA\DAV\Connector\Sabre\Directory;
use OCA\DAV\Connector\Sabre\File; use OCA\DAV\Connector\Sabre\File;
use OCA\DAV\Connector\Sabre\FilesPlugin; use OCA\DAV\Connector\Sabre\FilesPlugin;
use OCA\DAV\Connector\Sabre\Node; use OCA\DAV\Connector\Sabre\Node;
@ -319,7 +320,7 @@ class FilesPluginTest extends TestCase {
} }
public function testGetPropertiesForRootDirectory() { public function testGetPropertiesForRootDirectory() {
/** @var \OCA\DAV\Connector\Sabre\Directory | \PHPUnit_Framework_MockObject_MockObject $node */ /** @var \OCA\DAV\Connector\Sabre\Directory|\PHPUnit_Framework_MockObject_MockObject $node */
$node = $this->getMockBuilder(Directory::class) $node = $this->getMockBuilder(Directory::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();

View File

@ -251,7 +251,7 @@ class SystemTagNodeTest extends \Test\TestCase {
->method('deleteTags') ->method('deleteTags')
->with('1'); ->with('1');
if (!$isAdmin) { if (!$isAdmin) {
$this->setExpectedException(Forbidden::class); $this->expectException(Forbidden::class);
} }
$this->getTagNode($isAdmin, $tag)->delete(); $this->getTagNode($isAdmin, $tag)->delete();
} }
@ -282,7 +282,7 @@ class SystemTagNodeTest extends \Test\TestCase {
$this->tagManager->expects($this->never()) $this->tagManager->expects($this->never())
->method('deleteTags'); ->method('deleteTags');
$this->setExpectedException($expectedException); $this->expectException($expectedException);
$this->getTagNode(false, $tag)->delete(); $this->getTagNode(false, $tag)->delete();
} }

View File

@ -34,6 +34,7 @@ use OCP\Files\IAppData;
use OCP\Files\IRootFolder; use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\IConfig; use OCP\IConfig;
use PHPUnit\Framework\Error\Warning;
use Test\TestCase; use Test\TestCase;
class IconBuilderTest extends TestCase { class IconBuilderTest extends TestCase {
@ -172,11 +173,9 @@ class IconBuilderTest extends TestCase {
// cloud be something like $expectedIcon->compareImages($icon, Imagick::METRIC_MEANABSOLUTEERROR)[1]) // cloud be something like $expectedIcon->compareImages($icon, Imagick::METRIC_MEANABSOLUTEERROR)[1])
} }
/**
* @expectedException \PHPUnit_Framework_Error_Warning
*/
public function testGetFaviconNotFound() { public function testGetFaviconNotFound() {
$this->checkImagick(); $this->checkImagick();
$this->expectException(Warning::class);
$util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock(); $util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock();
$iconBuilder = new IconBuilder($this->themingDefaults, $util); $iconBuilder = new IconBuilder($this->themingDefaults, $util);
$this->themingDefaults->expects($this->once()) $this->themingDefaults->expects($this->once())
@ -188,11 +187,9 @@ class IconBuilderTest extends TestCase {
$this->assertFalse($iconBuilder->getFavicon('noapp')); $this->assertFalse($iconBuilder->getFavicon('noapp'));
} }
/**
* @expectedException \PHPUnit_Framework_Error_Warning
*/
public function testGetTouchIconNotFound() { public function testGetTouchIconNotFound() {
$this->checkImagick(); $this->checkImagick();
$this->expectException(Warning::class);
$util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock(); $util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock();
$iconBuilder = new IconBuilder($this->themingDefaults, $util); $iconBuilder = new IconBuilder($this->themingDefaults, $util);
$util->expects($this->once()) $util->expects($this->once())
@ -201,11 +198,9 @@ class IconBuilderTest extends TestCase {
$this->assertFalse($iconBuilder->getTouchIcon('noapp')); $this->assertFalse($iconBuilder->getTouchIcon('noapp'));
} }
/**
* @expectedException \PHPUnit_Framework_Error_Warning
*/
public function testColorSvgNotFound() { public function testColorSvgNotFound() {
$this->checkImagick(); $this->checkImagick();
$this->expectException(Warning::class);
$util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock(); $util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock();
$iconBuilder = new IconBuilder($this->themingDefaults, $util); $iconBuilder = new IconBuilder($this->themingDefaults, $util);
$util->expects($this->once()) $util->expects($this->once())

View File

@ -62,7 +62,7 @@ class ProviderTest extends TestCase {
$event->expects($this->once()) $event->expects($this->once())
->method('getApp') ->method('getApp')
->willReturn('comments'); ->willReturn('comments');
$this->setExpectedException(InvalidArgumentException::class); $this->expectException(InvalidArgumentException::class);
$this->provider->parse($lang, $event); $this->provider->parse($lang, $event);
} }

View File

@ -62,7 +62,7 @@ class SecurityProviderTest extends TestCase {
$event->expects($this->once()) $event->expects($this->once())
->method('getType') ->method('getType')
->willReturn('comments'); ->willReturn('comments');
$this->setExpectedException(InvalidArgumentException::class); $this->expectException(InvalidArgumentException::class);
$this->provider->parse($lang, $event); $this->provider->parse($lang, $event);
} }

View File

@ -46,7 +46,7 @@ class TestEntity extends Entity {
protected $preName; protected $preName;
public function __construct($name=null){ public function __construct($name=null){
$this->addType('testId', 'integer'); $this->addType('testId', 'integer');
$this->name = $name; $this->name = $name;
} }
}; };
@ -119,23 +119,26 @@ class EntityTest extends \Test\TestCase {
} }
/**
* @expectedException \BadFunctionCallException
*/
public function testCallShouldOnlyWorkForGetterSetter(){ public function testCallShouldOnlyWorkForGetterSetter(){
$this->setExpectedException('\BadFunctionCallException');
$this->entity->something(); $this->entity->something();
} }
/**
* @expectedException \BadFunctionCallException
*/
public function testGetterShouldFailIfAttributeNotDefined(){ public function testGetterShouldFailIfAttributeNotDefined(){
$this->setExpectedException('\BadFunctionCallException');
$this->entity->getTest(); $this->entity->getTest();
} }
/**
* @expectedException \BadFunctionCallException
*/
public function testSetterShouldFailIfAttributeNotDefined(){ public function testSetterShouldFailIfAttributeNotDefined(){
$this->setExpectedException('\BadFunctionCallException');
$this->entity->setTest(); $this->entity->setTest();
} }

View File

@ -24,6 +24,8 @@
namespace Test\AppFramework\Db; namespace Test\AppFramework\Db;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use \OCP\IDBConnection; use \OCP\IDBConnection;
use \OCP\AppFramework\Db\Entity; use \OCP\AppFramework\Db\Entity;
use \OCP\AppFramework\Db\Mapper; use \OCP\AppFramework\Db\Mapper;
@ -95,8 +97,7 @@ class MapperTest extends MapperTestUtility {
$params = array('jo'); $params = array('jo');
$rows = array(); $rows = array();
$this->setMapperResult($sql, $params, $rows); $this->setMapperResult($sql, $params, $rows);
$this->setExpectedException( $this->expectException(DoesNotExistException::class);
'\OCP\AppFramework\Db\DoesNotExistException');
$this->mapper->find($sql, $params); $this->mapper->find($sql, $params);
} }
@ -105,8 +106,7 @@ class MapperTest extends MapperTestUtility {
$params = array('jo'); $params = array('jo');
$rows = array(); $rows = array();
$this->setMapperResult($sql, $params, $rows, null, null, true); $this->setMapperResult($sql, $params, $rows, null, null, true);
$this->setExpectedException( $this->expectException(DoesNotExistException::class);
'\OCP\AppFramework\Db\DoesNotExistException');
$this->mapper->findOneEntity($sql, $params); $this->mapper->findOneEntity($sql, $params);
} }
@ -117,8 +117,7 @@ class MapperTest extends MapperTestUtility {
array('jo'), array('ho') array('jo'), array('ho')
); );
$this->setMapperResult($sql, $params, $rows, null, null, true); $this->setMapperResult($sql, $params, $rows, null, null, true);
$this->setExpectedException( $this->expectException(MultipleObjectsReturnedException::class);
'\OCP\AppFramework\Db\MultipleObjectsReturnedException');
$this->mapper->find($sql, $params); $this->mapper->find($sql, $params);
} }
@ -129,8 +128,7 @@ class MapperTest extends MapperTestUtility {
array('jo'), array('ho') array('jo'), array('ho')
); );
$this->setMapperResult($sql, $params, $rows, null, null, true); $this->setMapperResult($sql, $params, $rows, null, null, true);
$this->setExpectedException( $this->expectException(MultipleObjectsReturnedException::class);
'\OCP\AppFramework\Db\MultipleObjectsReturnedException');
$this->mapper->findOneEntity($sql, $params); $this->mapper->findOneEntity($sql, $params);
} }
@ -223,7 +221,7 @@ class MapperTest extends MapperTestUtility {
$entity->setPreName($params[0]); $entity->setPreName($params[0]);
$entity->setEmail($params[1]); $entity->setEmail($params[1]);
$this->setExpectedException('InvalidArgumentException'); $this->expectException(\InvalidArgumentException::class);
$this->mapper->update($entity); $this->mapper->update($entity);
} }

View File

@ -267,7 +267,7 @@ class DispatcherTest extends \Test\TestCase {
$responseHeaders = array('hell' => 'yeah'); $responseHeaders = array('hell' => 'yeah');
$this->setMiddlewareExpectations($out, $httpHeaders, $responseHeaders, true, false); $this->setMiddlewareExpectations($out, $httpHeaders, $responseHeaders, true, false);
$this->setExpectedException('\Exception'); $this->expectException(\Exception::class);
$response = $this->dispatcher->dispatch($this->controller, $response = $this->dispatcher->dispatch($this->controller,
$this->controllerMethod); $this->controllerMethod);

View File

@ -177,7 +177,7 @@ class MiddlewareDispatcherTest extends \Test\TestCase {
$this->dispatcher->registerMiddleware($m1); $this->dispatcher->registerMiddleware($m1);
$this->dispatcher->registerMiddleware($m2); $this->dispatcher->registerMiddleware($m2);
$this->setExpectedException('\Exception'); $this->expectException(\Exception::class);
$this->dispatcher->beforeController($this->controller, $this->method); $this->dispatcher->beforeController($this->controller, $this->method);
$this->dispatcher->afterException($this->controller, $this->method, $this->exception); $this->dispatcher->afterException($this->controller, $this->method, $this->exception);
} }
@ -206,7 +206,7 @@ class MiddlewareDispatcherTest extends \Test\TestCase {
public function testAfterExceptionCorrectArguments(){ public function testAfterExceptionCorrectArguments(){
$m1 = $this->getMiddleware(); $m1 = $this->getMiddleware();
$this->setExpectedException('\Exception'); $this->expectException(\Exception::class);
$this->dispatcher->beforeController($this->controller, $this->method); $this->dispatcher->beforeController($this->controller, $this->method);
$this->dispatcher->afterException($this->controller, $this->method, $this->exception); $this->dispatcher->afterException($this->controller, $this->method, $this->exception);
@ -253,7 +253,7 @@ class MiddlewareDispatcherTest extends \Test\TestCase {
$m1 = $this->getMiddleware(); $m1 = $this->getMiddleware();
$m2 = $this->getMiddleware(); $m2 = $this->getMiddleware();
$this->setExpectedException('\Exception'); $this->expectException(\Exception::class);
$this->dispatcher->beforeController($this->controller, $this->method); $this->dispatcher->beforeController($this->controller, $this->method);
$this->dispatcher->afterException($this->controller, $this->method, $this->exception); $this->dispatcher->afterException($this->controller, $this->method, $this->exception);

View File

@ -75,8 +75,8 @@ class MiddlewareTest extends \Test\TestCase {
public function testAfterExceptionRaiseAgainWhenUnhandled() { public function testAfterExceptionRaiseAgainWhenUnhandled() {
$this->setExpectedException('Exception'); $this->expectException(\Exception::class);
$afterEx = $this->middleware->afterException($this->controller, null, $this->exception); $this->middleware->afterException($this->controller, null, $this->exception);
} }

View File

@ -263,7 +263,7 @@ class SecurityMiddlewareTest extends \Test\TestCase {
$sec = $this->getMiddleware($isLoggedIn, $isAdminUser); $sec = $this->getMiddleware($isLoggedIn, $isAdminUser);
if($shouldFail) { if($shouldFail) {
$this->setExpectedException('\OC\AppFramework\Middleware\Security\Exceptions\SecurityException'); $this->expectException(SecurityException::class);
} else { } else {
$this->assertTrue(true); $this->assertTrue(true);
} }
@ -454,7 +454,7 @@ class SecurityMiddlewareTest extends \Test\TestCase {
public function testAfterExceptionNotCaughtThrowsItAgain(){ public function testAfterExceptionNotCaughtThrowsItAgain(){
$ex = new \Exception(); $ex = new \Exception();
$this->setExpectedException('\Exception'); $this->expectException(\Exception::class);
$this->middleware->afterException($this->controller, 'test', $ex); $this->middleware->afterException($this->controller, 'test', $ex);
} }

View File

@ -34,6 +34,7 @@ use OCP\UserInterface;
use Symfony\Component\Console\Formatter\OutputFormatterInterface; use Symfony\Component\Console\Formatter\OutputFormatterInterface;
use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Test\TestCase; use Test\TestCase;

View File

@ -719,9 +719,7 @@ class EncryptionTest extends Storage {
} }
public function testCopyBetweenStorageMinimumEncryptedVersion() { public function testCopyBetweenStorageMinimumEncryptedVersion() {
$storage2 = $this->getMockBuilder(Storage::class) $storage2 = $this->createMock(\OC\Files\Storage\Storage::class);
->disableOriginalConstructor()
->getMock();
$sourceInternalPath = $targetInternalPath = 'file.txt'; $sourceInternalPath = $targetInternalPath = 'file.txt';
$preserveMtime = $isRename = false; $preserveMtime = $isRename = false;
@ -768,9 +766,7 @@ class EncryptionTest extends Storage {
* @param bool $expectedEncrypted * @param bool $expectedEncrypted
*/ */
public function testCopyBetweenStorage($encryptionEnabled, $mountPointEncryptionEnabled, $expectedEncrypted) { public function testCopyBetweenStorage($encryptionEnabled, $mountPointEncryptionEnabled, $expectedEncrypted) {
$storage2 = $this->getMockBuilder(Storage::class) $storage2 = $this->createMock(\OC\Files\Storage\Storage::class);
->disableOriginalConstructor()
->getMock();
$sourceInternalPath = $targetInternalPath = 'file.txt'; $sourceInternalPath = $targetInternalPath = 'file.txt';
$preserveMtime = $isRename = false; $preserveMtime = $isRename = false;
@ -830,13 +826,9 @@ class EncryptionTest extends Storage {
*/ */
public function testCopyBetweenStorageVersions($sourceInternalPath, $targetInternalPath, $copyResult, $encrypted) { public function testCopyBetweenStorageVersions($sourceInternalPath, $targetInternalPath, $copyResult, $encrypted) {
$sourceStorage = $this->getMockBuilder(Storage::class) $sourceStorage = $this->createMock(\OC\Files\Storage\Storage::class);
->disableOriginalConstructor()
->getMock();
$targetStorage = $this->getMockBuilder(Storage::class) $targetStorage = $this->createMock(\OC\Files\Storage\Storage::class);
->disableOriginalConstructor()
->getMock();
$cache = $this->getMockBuilder('\OC\Files\Cache\Cache') $cache = $this->getMockBuilder('\OC\Files\Cache\Cache')
->disableOriginalConstructor()->getMock(); ->disableOriginalConstructor()->getMock();

View File

@ -392,7 +392,7 @@ class FactoryTest extends TestCase {
->willReturn($header); ->willReturn($header);
if ($expected instanceof LanguageNotFoundException) { if ($expected instanceof LanguageNotFoundException) {
$this->setExpectedException(LanguageNotFoundException::class); $this->expectException(LanguageNotFoundException::class);
self::invokePrivate($factory, 'getLanguageFromRequest', [$app]); self::invokePrivate($factory, 'getLanguageFromRequest', [$app]);
} else { } else {
$this->assertSame($expected, self::invokePrivate($factory, 'getLanguageFromRequest', [$app]), 'Asserting returned language'); $this->assertSame($expected, self::invokePrivate($factory, 'getLanguageFromRequest', [$app]), 'Asserting returned language');

View File

@ -466,7 +466,7 @@ class NotificationTest extends TestCase {
$this->assertSame($this->notification, $this->notification->addAction($action)); $this->assertSame($this->notification, $this->notification->addAction($action));
$this->setExpectedException('\InvalidArgumentException'); $this->expectException(\InvalidArgumentException::class);
$this->notification->addAction($action); $this->notification->addAction($action);
} }
@ -512,7 +512,7 @@ class NotificationTest extends TestCase {
$this->assertSame($this->notification, $this->notification->addParsedAction($action)); $this->assertSame($this->notification, $this->notification->addParsedAction($action));
$this->setExpectedException('\InvalidArgumentException'); $this->expectException(\InvalidArgumentException::class);
$this->notification->addParsedAction($action); $this->notification->addParsedAction($action);
} }

View File

@ -24,6 +24,7 @@
namespace Test\Template; namespace Test\Template;
use OC\Files\AppData\Factory; use OC\Files\AppData\Factory;
use OCP\Files\IAppData;
use OCP\ILogger; use OCP\ILogger;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\IConfig; use OCP\IConfig;
@ -37,7 +38,7 @@ class CSSResourceLocatorTest extends \Test\TestCase {
protected $appData; protected $appData;
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */ /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
protected $urlGenerator; protected $urlGenerator;
/** @var SystemConfig|\PHPUnit_Framework_MockObject_MockObject */ /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
protected $config; protected $config;
/** @var ThemingDefaults|\PHPUnit_Framework_MockObject_MockObject */ /** @var ThemingDefaults|\PHPUnit_Framework_MockObject_MockObject */
protected $themingDefaults; protected $themingDefaults;

View File

@ -329,7 +329,7 @@ class ManagerTest extends TestCase {
$manager = new \OC\User\Manager($this->config); $manager = new \OC\User\Manager($this->config);
$manager->registerBackend($backend); $manager->registerBackend($backend);
$this->setExpectedException(\InvalidArgumentException::class, $exception); $this->expectException(\InvalidArgumentException::class, $exception);
$manager->createUser($uid, $password); $manager->createUser($uid, $password);
} }