Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #9 from cashlink/php-8
Browse files Browse the repository at this point in the history
PHP 8 compatibility, update PHPUnit
  • Loading branch information
mensler authored Aug 22, 2022
2 parents dabd9a9 + 3379d25 commit 81ad350
Show file tree
Hide file tree
Showing 169 changed files with 224 additions and 248 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

strategy:
matrix:
php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4']
php-versions: ['7.3', '7.4', '8.0', '8.1']

steps:

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
nbproject
.settings
.buildpath
.phpunit.result.cache
.project
.idea
vendor
Expand Down
10 changes: 4 additions & 6 deletions classes/dataBackend/file/download/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Downloader
public function __construct()
{
$this->handle = curl_init();
if (! is_resource($this->handle)) {
if ($this->handle === false) {
throw new DownloaderException("Failed initializing curl");

}
Expand All @@ -36,8 +36,8 @@ public function __construct()
/**
* Execute the curl call.
*
* @return bool|string
* @throws DownloaderException
* @return mixed
*/
private function download($uri)
{
Expand All @@ -62,7 +62,7 @@ private function download($uri)
*
* @param string $uri URI
* @return string Content of the page
* @throws DownloaderException
* @throws DownloaderException|DataBackendIOException
*/
public function downloadContent($uri)
{
Expand All @@ -81,7 +81,7 @@ public function downloadContent($uri)
*
* @param string $uri URI
* @return string local path to downloaded file.
* @throws DownloaderException
* @throws DownloaderException|NoTempDirectoryException
*/
public function downloadFile($uri)
{
Expand All @@ -90,15 +90,13 @@ public function downloadFile($uri)
$fp = fopen($file, 'w');
if (! ($file && $fp)) {
throw new DownloaderException("Failed opening a temporary file");

}
curl_setopt($this->handle, CURLOPT_FILE, $fp);

if (! $this->download($uri)) {
fclose($fp);
unlink($file);
throw new DownloaderException(curl_error($this->handle), curl_errno($this->handle));

}
return $file;
}
Expand Down
18 changes: 12 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,39 @@
"type": "library",
"description": "BAV provides validation for German Bank Accounts (Konto)",
"keywords": ["bank", "account", "bankaccount", "validation", "check", "konto"],
"homepage": "http://bav.malkusch.de/",
"homepage": "https://github.com/cashlink/bav",
"license": "WTFPL",
"authors": [
{
"name": "Markus Malkusch",
"email": "[email protected]",
"homepage": "http://markus.malkusch.de",
"role": "Developer"
},
{
"name": "Clemens Weiß",
"email": "[email protected]",
"role": "Maintainer"
}
],
"autoload": {
"files": ["autoloader/autoloader.php"]
},
"require": {
"php": ">=7.0.0",
"php": ">=7.3",
"cashlink/php-index": "~1.0.0"
},
"suggest": {
"ext-PDO": "Allows storing bank information in a database",
"ext-mbstring": "Enables UTF-8 support",
"ext-dom": "Enables picking the download URI by xpath",
"lib-curl": "Enables API for downloading the bank file",
"ext-curl": "Enables API for downloading the bank file",
"doctrine/orm": "Support for Doctrine ORM data backend"
},
"require-dev": {
"phpunit/phpunit": "~5.7",
"doctrine/orm": "^2"
"phpunit/phpunit": "~9.5",
"doctrine/orm": "^2",
"doctrine/dbal": "^2",
"symfony/cache": "^4.4 || ^5.4 || ^6.0"
},
"archive": {
"exclude": [
Expand Down
6 changes: 2 additions & 4 deletions tests/integration/AgencyQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use PHPUnit\Framework\TestCase;

require_once __DIR__ . "/../bootstrap.php";

/**
* Test SQLDataBackend::getAgencies($sql)
*
Expand Down Expand Up @@ -66,18 +64,18 @@ public function testNoBank(SQLDataBackend $backend)

/**
* @dataProvider provideBackends
* @expectedException malkusch\bav\MissingAttributesDataBackendIOException
*/
public function testNoID(SQLDataBackend $backend)
{
$this->expectException(MissingAttributesDataBackendIOException::class);
$result = $backend->getAgencies(
'SELECT name, postcode, city, shortTerm, pan, bic, bank FROM bav_agency LIMIT 1'
);
}

private function assertAgencies(Array $agencies, $count)
{
$this->assertEquals($count, count($agencies));
$this->assertCount($count, $agencies);

foreach ($agencies as $agency) {
if ($agency->isMainAgency()) {
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/BackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace malkusch\bav;

require_once __DIR__ . "/../bootstrap.php";
use PHPUnit\Framework\TestCase;

/**
* Tests the Backends.
Expand All @@ -11,7 +11,7 @@
* @license WTFPL
* @author Markus Malkusch <[email protected]>
*/
class BackendTest extends \PHPUnit_Framework_TestCase
class BackendTest extends TestCase
{

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/CrossProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace malkusch\bav;

require_once __DIR__ . "/../bootstrap.php";
use PHPUnit\Framework\TestCase;

/**
* Tests the values between different projects.
Expand All @@ -18,7 +18,7 @@
* @license WTFPL
* @large
*/
class CrossProjectTest extends \PHPUnit_Framework_TestCase
class CrossProjectTest extends TestCase
{

/**
Expand Down
11 changes: 5 additions & 6 deletions tests/integration/DataConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
namespace malkusch\bav;

use PHPUnit\Framework\TestCase;

require_once __DIR__ . "/../bootstrap.php";
use RuntimeException;

/**
* Test if the banklist.txt fits into the model.
Expand All @@ -17,7 +16,7 @@ class DataConstraintTest extends TestCase
*/
private static $pdo;

public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
// FIXME: this very MySQL specific
return;
Expand Down Expand Up @@ -87,7 +86,7 @@ public static function setUpBeforeClass()
}

/**
* @return Array
* @return array
*/
public function provideParsedLines()
{
Expand All @@ -110,8 +109,8 @@ public function provideParsedLines()
*/
public function testParser($blz, $type)
{
$this->assertRegExp('~^\d{8}$~', $blz);
$this->assertRegExp('~^[\dA-Z]\d$~', $type);
$this->assertMatchesRegularExpression('~^\d{8}$~', $blz);
$this->assertMatchesRegularExpression('~^[\dA-Z]\d$~', $type);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions tests/integration/StatementContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use PHPUnit\Framework\TestCase;

require_once __DIR__ . "/../bootstrap.php";

/**
* Tests StatementContainer.
*
Expand All @@ -21,7 +19,7 @@ class StatementContainerTest extends TestCase
*/
private $statementContainer;

public function setUp()
public function setUp(): void
{
$this->statementContainer = new StatementContainer(PDOFactory::makePDO());
}
Expand Down
10 changes: 3 additions & 7 deletions tests/unit/00UpdatePlanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use PHPUnit\Framework\TestCase;

require_once __DIR__ . "/../bootstrap.php";

/**
* Tests UpdatePlan
*
Expand Down Expand Up @@ -66,33 +64,31 @@ public function testIsOutdated($mtime, $time, $expectedIsOutdated)
TimeMock::disable();
}

/**
* @expectedException \PHPUnit_Framework_Error_Warning
*/
public function testLogUpdatePlan()
{
$this->expectWarning();
$updatePlan = new LogUpdatePlan();
$updatePlan->perform(new FileDataBackend());
}

/**
* @expectedException \PHPUnit_Framework_Error_Notice
* @medium
*/
public function testAutomaticUpdatePlanNotice()
{
$this->expectNotice();
$fileUtil = new FileUtil();
$file = tempnam($fileUtil->getTempDirectory(), 'bavtest');
$updatePlan = new AutomaticUpdatePlan();
$updatePlan->perform(new FileDataBackend($file));
}

/**
* @expectedException \PHPUnit_Framework_Error_Notice
* @medium
*/
public function testAutomaticUpdatePlan()
{
$this->expectNotice();
$fileUtil = new FileUtil();
$file = tempnam($fileUtil->getTempDirectory(), 'bavtest');
touch($file, strtotime("-1 year"));
Expand Down
8 changes: 3 additions & 5 deletions tests/unit/BAVFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use PHPUnit\Framework\TestCase;

require_once __DIR__ . "/../bootstrap.php";

/**
* Tests the facade BAV.
*
Expand All @@ -31,23 +29,23 @@ public function testGetBank()
/**
* Tests BAV::getBank();
*
* @expectedException malkusch\bav\BankNotFoundException
* @see BAV::getBank();
*/
public function testFailGetBank()
{
$this->expectException(BankNotFoundException::class);
$bav = new BAV();
$bav->getBank("12345678");
}

/**
* Tests BAV::getAgencies();
*
* @expectedException malkusch\bav\BankNotFoundException
* @see BAV::getAgencies();
*/
public function testFailGetAgencies()
{
$this->expectException(BankNotFoundException::class);
$bav = new BAV();
$bav->getAgencies("12345678");
}
Expand Down Expand Up @@ -95,11 +93,11 @@ public function testGetMainAgency()
/**
* Tests BAV::getMainAgency();
*
* @expectedException malkusch\bav\BankNotFoundException
* @see BAV::getMainAgency();
*/
public function testFailGetMainAgency()
{
$this->expectException(BankNotFoundException::class);
$bav = new BAV();
$bav->getMainAgency("12345678");
}
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/BICUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use PHPUnit\Framework\TestCase;

require_once __DIR__ . "/../bootstrap.php";

/**
* Tests BICUtil.
*
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/BackendContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use PHPUnit\Framework\TestCase;

require_once __DIR__ . "/../bootstrap.php";

/**
* Tests DataBackendContainer
*
Expand Down
9 changes: 4 additions & 5 deletions tests/unit/ConfigurationLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use PHPUnit\Framework\TestCase;

require_once __DIR__ . "/../bootstrap.php";

/**
* Tests ConfigurationLocator
*
Expand All @@ -31,10 +29,10 @@ public function testlocateReturnsNull()
* locate() should throw an exception
*
* @see ConfigurationLocator::locate();
* @expectedException malkusch\bav\ConfigurationException
*/
public function testlocateThrowsException()
{
$this->expectException(ConfigurationException::class);
$locator = new ConfigurationLocator(array(
__DIR__ . "/../data/no_configuration.php"
));
Expand Down Expand Up @@ -84,15 +82,16 @@ public function provideTestLocateFindsAbsolutePath()
*/
public function testLocateFindsIncludePath($includePath, array $paths)
{
set_include_path(get_include_path() . PATH_SEPARATOR . $includePath);
$oldIncludePath = get_include_path();
set_include_path($oldIncludePath . PATH_SEPARATOR . $includePath);

$locator = new ConfigurationLocator($paths);
$configuration = $locator->locate();

$this->assertInstanceOf("malkusch\bav\Configuration", $configuration);
$this->assertEquals("test", $configuration->getTempDirectory());

restore_include_path();
set_include_path($oldIncludePath);
}

/**
Expand Down
Loading

0 comments on commit 81ad350

Please sign in to comment.