summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Molenaar <sean@seanmolenaar.eu>2021-01-08 22:45:43 +0100
committerSean Molenaar <SMillerDev@users.noreply.github.com>2021-01-12 13:29:08 +0100
commitf7b43501afa339dd11abca62c5e8eaa9a2c67d4e (patch)
tree4a2a7dd046e49a9225b54016c118f2103b05f837
parent7cc22415a03889d5de3b90018bdc38ab2995e4f3 (diff)
Fix nc 21 phpunit issue
-rw-r--r--AUTHORS.md1
-rw-r--r--phpunit.xml48
-rw-r--r--tests/Unit/Command/ExploreGeneratorTest.php23
-rw-r--r--tests/Unit/Db/FeedMapperTest.php11
-rw-r--r--tests/Unit/Db/MapperTestUtility.php8
-rw-r--r--tests/Unit/Db/NewsMapperTest.php17
-rw-r--r--tests/Unit/Migration/MigrateStatusFlagsTest.php111
7 files changed, 62 insertions, 157 deletions
diff --git a/AUTHORS.md b/AUTHORS.md
index d81d5e579..522e46238 100644
--- a/AUTHORS.md
+++ b/AUTHORS.md
@@ -41,6 +41,7 @@
* [Qingping Hou](mailto:dave2008713@gmail.com)
* [Roman](mailto:reverse@jamm.me)
* [b_b](mailto:bruno@eliaz.fr)
+* [heyarne](mailto:arne@schlueter.is)
* [Andreas Fischer](mailto:bantu@owncloud.com)
* [David Guillot](mailto:david@guillot.me)
* [Gioele Falcetti](mailto:thegio.f@gmail.com)
diff --git a/phpunit.xml b/phpunit.xml
index 9c52c7234..6a2f2d01b 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -1,25 +1,27 @@
<?xml version="1.0"?>
-<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
- <coverage processUncoveredFiles="true">
- <include>
- <directory suffix=".php">./lib/</directory>
- </include>
- <exclude>
- <file>./lib/AppInfo/Application.php</file>
- <file>./lib/Controller/JSONHttpErrorTrait.php</file>
- <file>./lib/**Exception.php</file>
- </exclude>
- <report>
- <clover outputFile="./build/coverage.xml"/>
- <html outputDirectory="./build/report" lowUpperBound="35" highLowerBound="70"/>
- </report>
- </coverage>
- <testsuites>
- <testsuite name="unit">
- <directory>./tests/Unit</directory>
- </testsuite>
- </testsuites>
- <logging>
- <junit outputFile="./build/junit.xml"/>
- </logging>
+<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true"
+ xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd">
+ <testsuites>
+ <testsuite name="unit">
+ <directory>./tests/Unit</directory>
+ </testsuite>
+ </testsuites>
+ <coverage processUncoveredFiles="true">
+ <include>
+ <directory suffix=".php">./lib/</directory>
+ </include>
+ <exclude>
+ <file>./lib/AppInfo/Application.php</file>
+ <file>./lib/Controller/JSONHttpErrorTrait.php</file>
+ <file>./lib/**Exception.php</file>
+ </exclude>
+ <report>
+ <clover outputFile="./build/coverage.xml"/>
+ <html outputDirectory="./build/report" lowUpperBound="35" highLowerBound="70"/>
+ </report>
+ </coverage>
+
+ <logging>
+ <junit outputFile="./build/junit.xml"/>
+ </logging>
</phpunit>
diff --git a/tests/Unit/Command/ExploreGeneratorTest.php b/tests/Unit/Command/ExploreGeneratorTest.php
index ec04c4241..4482b91f3 100644
--- a/tests/Unit/Command/ExploreGeneratorTest.php
+++ b/tests/Unit/Command/ExploreGeneratorTest.php
@@ -26,22 +26,24 @@ use Favicon\Favicon;
use FeedIo\Reader\Result;
use OCA\News\Command\ExploreGenerator;
+use PHPUnit\Framework\MockObject\MockObject;
+use PHPUnit\Framework\TestCase;
+use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
-use Test\TestCase;
class ExploreGeneratorTest extends TestCase
{
- /** @var \PHPUnit_Framework_MockObject_MockObject */
+ /** @var MockObject */
protected $favicon;
- /** @var \PHPUnit_Framework_MockObject_MockObject */
+ /** @var MockObject */
protected $feedio;
- /** @var \PHPUnit_Framework_MockObject_MockObject */
+ /** @var MockObject */
protected $consoleInput;
- /** @var \PHPUnit_Framework_MockObject_MockObject */
+ /** @var MockObject */
protected $consoleOutput;
- /** @var \Symfony\Component\Console\Command\Command */
+ /** @var Command */
protected $command;
protected function setUp(): void
@@ -110,7 +112,8 @@ class ExploreGeneratorTest extends TestCase
->method('writeln')
->with($this->stringContains('https:\/\/feed.io\/rss.xml'));
- self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
+ $result = $this->command->run($this->consoleInput, $this->consoleOutput);
+ $this->assertSame(0, $result);
}
/**
@@ -141,7 +144,8 @@ class ExploreGeneratorTest extends TestCase
->method('writeln')
->withConsecutive(['<error>Failed to fetch feed info:</error>'], ['Failure']);
- self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
+ $result = $this->command->run($this->consoleInput, $this->consoleOutput);
+ $this->assertSame(1, $result);
}
/**
@@ -192,6 +196,7 @@ class ExploreGeneratorTest extends TestCase
->method('writeln')
->with($this->stringContains('200'));
- self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
+ $result = $this->command->run($this->consoleInput, $this->consoleOutput);
+ $this->assertSame(0, $result);
}
}
diff --git a/tests/Unit/Db/FeedMapperTest.php b/tests/Unit/Db/FeedMapperTest.php
index a6a4be866..c14b8995f 100644
--- a/tests/Unit/Db/FeedMapperTest.php
+++ b/tests/Unit/Db/FeedMapperTest.php
@@ -15,17 +15,17 @@ namespace OCA\News\Tests\Unit\Db;
use OCA\News\Db\Feed;
use OCA\News\Db\FeedMapperV2;
-use OCA\News\Db\Folder;
use OCA\News\Utility\Time;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\DB\QueryBuilder\IFunctionBuilder;
+use OCP\DB\QueryBuilder\IQueryFunction;
class FeedMapperTest extends MapperTestUtility
{
/** @var FeedMapperV2 */
private $class;
- /** @var Feeds[] */
+ /** @var Feed[] */
private $feeds;
/**
@@ -68,10 +68,13 @@ class FeedMapperTest extends MapperTestUtility
$funcbuilder = $this->getMockBuilder(IFunctionBuilder::class)
->getMock();
+ $func = $this->getMockBuilder(IQueryFunction::class)
+ ->getMock();
+
$funcbuilder->expects($this->once())
->method('count')
->with('items.id', 'unreadCount')
- ->will($this->returnValue('COUNT_FUNC'));
+ ->will($this->returnValue($func));
$this->builder->expects($this->once())
->method('func')
@@ -79,7 +82,7 @@ class FeedMapperTest extends MapperTestUtility
$this->builder->expects($this->once())
->method('select')
- ->with('feeds.*', 'COUNT_FUNC')
+ ->with('feeds.*', $func)
->will($this->returnSelf());
$this->builder->expects($this->once())
diff --git a/tests/Unit/Db/MapperTestUtility.php b/tests/Unit/Db/MapperTestUtility.php
index 725f0c3c0..3aa1d8aed 100644
--- a/tests/Unit/Db/MapperTestUtility.php
+++ b/tests/Unit/Db/MapperTestUtility.php
@@ -23,12 +23,11 @@
namespace OCA\News\Tests\Unit\Db;
-use Doctrine\DBAL\Driver\PDOStatement;
use Doctrine\DBAL\Driver\Statement;
-use OCA\News\Tests\Unit\Service\ServiceTest;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
+use PDOStatement;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
@@ -71,13 +70,14 @@ abstract class MapperTestUtility extends TestCase
->disableOriginalConstructor()
->getMock();
- $this->query = $this->getMockBuilder(\PDOStatement::class)
+ $this->query = $this->getMockBuilder(PDOStatement::class)
->getMock();
$this->builder = $this->getMockBuilder(IQueryBuilder::class)
->getMock();
$this->cursor = $this->getMockBuilder(Statement::class)
- ->getMock();
+ ->addMethods(['fetch', 'closeCursor'])
+ ->getMockForAbstractClass();
}
}
diff --git a/tests/Unit/Db/NewsMapperTest.php b/tests/Unit/Db/NewsMapperTest.php
index 5d75f740f..c7ce7342a 100644
--- a/tests/Unit/Db/NewsMapperTest.php
+++ b/tests/Unit/Db/NewsMapperTest.php
@@ -14,21 +14,26 @@
namespace OCA\News\Tests\Unit\Db;
use OCA\News\Db\Feed;
-use OCA\News\Db\FeedMapperV2;
-use OCA\News\Db\Folder;
use OCA\News\Db\NewsMapperV2;
use OCA\News\Utility\Time;
-use OCP\AppFramework\Db\DoesNotExistException;
-use OCP\AppFramework\Db\MultipleObjectsReturnedException;
-use OCP\DB\QueryBuilder\IFunctionBuilder;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
-use Test\TestCase;
+use PHPUnit\Framework\TestCase;
+/**
+ * Class TmpNewsMapper
+ *
+ * @package OCA\News\Tests\Unit\Db
+ */
abstract class TmpNewsMapper extends NewsMapperV2 {
const TABLE_NAME = 'NAME';
}
+/**
+ * Class NewsMapperTest
+ *
+ * @package OCA\News\Tests\Unit\Db
+ */
class NewsMapperTest extends TestCase
{
/** @var IDBConnection */
diff --git a/tests/Unit/Migration/MigrateStatusFlagsTest.php b/tests/Unit/Migration/MigrateStatusFlagsTest.php
deleted file mode 100644
index d71f1a54c..000000000
--- a/tests/Unit/Migration/MigrateStatusFlagsTest.php
+++ /dev/null
@@ -1,111 +0,0 @@
-<?php
-/**
- * Nextcloud - News
- *
- * This file is licensed under the Affero General Public License version 3 or
- * later. See the COPYING file.
- *
- * @author Daniel Opitz <dev@copynpaste.de>
- * @copyright Daniel Opitz 2017
- */
-
-namespace OCA\News\Tests\Unit\Migration;
-
-use Doctrine\DBAL\Driver\Statement;
-use OCA\News\Migration\MigrateStatusFlags;
-use OCP\IConfig;
-use OCP\IDBConnection;
-use OCP\Migration\IOutput;
-use Test\TestCase;
-
-class MigrateStatusFlagsTest extends TestCase
-{
-
- /**
- * @var IDBConnection|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $db;
- /**
- * @var IConfig|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $config;
- /**
- * @var IOutput|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $output;
-
- protected function setUp(): void
- {
- $this->db = $this->createMock(IDBConnection::class);
- $this->config = $this->createMock(IConfig::class);
- $this->output = $this->createMock(IOutput::class);
- }
-
- public function testRun()
- {
- $statement = $this->createMock(Statement::class);
- $statement->expects($this->exactly(1))
- ->method('execute')
- ->with()
- ->willReturn(true);
-
- $this->config->expects($this->exactly(1))
- ->method('getAppValue')
- ->with('news', 'installed_version', '0.0.0')
- ->willReturn('11.0.5');
-
- $sql = 'UPDATE `*PREFIX*news_items` '
- . 'SET `unread` = ((`status` & 2) = 2), '
- . '`starred` = ((`status` & 4) = 4)';
-
- $this->db->expects($this->exactly(1))
- ->method('prepare')
- ->with($sql)
- ->willReturn($statement);
-
- $migration = new MigrateStatusFlags($this->db, $this->config);
- $migration->run($this->output);
- }
-
- public function testRunException()
- {
- $this->expectException('\Exception');
- $this->expectExceptionMessage('Could not migrate status');
-
- $statement = $this->createMock(Statement::class);
- $statement->expects($this->exactly(1))
- ->method('execute')
- ->with()
- ->willReturn(false);
-
- $this->config->expects($this->exactly(1))
- ->method('getAppValue')
- ->with('news', 'installed_version', '0.0.0')
- ->willReturn('11.0.5');
-
- $sql = 'UPDATE `*PREFIX*news_items` '
- . 'SET `unread` = ((`status` & 2) = 2), '
- . '`starred` = ((`status` & 4) = 4)';
-
- $this->db->expects($this->exactly(1))
- ->method('prepare')
- ->with($sql)
- ->willReturn($statement);
-
- $migration = new MigrateStatusFlags($this->db, $this->config);
- $migration->run($this->output);
- }
-
- public function testRunNewerVersion()
- {
- $this->config->expects($this->exactly(1))
- ->method('getAppValue')
- ->with('news', 'installed_version', '0.0.0')
- ->willReturn('11.1.0');
- $this->db->expects($this->exactly(0))
- ->method('prepare');
-
- $migration = new MigrateStatusFlags($this->db, $this->config);
- $migration->run($this->output);
- }
-} \ No newline at end of file