diff --git a/.travis.yml b/.travis.yml index b05fe95..3929175 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,10 +4,9 @@ cache: directories: - $HOME/.composer/cache php: + - 7.3 - 7.2 - 7.1 - - 7.0 - - 5.6 install: - composer self-update - composer install --prefer-dist diff --git a/README.md b/README.md index 870ee7f..12b0b6d 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ PHP library which will retrieve a thumbnail for any given URL, if available. Mandatory: - - PHP 5.6 + - PHP 7.1 (`v2.0.0`+) - PHP 5.6 (`v1.x.x`) - PHP GD extension (Highly) Recommended: diff --git a/composer.json b/composer.json index ca906c7..5445536 100644 --- a/composer.json +++ b/composer.json @@ -10,11 +10,11 @@ } ], "require": { - "php": ">=5.6", + "php": ">=7.1", "phpunit/php-text-template": "^1.2" }, "require-dev": { - "phpunit/phpunit": "^5.0 || ^6.0 || ^7.0 || ^8.0", + "phpunit/phpunit": "^7.0 || ^8.0", "php-coveralls/php-coveralls": "^2.0", "squizlabs/php_codesniffer": "^3.0" }, diff --git a/tests/WebThumbnailer/Application/CacheManagerTest.php b/tests/WebThumbnailer/Application/CacheManagerTest.php index 6dfb20b..2eb3804 100644 --- a/tests/WebThumbnailer/Application/CacheManagerTest.php +++ b/tests/WebThumbnailer/Application/CacheManagerTest.php @@ -2,6 +2,7 @@ namespace WebThumbnailer\Application; +use PHPUnit\Framework\TestCase; use WebThumbnailer\Utils\FileUtils; /** @@ -11,7 +12,7 @@ * * @package WebThumbnailer\Application */ -class CacheManagerTest extends \PHPUnit_Framework_TestCase +class CacheManagerTest extends TestCase { /** * @var string $cache relative path. @@ -21,7 +22,7 @@ class CacheManagerTest extends \PHPUnit_Framework_TestCase /** * Load test config before running tests. */ - public function setUp() + public function setUp(): void { $resource = 'tests/WebThumbnailer/resources/'; ConfigManager::$configFiles = [$resource . 'settings-useful.json']; @@ -31,7 +32,7 @@ public function setUp() /** * Remove cache folder after every tests. */ - public function tearDown() + public function tearDown(): void { FileUtils::rmdir(ConfigManager::get('settings.path.cache')); } @@ -43,32 +44,29 @@ public function testGetCachePathValid() { $path = CacheManager::getCachePath(CacheManager::TYPE_THUMB); $this->assertTrue(is_dir($path)); - $this->assertContains(self::$cache . CacheManager::TYPE_THUMB .'/', $path); + $this->assertStringContainsString(self::$cache . CacheManager::TYPE_THUMB .'/', $path); $path = CacheManager::getCachePath(CacheManager::TYPE_FINDER); $this->assertTrue(is_dir($path)); - $this->assertContains(self::$cache . CacheManager::TYPE_FINDER .'/', $path); + $this->assertStringContainsString(self::$cache . CacheManager::TYPE_FINDER .'/', $path); } /** * Test getCachePath() with an invalid type. - * - * @expectedException \Exception - * @expectedExceptionMessageRegExp /Unknown cache type/ */ public function testGetCachePathInvalidType() { + $this->expectException(\Exception::class); + $this->expectExceptionMessageRegExp('/Unknown cache type/'); CacheManager::getCachePath('nope'); } /** * Test getCachePath() without cache folder. - * - * @expectedException \Exception - * @expectedExceptionMessageRegExp /Cache folders are not writable/ - * */ public function testGetCachePathNoFolder() { + $this->expectException(\Exception::class); + $this->expectExceptionMessageRegExp('/Cache folders are not writable/'); CacheManager::getCachePath(CacheManager::TYPE_THUMB, true); } @@ -85,9 +83,9 @@ public function testGetCacheFilePathValid() $cacheFile = CacheManager::getCacheFilePath($url, $domain, $type, $width, $height, false); $whateverDir = self::$cache . 'thumb/'. md5($domain) .'/'; $this->assertTrue(is_dir($whateverDir)); - $this->assertContains($whateverDir, $cacheFile); + $this->assertStringContainsString($whateverDir, $cacheFile); // sha1 sum + dimensions - $this->assertContains('0a35602901944a0c6d853da2a5364665c2bda069' . '51200' . '.jpg', $cacheFile); + $this->assertStringContainsString('0a35602901944a0c6d853da2a5364665c2bda069' . '51200' . '.jpg', $cacheFile); } /** diff --git a/tests/WebThumbnailer/Application/ConfigManagerTest.php b/tests/WebThumbnailer/Application/ConfigManagerTest.php index 4938d2b..6506e70 100644 --- a/tests/WebThumbnailer/Application/ConfigManagerTest.php +++ b/tests/WebThumbnailer/Application/ConfigManagerTest.php @@ -2,6 +2,7 @@ namespace WebThumbnailer\Application; +use PHPUnit\Framework\TestCase; use WebThumbnailer\Utils\DataUtils; use WebThumbnailer\Utils\FileUtils; @@ -12,12 +13,12 @@ * * @package WebThumbnailer\Application */ -class ConfigManagerTest extends \PHPUnit_Framework_TestCase +class ConfigManagerTest extends TestCase { /** * Before each test method. */ - public function setUp() + public function setUp(): void { ConfigManager::$configFiles = []; ConfigManager::reload(); diff --git a/tests/WebThumbnailer/Application/ThumbnailerTest.php b/tests/WebThumbnailer/Application/ThumbnailerTest.php index b898149..e588eb6 100644 --- a/tests/WebThumbnailer/Application/ThumbnailerTest.php +++ b/tests/WebThumbnailer/Application/ThumbnailerTest.php @@ -2,6 +2,8 @@ namespace WebThumbnailer\Application; +use PHPUnit\Framework\TestCase; +use WebThumbnailer\Exception\BadRulesException; use WebThumbnailer\Utils\FileUtils; use WebThumbnailer\Utils\SizeUtils; use WebThumbnailer\WebThumbnailer; @@ -13,7 +15,7 @@ * * @package WebThumbnailer\Application */ -class ThumbnailerTest extends \PHPUnit_Framework_TestCase +class ThumbnailerTest extends TestCase { /** * @var string Gravatar image link. @@ -25,7 +27,7 @@ class ThumbnailerTest extends \PHPUnit_Framework_TestCase */ public static $gravatarThumb = 'http://gravatar.com/avatar/69ae657aa40c6c777aa2f391a63f327f?s=320'; - public function setUp() + public function setUp(): void { FileUtils::rmdir(__DIR__ .'/../../../cache/finder'); FileUtils::rmdir(__DIR__ .'/../../../cache/thumb'); @@ -184,12 +186,11 @@ public function testDownloadSizedThumbnailWidth() /** * Try to create an instance of Thumbnailer with incompatible settings. - * - * @expectedException WebThumbnailer\Exception\BadRulesException - * @expectedExceptionMessageRegExp /Only one of these flags can be set between: DOWNLOAD HOTLINK HOTLINK_STRICT/ */ public function testDownloadBadConfigurationDownload() { + $this->expectException(BadRulesException::class); + $this->expectExceptionMessageRegExp('/Only one of these flags can be set between: DOWNLOAD HOTLINK HOTLINK_STRICT/'); $options = [ WebThumbnailer::DOWNLOAD, WebThumbnailer::HOTLINK_STRICT, diff --git a/tests/WebThumbnailer/Finder/DefaultFinderTest.php b/tests/WebThumbnailer/Finder/DefaultFinderTest.php index 7ae5acd..87bdf90 100644 --- a/tests/WebThumbnailer/Finder/DefaultFinderTest.php +++ b/tests/WebThumbnailer/Finder/DefaultFinderTest.php @@ -2,6 +2,7 @@ namespace WebThumbnailer\Finder; +use PHPUnit\Framework\TestCase; use WebThumbnailer\WebThumbnailer; /** @@ -9,7 +10,7 @@ * * @package WebThumbnailer\Finder */ -class DefaultFinderTest extends \PHPUnit_Framework_TestCase +class DefaultFinderTest extends TestCase { /** * PHP builtin local server URL. diff --git a/tests/WebThumbnailer/Finder/FinderFactoryTest.php b/tests/WebThumbnailer/Finder/FinderFactoryTest.php index 3c7f6bb..d1cecb4 100644 --- a/tests/WebThumbnailer/Finder/FinderFactoryTest.php +++ b/tests/WebThumbnailer/Finder/FinderFactoryTest.php @@ -2,12 +2,15 @@ namespace WebThumbnailer\Finder; +use PHPUnit\Framework\TestCase; +use WebThumbnailer\Exception\BadRulesException; + /** * Class FinderFactoryTest * * @package WebThumbnailer\Finder */ -class FinderFactoryTest extends \PHPUnit_Framework_TestCase +class FinderFactoryTest extends TestCase { /** * Test getFinder() with a supported domain. @@ -178,6 +181,7 @@ public function testGetThumbnailMetaGravatar() */ public function testCheckMetaFormatValid() { + $this->addToAssertionCount(1); $meta = [ 'finder' => 'foo', 'domains' => ['bar'] @@ -189,11 +193,10 @@ public function testCheckMetaFormatValid() /** * Test checkMetaFormat() with invalid info. - * - * @expectedException \WebThumbnailer\Exception\BadRulesException */ public function testCheckMetaFormatBadRules() { + $this->expectException(BadRulesException::class); $meta = array('finder' => 'test'); FinderFactory::checkMetaFormat($meta); } diff --git a/tests/WebThumbnailer/Finder/FlickRFinderTest.php b/tests/WebThumbnailer/Finder/FlickRFinderTest.php index e7e2158..ca25971 100644 --- a/tests/WebThumbnailer/Finder/FlickRFinderTest.php +++ b/tests/WebThumbnailer/Finder/FlickRFinderTest.php @@ -2,12 +2,14 @@ namespace WebThumbnailer\Finder; +use PHPUnit\Framework\TestCase; + /** * Class FlickRFinderTest * * @package WebThumbnailer\Finder */ -class FlickRFinderTest extends \PHPUnit_Framework_TestCase +class FlickRFinderTest extends TestCase { /** * @var array Finder rules. @@ -22,7 +24,7 @@ class FlickRFinderTest extends \PHPUnit_Framework_TestCase /** * Before every tests, reset rules and params. */ - public function setUp() + public function setUp(): void { self::$rules = [ 'image_regex' => ' '(.*?)', @@ -164,22 +166,20 @@ public function testGetName() /** * Test loading the finder with bad rules (`thumbnail_url`). - * - * @expectedException \WebThumbnailer\Exception\BadRulesException */ public function testQueryRegexFinderBadRulesThumbUrl() { + $this->expectException(BadRulesException::class); unset(self::$rules['thumbnail_url']); new QueryRegexFinder('domain.tld', '', self::$rules, null); } /** * Test loading the finder with bad rules (`image_regex`). - * - * @expectedException \WebThumbnailer\Exception\BadRulesException */ public function testQueryRegexFinderBadRulesImageRegex() { + $this->expectException(BadRulesException::class); unset(self::$rules['image_regex']); new QueryRegexFinder('domain.tld', '', self::$rules, null); } @@ -217,12 +217,12 @@ public function testQueryRegexNoEnoughMatch() /** * Use an unknown option in the URL. - * - * @expectedException \Exception - * @expectedExceptionMessage Unknown option "option" for the finder "Query Regex" */ public function testQueryRegexUnknownOption() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Unknown option "option" for the finder "Query Regex"'); + $url = __DIR__ . '/../resources/queryregex/one-thumb.html'; self::$rules['thumbnail_url'] = '${option}'; $finder = new QueryRegexFinder('domain.tld', $url, self::$rules, null); diff --git a/tests/WebThumbnailer/Finder/UrlRegexFinderTest.php b/tests/WebThumbnailer/Finder/UrlRegexFinderTest.php index 4bcd27a..944a3f6 100644 --- a/tests/WebThumbnailer/Finder/UrlRegexFinderTest.php +++ b/tests/WebThumbnailer/Finder/UrlRegexFinderTest.php @@ -2,6 +2,8 @@ namespace WebThumbnailer\Finder; +use PHPUnit\Framework\TestCase; +use WebThumbnailer\Exception\BadRulesException; use WebThumbnailer\Utils\DataUtils; use WebThumbnailer\Utils\FileUtils; use WebThumbnailer\WebThumbnailer; @@ -11,13 +13,15 @@ * * @package WebThumbnailer\Finder */ -class UrlRegexFinderTest extends \PHPUnit_Framework_TestCase +class UrlRegexFinderTest extends TestCase { /** * Test checkRules() with valid data. */ public function testCheckRulesValid() { + $this->addToAssertionCount(1); + $rules = array( 'url_regex' => 'str', 'thumbnail_url' => 'str', @@ -28,11 +32,11 @@ public function testCheckRulesValid() /** * Test checkRules() with invalid data. - * - * @expectedException \WebThumbnailer\Exception\BadRulesException */ public function testCheckRulesMissingThumbUrl() { + $this->expectException(BadRulesException::class); + $rules = [ 'url_regex' => 'str', ]; @@ -42,11 +46,11 @@ public function testCheckRulesMissingThumbUrl() /** * Test checkRules() with invalid data. - * - * @expectedException \WebThumbnailer\Exception\BadRulesException */ public function testCheckRulesMissingUrlRegex() { + $this->expectException(BadRulesException::class); + $rules = [ 'thumbnail_url' => 'str', ]; @@ -241,12 +245,12 @@ public function testFindWithDefaultOptionsBadValues() /** * Test find() with basic replacements, and default options * but without defining default values. - * - * @expectedException \Exception - * @expectedExceptionMessageRegExp /No default set for option/ */ public function testFindWithDefaultOptionsNoDefault() { + $this->expectException(\Exception::class); + $this->expectExceptionMessageRegExp('/No default set for option/'); + $url = 'http://test.io/?123'; $rules = array( 'url_regex' => '/\\?([^&]+)', @@ -264,12 +268,12 @@ public function testFindWithDefaultOptionsNoDefault() /** * Test find() with basic replacements, and default options * with an invalid default option. - * - * @expectedException \Exception - * @expectedExceptionMessageRegExp /No default parameter set for option/ */ public function testFindWithDefaultOptionsNoDefaultParam() { + $this->expectException(\Exception::class); + $this->expectExceptionMessageRegExp('/No default parameter set for option/'); + $url = 'http://test.io/?123'; $rules = array( 'url_regex' => '/\\?([^&]+)', @@ -288,12 +292,12 @@ public function testFindWithDefaultOptionsNoDefaultParam() /** * Test find() with basic replacements, and options not matching anything. - * - * @expectedException \Exception - * @expectedExceptionMessageRegExp /Unknown option/ */ public function testFindWithDefaultOptionsUnknownOption() { + $this->expectException(\Exception::class); + $this->expectExceptionMessageRegExp('/Unknown option/'); + $url = 'http://test.io/?123'; $rules = array( 'url_regex' => '/\\?([^&]+)', diff --git a/tests/WebThumbnailer/Utils/DataUtilsTest.php b/tests/WebThumbnailer/Utils/DataUtilsTest.php index 6c8dd66..7a8c96f 100644 --- a/tests/WebThumbnailer/Utils/DataUtilsTest.php +++ b/tests/WebThumbnailer/Utils/DataUtilsTest.php @@ -2,6 +2,8 @@ namespace WebThumbnailer\Utils; +use PHPUnit\Framework\TestCase; + /** * Class DataUtilsTest * @@ -9,7 +11,7 @@ * * @package WebThumbnailer\Utils */ -class DataUtilsTest extends \PHPUnit_Framework_TestCase +class DataUtilsTest extends TestCase { public function testLoadJsonResource() { @@ -18,21 +20,17 @@ public function testLoadJsonResource() $this->assertEquals('medium', $rules['imgur_single']['options']['size']['default']); } - /** - * @expectedException \Exception - * @expectedExceptionMessage JSON resource file not found or not readable. - */ public function testLoadJsonResourceNoFile() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('JSON resource file not found or not readable.'); DataUtils::loadJson(FileUtils::RESOURCES_PATH . 'nope.json'); } - /** - * @expectedException \Exception - * @expectedExceptionMessageRegExp /An error occured while parsing JSON file: error code #/ - */ public function testLoadJsonResourceBadSyntax() { + $this->expectException(\Exception::class); + $this->expectExceptionMessageRegExp('/An error occured while parsing JSON file: error code #/'); $path = __DIR__ . DIRECTORY_SEPARATOR . '..'. DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR; DataUtils::loadJson($path . 'badsyntax.json'); } diff --git a/tests/WebThumbnailer/Utils/FileUtilsTests.php b/tests/WebThumbnailer/Utils/FileUtilsTests.php index 5486977..9e70830 100644 --- a/tests/WebThumbnailer/Utils/FileUtilsTests.php +++ b/tests/WebThumbnailer/Utils/FileUtilsTests.php @@ -2,12 +2,14 @@ namespace WebThumbnailer\Utils; +use PHPUnit\Framework\TestCase; + /** * Class FileUtilsTests * * @package WebThumbnailer\Utils */ -class FileUtilsTests extends \PHPUnit_Framework_TestCase +class FileUtilsTests extends TestCase { /** * Test getPath() with a valid path. diff --git a/tests/WebThumbnailer/Utils/FinderUtilsTest.php b/tests/WebThumbnailer/Utils/FinderUtilsTest.php index fb15b15..cd029a5 100644 --- a/tests/WebThumbnailer/Utils/FinderUtilsTest.php +++ b/tests/WebThumbnailer/Utils/FinderUtilsTest.php @@ -2,12 +2,14 @@ namespace WebThumbnailer\Utils; +use PHPUnit\Framework\TestCase; + /** * Class FinderUtilsTest * * @package WebThumbnailer\utils */ -class FinderUtilsTest extends \PHPUnit_Framework_TestCase +class FinderUtilsTest extends TestCase { /** * Test buildRegex() function. diff --git a/tests/WebThumbnailer/Utils/ImageUtilsTest.php b/tests/WebThumbnailer/Utils/ImageUtilsTest.php index 938ad21..a454626 100644 --- a/tests/WebThumbnailer/Utils/ImageUtilsTest.php +++ b/tests/WebThumbnailer/Utils/ImageUtilsTest.php @@ -2,6 +2,9 @@ namespace WebThumbnailer\Utils; +use PHPUnit\Framework\TestCase; +use WebThumbnailer\Exception\NotAnImageException; + /** * Class ImageUtilsTest * @@ -9,7 +12,7 @@ * * @package WebThumbnailer\utils */ -class ImageUtilsTest extends \PHPUnit_Framework_TestCase +class ImageUtilsTest extends TestCase { /** * @var string Image as string. @@ -24,7 +27,7 @@ class ImageUtilsTest extends \PHPUnit_Framework_TestCase /** * Regenerate the image before every tests. */ - public function setUp() + public function setUp(): void { // From http://php.net/imagecreatefromstring $data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl' @@ -38,7 +41,7 @@ public function setUp() * Remove the test image in workdir after every test. * Ignore errors. */ - public function tearDown() + public function tearDown(): void { @unlink(self::$WORKDIR . 'file1.png'); } @@ -87,47 +90,47 @@ public function testGenerateThumbnail() /** * Generate a thumbnail into a non existent folder => Exception. - * - * @expectedException \Exception - * @expectedExceptionMessage Target file is not writable. */ public function testGenerateThumbnailUnwritable() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Target file is not writable.'); + $path = self::$WORKDIR . 'nope' . DIRECTORY_SEPARATOR . 'file'; @ImageUtils::generateThumbnail(self::$imageSource, $path, 28, 18); } /** * Generate a thumbnail from a string which is not an image => NotAnImageException. - * - * @expectedException \WebThumbnailer\Exception\NotAnImageException */ public function testGenerateThumbnailNotAnImage() { + $this->expectException(NotAnImageException::class); + $path = self::$WORKDIR . 'file1.png'; ImageUtils::generateThumbnail('virus.exe', $path, 28, 18); } /** * Generate a thumbnail with bad sizes => Exception. - * - * @expectedException \Exception - * @expectedExceptionMessage Could not generate the thumbnail from source image. */ public function testGenerateThumbnailBadSize() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Could not generate the thumbnail from source image.'); + $path = self::$WORKDIR . 'file1.png'; @ImageUtils::generateThumbnail(self::$imageSource, $path, -1, -1); } /** * Generate a thumbnail with bad sizes (Double 0) => Exception. - * - * @expectedException \Exception - * @expectedExceptionMessage At least maxwidth or maxheight needs to be defined. */ public function testGenerateThumbnailBadSizeDoubleZero() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('At least maxwidth or maxheight needs to be defined.'); + $path = self::$WORKDIR . 'file1.png'; @ImageUtils::generateThumbnail(self::$imageSource, $path, 0, 0); } diff --git a/tests/WebThumbnailer/Utils/UrlUtilsTest.php b/tests/WebThumbnailer/Utils/UrlUtilsTest.php index 3023335..8a5fa67 100644 --- a/tests/WebThumbnailer/Utils/UrlUtilsTest.php +++ b/tests/WebThumbnailer/Utils/UrlUtilsTest.php @@ -2,6 +2,8 @@ namespace WebThumbnailer\Utils; +use PHPUnit\Framework\TestCase; + /** * Class UrlUtilsTest * @@ -9,7 +11,7 @@ * * @package WebThumbnailer\Utils */ -class UrlUtilsTest extends \PHPUnit_Framework_TestCase +class UrlUtilsTest extends TestCase { /** * Test getDomain() from various URL. diff --git a/tests/WebThumbnailer/WebThumbnailerTest.php b/tests/WebThumbnailer/WebThumbnailerTest.php index 3e0cb0f..a52ed1d 100644 --- a/tests/WebThumbnailer/WebThumbnailerTest.php +++ b/tests/WebThumbnailer/WebThumbnailerTest.php @@ -2,6 +2,7 @@ namespace WebThumbnailer; +use PHPUnit\Framework\TestCase; use WebThumbnailer\Application\ConfigManager; use WebThumbnailer\Utils\FileUtils; @@ -12,7 +13,7 @@ * * @package WebThumbnailer */ -class WebThumbnailerTest extends \PHPUnit_Framework_TestCase +class WebThumbnailerTest extends TestCase { /** * PHP builtin local server URL. @@ -42,7 +43,7 @@ class WebThumbnailerTest extends \PHPUnit_Framework_TestCase /** * Load test config before running tests. */ - public function setUp() + public function setUp(): void { $resource = 'tests/WebThumbnailer/resources/'; ConfigManager::clear(); @@ -52,7 +53,7 @@ public function setUp() /** * Remove cache folder after every tests. */ - public function tearDown() + public function tearDown(): void { FileUtils::rmdir(self::$cache); FileUtils::rmdir(self::$tmp);