Fix nc 21 phpunit issue

This commit is contained in:
Sean Molenaar 2021-01-08 22:45:43 +01:00 committed by Sean Molenaar
parent 7cc22415a0
commit f7b43501af
7 changed files with 62 additions and 157 deletions

View File

@ -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)

View File

@ -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>

View File

@ -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);
}
}

View File

@ -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())

View File

@ -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();
}
}

View File

@ -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 */

View File

@ -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);
}
}