namespacing: \Shaarli\Feed\{Cache,CachedPage,FeedBuilder}

Signed-off-by: VirtualTam <virtualtam@flibidi.net>
This commit is contained in:
VirtualTam 2018-12-03 00:08:04 +01:00
parent f3d2f25794
commit dfc650aa23
10 changed files with 54 additions and 44 deletions

View file

@ -3,9 +3,7 @@
* Link datastore tests
*/
use Shaarli\Exceptions\IOException;
require_once 'application/Cache.php';
require_once 'application/feed/Cache.php';
require_once 'application/FileUtils.php';
require_once 'application/LinkDB.php';
require_once 'application/Utils.php';

View file

@ -2,16 +2,17 @@
/**
* Cache tests
*/
namespace Shaarli\Feed;
// required to access $_SESSION array
session_start();
require_once 'application/Cache.php';
require_once 'application/feed/Cache.php';
/**
* Unitary tests for cached pages
*/
class CacheTest extends PHPUnit_Framework_TestCase
class CacheTest extends \PHPUnit\Framework\TestCase
{
// test cache directory
protected static $testCacheDir = 'sandbox/dummycache';
@ -25,16 +26,16 @@ class CacheTest extends PHPUnit_Framework_TestCase
*/
public function setUp()
{
if (! is_dir(self::$testCacheDir)) {
if (!is_dir(self::$testCacheDir)) {
mkdir(self::$testCacheDir);
} else {
array_map('unlink', glob(self::$testCacheDir.'/*'));
array_map('unlink', glob(self::$testCacheDir . '/*'));
}
foreach (self::$pages as $page) {
file_put_contents(self::$testCacheDir.'/'.$page.'.cache', $page);
file_put_contents(self::$testCacheDir . '/' . $page . '.cache', $page);
}
file_put_contents(self::$testCacheDir.'/intru.der', 'ShouldNotBeThere');
file_put_contents(self::$testCacheDir . '/intru.der', 'ShouldNotBeThere');
}
/**
@ -42,7 +43,7 @@ class CacheTest extends PHPUnit_Framework_TestCase
*/
public function tearDown()
{
array_map('unlink', glob(self::$testCacheDir.'/*'));
array_map('unlink', glob(self::$testCacheDir . '/*'));
rmdir(self::$testCacheDir);
}
@ -53,10 +54,10 @@ class CacheTest extends PHPUnit_Framework_TestCase
{
purgeCachedPages(self::$testCacheDir);
foreach (self::$pages as $page) {
$this->assertFileNotExists(self::$testCacheDir.'/'.$page.'.cache');
$this->assertFileNotExists(self::$testCacheDir . '/' . $page . '.cache');
}
$this->assertFileExists(self::$testCacheDir.'/intru.der');
$this->assertFileExists(self::$testCacheDir . '/intru.der');
}
/**
@ -68,7 +69,7 @@ class CacheTest extends PHPUnit_Framework_TestCase
ini_set('error_log', '/dev/null');
$this->assertEquals(
'Cannot purge sandbox/dummycache_missing: no directory',
purgeCachedPages(self::$testCacheDir.'_missing')
purgeCachedPages(self::$testCacheDir . '_missing')
);
ini_set('error_log', $oldlog);
}
@ -83,7 +84,7 @@ class CacheTest extends PHPUnit_Framework_TestCase
invalidateCaches(self::$testCacheDir);
foreach (self::$pages as $page) {
$this->assertFileNotExists(self::$testCacheDir.'/'.$page.'.cache');
$this->assertFileNotExists(self::$testCacheDir . '/' . $page . '.cache');
}
$this->assertArrayNotHasKey('tags', $_SESSION);

View file

@ -2,13 +2,12 @@
/**
* PageCache tests
*/
require_once 'application/CachedPage.php';
namespace Shaarli\Feed;
/**
* Unitary tests for cached pages
*/
class CachedPageTest extends PHPUnit_Framework_TestCase
class CachedPageTest extends \PHPUnit\Framework\TestCase
{
// test cache directory
protected static $testCacheDir = 'sandbox/pagecache';
@ -20,10 +19,10 @@ class CachedPageTest extends PHPUnit_Framework_TestCase
*/
public static function setUpBeforeClass()
{
if (! is_dir(self::$testCacheDir)) {
if (!is_dir(self::$testCacheDir)) {
mkdir(self::$testCacheDir);
}
self::$filename = self::$testCacheDir.'/'.sha1(self::$url).'.cache';
self::$filename = self::$testCacheDir . '/' . sha1(self::$url) . '.cache';
}
/**

View file

@ -1,6 +1,11 @@
<?php
require_once 'application/FeedBuilder.php';
namespace Shaarli\Feed;
use DateTime;
use LinkDB;
use ReferenceLinkDB;
require_once 'application/LinkDB.php';
/**
@ -8,7 +13,7 @@ require_once 'application/LinkDB.php';
*
* Unit tests for FeedBuilder.
*/
class FeedBuilderTest extends PHPUnit_Framework_TestCase
class FeedBuilderTest extends \PHPUnit\Framework\TestCase
{
/**
* @var string locale Basque (Spain).
@ -90,7 +95,7 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
$this->assertEquals('http://host.tld/?WDWyig', $link['url']);
$this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']);
$pub = DateTime::createFromFormat(DateTime::RSS, $link['pub_iso_date']);
$up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']);
$up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']);
$this->assertEquals($pub, $up);
$this->assertContains('Stallman has a beard', $link['description']);
$this->assertContains('Permalink', $link['description']);