Skip to content

Commit

Permalink
Merge pull request #26 from ArthurHoaro/fix/phpunit-compat
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurHoaro authored Sep 29, 2020
2 parents cb5aaa9 + ca8544f commit 4f9307f
Show file tree
Hide file tree
Showing 19 changed files with 75 additions and 42 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
],
"require": {
"php": ">=7.1",
"phpunit/php-text-template": "^1.2"
"phpunit/php-text-template": "^1.2 || ^2.0"
},
"require-dev": {
"phpunit/phpunit": "^7.0 || ^8.0",
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0",
"php-coveralls/php-coveralls": "^2.0",
"squizlabs/php_codesniffer": "^3.0",
"gskema/phpcs-type-sniff": "^0.13.1",
Expand Down
49 changes: 23 additions & 26 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
colors="true"
bootstrap="./tests/bootstrap.php">
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/WebThumbnailer/</directory>
<directory suffix=".php">tests/WebThumbnailer/</directory>
</whitelist>
</filter>
<testsuites>
<testsuite name="AllTests">
<directory>tests</directory>
</testsuite>
</testsuites>
<logging>
<log type="coverage-html" target="coverage" lowUpperBound="30" highLowerBound="80"/>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="true"/>
<log type="coverage-clover" target="coverage/logs/clover.xml"/>
</logging>
<php>
<const name="WEB_SERVER_HOST" value="localhost" />
<const name="WEB_SERVER_PORT" value="8081" />
<const name="WEB_SERVER_DOCROOT" value="./tests/public" />
</php>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" colors="true" bootstrap="./tests/bootstrap.php">
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">src/WebThumbnailer/</directory>
<directory suffix=".php">tests/WebThumbnailer/</directory>
</include>
<report>
<clover outputFile="coverage/logs/clover.xml"/>
<html outputDirectory="coverage" lowUpperBound="30" highLowerBound="80"/>
<text outputFile="php://stdout" showUncoveredFiles="true"/>
</report>
</coverage>
<testsuites>
<testsuite name="AllTests">
<directory>tests</directory>
</testsuite>
</testsuites>
<logging/>
<php>
<const name="WEB_SERVER_HOST" value="localhost"/>
<const name="WEB_SERVER_PORT" value="8081"/>
<const name="WEB_SERVER_DOCROOT" value="./tests/public"/>
</php>
</phpunit>
3 changes: 2 additions & 1 deletion src/WebThumbnailer/Application/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use WebThumbnailer\Exception\CacheException;
use WebThumbnailer\Exception\IOException;
use WebThumbnailer\Utils\FileUtils;
use WebThumbnailer\Utils\TemplatePolyfill;

/**
* Handles file caching using static methods.
Expand Down Expand Up @@ -176,7 +177,7 @@ protected static function createHtaccessFile(string $path, bool $allowed = false
$templateFile = file_exists(FileUtils::RESOURCES_PATH . 'htaccess' . $apacheVersion . '_template')
? FileUtils::RESOURCES_PATH . 'htaccess' . $apacheVersion . '_template'
: FileUtils::RESOURCES_PATH . 'htaccess_template';
$template = new \Text_Template($templateFile);
$template = TemplatePolyfill::get($templateFile);
$template->setVar([
'new_all' => $allowed ? 'granted' : 'denied',
'old_allow' => $allowed ? 'all' : 'none',
Expand Down
18 changes: 18 additions & 0 deletions src/WebThumbnailer/Utils/TemplatePolyfill.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace WebThumbnailer\Utils;

class TemplatePolyfill
{
/** @return \Text_Template|\SebastianBergmann\Template\Template */
public static function get(string $file)
{
if (class_exists('Text_Template')) {
return new \Text_Template($file);
}

return new \SebastianBergmann\Template\Template($file);
}
}
2 changes: 1 addition & 1 deletion tests/WebThumbnailer/Application/CacheManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace WebThumbnailer\Application;

use PHPUnit\Framework\TestCase;
use WebThumbnailer\TestCase;
use WebThumbnailer\Utils\FileUtils;

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/WebThumbnailer/Application/ThumbnailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace WebThumbnailer\Application;

use PHPUnit\Framework\TestCase;
use WebThumbnailer\Exception\BadRulesException;
use WebThumbnailer\TestCase;
use WebThumbnailer\Utils\FileUtils;
use WebThumbnailer\Utils\SizeUtils;
use WebThumbnailer\WebThumbnailer;
Expand Down
2 changes: 1 addition & 1 deletion tests/WebThumbnailer/Finder/DefaultFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace WebThumbnailer\Finder;

use PHPUnit\Framework\TestCase;
use WebThumbnailer\TestCase;

/**
* Class DefaultFinderTest
Expand Down
2 changes: 1 addition & 1 deletion tests/WebThumbnailer/Finder/FinderFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace WebThumbnailer\Finder;

use PHPUnit\Framework\TestCase;
use WebThumbnailer\Exception\BadRulesException;
use WebThumbnailer\TestCase;

/**
* Class FinderFactoryTest
Expand Down
2 changes: 1 addition & 1 deletion tests/WebThumbnailer/Finder/FlickRFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace WebThumbnailer\Finder;

use PHPUnit\Framework\TestCase;
use WebThumbnailer\TestCase;

/**
* Class FlickRFinderTest
Expand Down
2 changes: 1 addition & 1 deletion tests/WebThumbnailer/Finder/QueryRegexFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace WebThumbnailer\Finder;

use PHPUnit\Framework\TestCase;
use WebThumbnailer\Exception\BadRulesException;
use WebThumbnailer\TestCase;
use WebThumbnailer\Utils\DataUtils;
use WebThumbnailer\Utils\FileUtils;

Expand Down
2 changes: 1 addition & 1 deletion tests/WebThumbnailer/Finder/UrlRegexFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace WebThumbnailer\Finder;

use PHPUnit\Framework\TestCase;
use WebThumbnailer\Exception\BadRulesException;
use WebThumbnailer\TestCase;
use WebThumbnailer\Utils\DataUtils;
use WebThumbnailer\Utils\FileUtils;
use WebThumbnailer\WebThumbnailer;
Expand Down
17 changes: 17 additions & 0 deletions tests/WebThumbnailer/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace WebThumbnailer;

class TestCase extends \PHPUnit\Framework\TestCase
{
public function expectExceptionMessageRegExp(string $regularExpression): void
{
if (method_exists($this, 'expectExceptionMessageMatches')) {
$this->expectExceptionMessageMatches($regularExpression);
} else {
parent::expectExceptionMessageRegExp($regularExpression);
}
}
}
2 changes: 1 addition & 1 deletion tests/WebThumbnailer/Utils/DataUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace WebThumbnailer\Utils;

use PHPUnit\Framework\TestCase;
use WebThumbnailer\TestCase;

/**
* Class DataUtilsTest
Expand Down
2 changes: 1 addition & 1 deletion tests/WebThumbnailer/Utils/FileUtilsTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace WebThumbnailer\Utils;

use PHPUnit\Framework\TestCase;
use WebThumbnailer\TestCase;

/**
* Class FileUtilsTests
Expand Down
2 changes: 1 addition & 1 deletion tests/WebThumbnailer/Utils/FinderUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace WebThumbnailer\Utils;

use PHPUnit\Framework\TestCase;
use WebThumbnailer\TestCase;

/**
* Class FinderUtilsTest
Expand Down
2 changes: 1 addition & 1 deletion tests/WebThumbnailer/Utils/ImageUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace WebThumbnailer\Utils;

use PHPUnit\Framework\TestCase;
use WebThumbnailer\Exception\NotAnImageException;
use WebThumbnailer\TestCase;

/**
* Class ImageUtilsTest
Expand Down
2 changes: 1 addition & 1 deletion tests/WebThumbnailer/Utils/UrlUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace WebThumbnailer\Utils;

use PHPUnit\Framework\TestCase;
use WebThumbnailer\TestCase;

/**
* Class UrlUtilsTest
Expand Down
2 changes: 1 addition & 1 deletion tests/WebThumbnailer/WebThumbnailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function testDirectImageWithoutExtension()
*/
public function testOpenGraphImage()
{
$image = 'default/le-monde.png';
$image = 'default/le-monde.jpg';
$this->regenerate($image);
$expected = self::$regenerated . $image;
$url = self::LOCAL_SERVER . 'default/le-monde.html';
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4f9307f

Please sign in to comment.