Files
FreshRSS/tests/app/Models/CategoryTest.php
Alexandre Alapetite b1d24fbdb7 PHPStan 2.0 (#7131)
* PHPStan 2.0
fix https://github.com/FreshRSS/FreshRSS/issues/6989
https://github.com/phpstan/phpstan/releases/tag/2.0.0
https://github.com/phpstan/phpstan/blob/2.0.x/UPGRADING.md

* More

* More

* Done

* fix i18n CLI

* Restore a PHPStan Next test
For work towards PHPStan Level 10

* 4 more on Level 10

* fix getTagsForEntry

* API at Level 10

* More Level 10

* Finish Minz at Level 10

* Finish CLI at Level 10

* Finish Controllers at Level 10

* More Level 10

* More

* Pass bleedingEdge

* Clean PHPStan options and add TODOs

* Level 10 for main config

* More

* Consitency array vs. list

* Sanitize themes get_infos

* Simplify TagDAO->getTagsForEntries()

* Finish reportAnyTypeWideningInVarTag

* Prepare checkBenevolentUnionTypes and checkImplicitMixed

* Fixes

* Refix

* Another fix

* Casing of __METHOD__ constant
2024-12-27 12:12:49 +01:00

91 lines
2.9 KiB
PHP

<?php
declare(strict_types=1);
use PHPUnit\Framework\Attributes\DataProvider;
class CategoryTest extends PHPUnit\Framework\TestCase {
public static function test__construct_whenNoParameters_createsObjectWithDefaultValues(): void {
$category = new FreshRSS_Category();
self::assertSame(0, $category->id());
self::assertSame('', $category->name());
}
#[DataProvider('provideValidNames')]
public static function test_name_whenValidValue_storesModifiedValue(string $input, string $expected): void {
$category = new FreshRSS_Category($input);
self::assertSame($expected, $category->name());
}
/** @return list<array{string,string}> */
public static function provideValidNames(): array {
return [
['', ''],
['this string does not need trimming', 'this string does not need trimming'],
[' this string needs trimming on left', 'this string needs trimming on left'],
['this string needs trimming on right ', 'this string needs trimming on right'],
[' this string needs trimming on both ends ', 'this string needs trimming on both ends'],
[str_repeat('X', 512), str_repeat('X', FreshRSS_DatabaseDAO::LENGTH_INDEX_UNICODE)], // max length
];
}
public function test_feedOrdering(): void {
$feed_1 = $this->getMockBuilder(FreshRSS_Feed::class)
->disableOriginalConstructor()
->getMock();
$feed_1->expects(self::any())
->method('name')
->willReturn('AAA');
$feed_2 = $this->getMockBuilder(FreshRSS_Feed::class)
->disableOriginalConstructor()
->getMock();
$feed_2->expects(self::any())
->method('name')
->willReturn('ZZZ');
$feed_3 = $this->getMockBuilder(FreshRSS_Feed::class)
->disableOriginalConstructor()
->getMock();
$feed_3->expects(self::any())
->method('name')
->willReturn('lll');
$category = new FreshRSS_Category('test', 0, [
$feed_1,
$feed_2,
$feed_3,
]);
$feeds = $category->feeds();
self::assertCount(3, $feeds);
$feed = reset($feeds) ?: FreshRSS_Feed::default();
self::assertSame('AAA', $feed->name());
$feed = next($feeds) ?: FreshRSS_Feed::default();
self::assertSame('lll', $feed->name());
$feed = next($feeds) ?: FreshRSS_Feed::default();
self::assertSame('ZZZ', $feed->name());
/** @var FreshRSS_Feed&PHPUnit\Framework\MockObject\MockObject */
$feed_4 = $this->getMockBuilder(FreshRSS_Feed::class)
->disableOriginalConstructor()
->getMock();
$feed_4->expects(self::any())
->method('name')
->willReturn('BBB');
$category->addFeed($feed_4);
$feeds = $category->feeds();
self::assertCount(4, $feeds);
$feed = reset($feeds) ?: FreshRSS_Feed::default();
self::assertSame('AAA', $feed->name());
$feed = next($feeds) ?: FreshRSS_Feed::default();
self::assertSame('BBB', $feed->name());
$feed = next($feeds) ?: FreshRSS_Feed::default();
self::assertSame('lll', $feed->name());
$feed = next($feeds) ?: FreshRSS_Feed::default();
self::assertSame('ZZZ', $feed->name());
}
}