Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to PHPUnit 10, raise PHP requirement to 8.1, update other dev tools. #21

Merged
merged 8 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ jobs:
VUFIND_LOCAL_DIR: $GITHUB_WORKSPACE/local
strategy:
matrix:
php-version: ['8.0', '8.1', '8.2']
php-version: ['8.1', '8.2', '8.3']
include:
- php-version: 8.0
phing_tasks: "phpunitfast"
- php-version: 8.1
phing_tasks: "phpunitfast"
- php-version: 8.2
phing_tasks: "phpunitfast"
- php-version: 8.3
phing_tasks: "phpunitfast phpcs-console php-cs-fixer-dryrun phpstan-console"

steps:
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ All notable changes to this project will be documented in this file, in reverse

### Changed

- The minimum PHP version requirement has been raised to 8.0.
- The minimum PHP version requirement has been raised to 8.1.

### Deprecated

Expand Down
19 changes: 10 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,27 @@
},
"config": {
"platform": {
"php": "8.0"
"php": "8.1"
}
},
"require": {
"php": ">=8.0",
"php": ">=8.1",
"laminas/laminas-http": ">=2.2",
"symfony/console": "^5.3||^6||^7"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "3.26.1",
"pear/http_request2": "2.5.1",
"phpmd/phpmd": "2.13.0",
"phpstan/phpstan": "1.10.34",
"phpunit/phpunit": "9.6.12",
"friendsofphp/php-cs-fixer": "3.51.0",
"pear/http_request2": "2.6.0",
"phpmd/phpmd": "2.15.0",
"phpstan/phpstan": "1.10.59",
"phpunit/phpunit": "10.5.11",
"phing/phing": "2.17.4",
"squizlabs/php_codesniffer": "3.7.2"
"squizlabs/php_codesniffer": "3.9.0"
},
"autoload": {
"psr-4": {
"VuFindHarvest\\": "src/"
"VuFindHarvest\\": "src/",
"VuFindTest\\Feature\\": "tests/unit-tests/src/VuFindTest/Feature/"
}
}
}
16 changes: 10 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="tests/bootstrap.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
displayDetailsOnTestsThatTriggerWarnings="true">
<testsuites>
<testsuite name="Integration Tests">
<directory>tests/integration-tests</directory>
Expand All @@ -16,4 +15,9 @@
<php>
<includePath>.</includePath>
</php>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
86 changes: 86 additions & 0 deletions tests/unit-tests/src/VuFindTest/Feature/WithConsecutiveTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

/**
* Trait for setting consecutive test expectations.
*
* PHP version 8
*
* Copyright (C) Villanova University 2024.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package Tests
* @author Demian Katz <[email protected]>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development:testing:unit_tests Wiki
*/

namespace VuFindTest\Feature;

use PHPUnit\Framework\Constraint\Constraint;
use PHPUnit\Framework\MockObject\Builder\InvocationStubber;
use PHPUnit\Framework\MockObject\MockObject;

use function count;
use function func_get_args;
use function is_array;

/**
* Trait for setting consecutive test expectations.
*
* @category VuFind
* @package Tests
* @author Demian Katz <[email protected]>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development:testing:unit_tests Wiki
*/
trait WithConsecutiveTrait
{
/**
* Expect consecutive calls to a mock.
*
* @param MockObject $mock Mock object
* @param string $method Method expecting calls
* @param array $expectedCalls Expected input parameters
* @param mixed $returnValues Return values to mock (either an array indexed parallel to
* $expectedCalls to return different values, or a single value to always return the same thing)
*
* @return InvocationStubber
*/
protected function expectConsecutiveCalls(
MockObject $mock,
string $method,
array $expectedCalls,
mixed $returnValues = null
): InvocationStubber {
$matcher = $this->exactly(count($expectedCalls));
$callback = function () use ($matcher, $expectedCalls, $returnValues) {
$index = $matcher->numberOfInvocations() - 1;
$expectedArgs = $expectedCalls[$index] ?? [];
$actualArgs = func_get_args();
foreach ($expectedArgs as $i => $expected) {
if ($expected instanceof Constraint) {
$expected->evaluate($actualArgs[$i] ?? null);
} else {
$this->assertEquals($expected, $actualArgs[$i] ?? null);
}
}
return is_array($returnValues) ? $returnValues[$index] ?? null : $returnValues;
};
return $mock->expects($matcher)
->method($method)
->willReturnCallback($callback);
}
}
85 changes: 49 additions & 36 deletions tests/unit-tests/src/VuFindTest/OaiPmh/HarvesterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
*/
class HarvesterTest extends \PHPUnit\Framework\TestCase
{
use \VuFindTest\Feature\WithConsecutiveTrait;

/**
* Time zone setting used with setup/tearDown
*
Expand Down Expand Up @@ -210,15 +212,18 @@ public function testSimpleListRecords()
{
$comm = $this->getMockCommunicator();
$expectedSettings = ['metadataPrefix' => 'oai_dc'];
$comm->expects($this->exactly(2))->method('request')
->withConsecutive(
$this->expectConsecutiveCalls(
$comm,
'request',
[
['Identify', []],
['ListRecords', $expectedSettings],
)
->willReturnOnConsecutiveCalls(
],
[
simplexml_load_string($this->getFakeIdentifyResponse()),
simplexml_load_string($this->getFakeResponse())
);
simplexml_load_string($this->getFakeResponse()),
]
);
$writer = $this->getMockRecordWriter();
$writer->expects($this->once())->method('write')
->with($this->isInstanceOf('SimpleXMLElement'))
Expand Down Expand Up @@ -248,15 +253,18 @@ public function testListRecordsWithResumption()
'from' => '2016-07-01', 'until' => '2016-07-31',
];
$expectedSettings1 = ['resumptionToken' => 'more'];
$comm->expects($this->exactly(2))->method('request')
->withConsecutive(
$this->expectConsecutiveCalls(
$comm,
'request',
[
['ListRecords', $expectedSettings0],
['ListRecords', $expectedSettings1],
)
->willReturnOnConsecutiveCalls(
],
[
simplexml_load_string($this->getFakeResponseWithToken()),
simplexml_load_string($this->getFakeResponse())
);
simplexml_load_string($this->getFakeResponse()),
]
);
$writer = $this->getMockRecordWriter();
$writer->expects($this->exactly(2))->method('write')
->with($this->isInstanceOf('SimpleXMLElement'));
Expand Down Expand Up @@ -290,12 +298,8 @@ public function testListRecordsWithStopAfterOption()
'from' => '2016-07-01', 'until' => '2016-07-31',
];
$comm->expects($this->exactly(1))->method('request')
->withConsecutive(
['ListRecords', $expectedSettings0],
)
->willReturnOnConsecutiveCalls(
simplexml_load_string($this->getFakeResponse())
);
->with('ListRecords', $expectedSettings0)
->willReturn(simplexml_load_string($this->getFakeResponse()));
$writer = $this->getMockRecordWriter();
$writer->expects($this->exactly(1))->method('write')
->with($this->isInstanceOf('SimpleXMLElement'));
Expand Down Expand Up @@ -327,15 +331,18 @@ public function testBadResumptionToken()

$comm = $this->getMockCommunicator();
$expectedSettings = ['resumptionToken' => 'foo'];
$comm->expects($this->exactly(2))->method('request')
->withConsecutive(
$this->expectConsecutiveCalls(
$comm,
'request',
[
['Identify', []],
['ListRecords', $expectedSettings],
)
->willReturnOnConsecutiveCalls(
],
[
simplexml_load_string($this->getFakeIdentifyResponse()),
simplexml_load_string($this->getTokenErrorResponse())
);
simplexml_load_string($this->getTokenErrorResponse()),
]
);
$sm = $this->getMockStateManager();
$sm->expects($this->any())->method('loadState')
->will($this->returnValue([null, 'foo', 'bar', 'baz']));
Expand All @@ -361,15 +368,18 @@ public function testArbitraryOaiError()

$comm = $this->getMockCommunicator();
$expectedSettings = ['metadataPrefix' => 'oai_dc'];
$comm->expects($this->exactly(2))->method('request')
->withConsecutive(
$this->expectConsecutiveCalls(
$comm,
'request',
[
['Identify', []],
['ListRecords', $expectedSettings],
)
->willReturnOnConsecutiveCalls(
],
[
simplexml_load_string($this->getFakeIdentifyResponse()),
simplexml_load_string($this->getArbitraryErrorResponse())
);
simplexml_load_string($this->getArbitraryErrorResponse()),
]
);
$harvester = $this->getHarvester(
['dateGranularity' => 'YYYY-MM-DDThh:mm:ssZ'],
$comm
Expand All @@ -387,15 +397,18 @@ public function testSimpleListRecordsGranularityHandling()
{
$comm = $this->getMockCommunicator();
$expectedSettings = ['metadataPrefix' => 'oai_dc'];
$comm->expects($this->exactly(2))->method('request')
->withConsecutive(
$this->expectConsecutiveCalls(
$comm,
'request',
[
['Identify', []],
['ListRecords', $expectedSettings],
)
->willReturnOnConsecutiveCalls(
],
[
simplexml_load_string($this->getFakeIdentifyResponse()),
simplexml_load_string($this->getFakeResponse())
);
simplexml_load_string($this->getFakeResponse()),
]
);
$writer = $this->getMockRecordWriter();
$writer->expects($this->once())->method('write')
->with($this->isInstanceOf('SimpleXMLElement'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
*/
class IndividualRecordWriterStrategyTest extends \PHPUnit\Framework\TestCase
{
use \VuFindTest\Feature\WithConsecutiveTrait;

/**
* Test strategy
*
Expand All @@ -51,10 +53,8 @@ public function testStrategy()
\VuFindHarvest\RecordWriterStrategy\IndividualRecordWriterStrategy::class
)->onlyMethods(['saveDeletedRecords', 'saveFile'])
->setConstructorArgs(['foo'])->getMock();
$mock->expects($this->exactly(2))->method('saveDeletedRecords')
->withConsecutive(['d1'], ['d2']);
$mock->expects($this->exactly(2))->method('saveFile')
->withConsecutive(['r1'], ['r2']);
$this->expectConsecutiveCalls($mock, 'saveDeletedRecords', [['d1'], ['d2']]);
$this->expectConsecutiveCalls($mock, 'saveFile', [['r1'], ['r2']]);
$mock->beginWrite();
$mock->addDeletedRecord('d1');
$mock->addRecord('r1', '<foo1 />');
Expand Down
6 changes: 3 additions & 3 deletions tests/vufind.php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
->in(__DIR__ . '/../src');

$rules = [
'@PHP80Migration' => true,
'@PHPUnit84Migration:risky' => true,
'@PHP81Migration' => true,
'@PHPUnit100Migration:risky' => true,
'@PSR12' => true,
'align_multiline_comment' => true,
'binary_operator_spaces' => [
Expand Down Expand Up @@ -45,8 +45,8 @@
'no_php4_constructor' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_spaces_around_offset' => true,
'no_unneeded_braces' => true,
'no_unneeded_control_parentheses' => true,
'no_unneeded_curly_braces' => true,
'no_unneeded_final_method' => true,
'no_unreachable_default_argument_value' => true,
'no_unused_imports' => true,
Expand Down
Loading