Skip to content

Commit bccea3d

Browse files
committed
Build and test again
The `pear run-tests -r tests/` command executes the .phpt tests of which there are none for Net/URL2: pear run-tests -r tests/ Running 0 tests TOTAL TIME: 00:00 0 PASSED TESTS 0 SKIPPED TESTS Running with `-u` for the Phpunit test-cases fails with the pear test runner as long as it is not possible to install Phpunit via pear. As an intermediate, use the phpunit test runner from the project configuration (composer.json) and bootstrap across PHP versions. Additionally, touch the test-cases for updates of PhpUnit since versions 3/4/5 up to 12.0.2 (tested with PHP 5.3-8.4).
1 parent a50760b commit bccea3d

File tree

9 files changed

+115
-11
lines changed

9 files changed

+115
-11
lines changed

.editorconfig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# https://editorconfig.org/
2+
3+
root = true
4+
5+
[Makefile]
6+
end_of_line = lf
7+
indent_size = 4
8+
indent_style = tab
9+
10+
[*.php]
11+
trim_trailing_whitespace = true
12+
insert_final_newline = true
13+
end_of_line = lf
14+
charset = utf-8
15+
indent_size = 4
16+
indent_style = space
17+
18+
[*.xml]
19+
end_of_line = lf
20+
indent_size = 2
21+
indent_style = space

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/.* export-ignore
2+
/Makefile export-ignore
23
/docs/*.php export-ignore
34
/tests/ export-ignore
45
/package.xml export-ignore

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ jobs:
2424
with:
2525
php-version: ${{ matrix.php-version }}
2626
ini-values: include_path=.:/usr/share/php:pear/usr/share/php
27-
- name: Run tests
28-
run: |
29-
pear run-tests -r tests/
27+
tools: composer:2.2
28+
- name: Make
29+
run: make

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# pear related
22
/Net_URL2-*.tgz
33

4+
# php build related
5+
/.php*
6+
47
# composer related
58
vendor/
69
/composer.lock

Makefile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
PHP ?= php
2+
export PHP_PEAR_PHP_BIN ?= $(PHP)
3+
export PHP_BINARY ?= $(PHP)
4+
COMPOSERCMD ?= $(PHP) "$(shell command -v composer)" -qn
5+
6+
all:
7+
.PHONY: all clean build dist distclean
8+
9+
vendor/bin/php% : composer.json
10+
$(COMPOSERCMD) install
11+
touch -c $@
12+
13+
build: vendor/bin/phpunit
14+
pear version
15+
$(PHP) $<
16+
pear run-tests -r tests/
17+
18+
all: build
19+
20+
clean:
21+
rm -f -- $(wildcard .php*)
22+
23+
distclean: clean
24+
rm -rf -- $(wildcard vendor composer.lock Net_URL2-?.?.?.tgz)
25+
26+
dist:
27+
pear version
28+
pear package

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,8 @@
4646
},
4747
"require-dev": {
4848
"phpunit/phpunit": ">=3.3.0"
49+
},
50+
"scripts": {
51+
"test": "phpunit"
4952
}
5053
}

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<phpunit bootstrap="Net/URL2.php"
1+
<phpunit bootstrap="tests/bootstrap.php"
22
colors="false"
33
convertErrorsToExceptions="true"
44
convertNoticesToExceptions="true"

tests/Net/URL2Test.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public function testSetFragment()
212212
* @see testResolveUrls
213213
* @return array
214214
*/
215-
public function provideResolveUrls()
215+
public static function provideResolveUrls()
216216
{
217217
return array(
218218
array(
@@ -283,6 +283,7 @@ public function provideResolveUrls()
283283
* @covers Net_URL2::resolve
284284
* @return void
285285
*/
286+
#[PHPUnit\Framework\Attributes\DataProvider('provideResolveUrls')]
286287
public function testResolveUrls($baseURL, array $relativeAbsolutePairs,
287288
array $options = array()
288289
) {
@@ -468,7 +469,7 @@ public function testDontUseBrackets()
468469
* @link http://tools.ietf.org/html/rfc3986#section-1.1.2
469470
* @see testExampleUri
470471
*/
471-
public function provideExampleUri()
472+
public static function provideExampleUri()
472473
{
473474
return array(
474475
array('ftp://ftp.is.co.za/rfc/rfc1808.txt'),
@@ -492,6 +493,7 @@ public function provideExampleUri()
492493
* @link http://tools.ietf.org/html/rfc3986#section-1.1.2
493494
* @see testComponentRecompositionAndNormalization
494495
*/
496+
#[PHPUnit\Framework\Attributes\DataProvider('provideExampleUri')]
495497
public function testExampleUri($uri)
496498
{
497499
$url = new Net_URL2($uri);
@@ -507,7 +509,7 @@ public function testExampleUri($uri)
507509
* @see testRemoveDotSegments
508510
* @return array
509511
*/
510-
public function providePath()
512+
public static function providePath()
511513
{
512514
// The numbers behind are in reference to sections
513515
// in RFC 3986 5.2.4. Remove Dot Segments
@@ -542,6 +544,7 @@ public function providePath()
542544
* @covers Net_URL2::removeDotSegments
543545
* @return void
544546
*/
547+
#[PHPUnit\Framework\Attributes\DataProvider('providePath')]
545548
public function testRemoveDotSegments($path, $assertion)
546549
{
547550
$this->assertEquals($assertion, Net_URL2::removeDotSegments($path));
@@ -570,7 +573,7 @@ public function testRemoveDotSegmentsLoopLimit()
570573
* @see testGetQueryVariables
571574
* @return array
572575
*/
573-
public function provideQueryStrings()
576+
public static function provideQueryStrings()
574577
{
575578
// If the second (expected) value is set or not null, parse_str() differs.
576579
// Notes on PHP differences with each entry/block
@@ -632,6 +635,7 @@ public function provideQueryStrings()
632635
* @covers Net_URL2::_queryKeyBracketOffset
633636
* @return void
634637
*/
638+
#[PHPUnit\Framework\Attributes\DataProvider('provideQueryStrings')]
635639
public function testGetQueryVariables($query, $expected = null,
636640
array $options = array()
637641
) {
@@ -663,7 +667,7 @@ public function testGetQueryVariables($query, $expected = null,
663667
* @return array
664668
* @see testHostAndPort
665669
*/
666-
public function provideHostAndPort()
670+
public static function provideHostAndPort()
667671
{
668672
return array(
669673
array('[::1]', '[::1]', false),
@@ -699,6 +703,7 @@ public function provideHostAndPort()
699703
* @link http://tools.ietf.org/html/rfc3986#section-3.2
700704
* @link http://tools.ietf.org/html/rfc3986#section-3.2.3
701705
*/
706+
#[PHPUnit\Framework\Attributes\DataProvider('provideHostAndPort')]
702707
public function testHostAndPort($authority, $expectedHost, $expectedPort)
703708
{
704709
$uri = "http://{$authority}";
@@ -762,6 +767,8 @@ public function test19315()
762767
Net_URL2::removeDotSegments($nonStringObject);
763768
} catch (PHPUnit_Framework_Error $error) {
764769
$this->addToAssertionCount(1);
770+
} catch (Throwable $error) {
771+
$this->addToAssertionCount(1);
765772
}
766773

767774
if (!isset($error)) {
@@ -816,7 +823,7 @@ public function test19684()
816823
* @see testConstructSelf
817824
* @return array
818825
*/
819-
public function provideEquivalentUrlLists()
826+
public static function provideEquivalentUrlLists()
820827
{
821828
return array(
822829
// String equivalence:
@@ -853,6 +860,7 @@ public function provideEquivalentUrlLists()
853860
*
854861
* @dataProvider provideEquivalentUrlLists
855862
*/
863+
#[PHPUnit\Framework\Attributes\DataProvider('provideEquivalentUrlLists')]
856864
public function testNormalize()
857865
{
858866
$urls = func_get_args();
@@ -897,7 +905,7 @@ public function testMagicSetGet()
897905
* @return array
898906
* @see testComponentRecompositionAndNormalization
899907
*/
900-
public function provideComposedAndNormalized()
908+
public static function provideComposedAndNormalized()
901909
{
902910
return array(
903911
array(''),
@@ -926,6 +934,7 @@ public function provideComposedAndNormalized()
926934
* @link https://pear.php.net/bugs/bug.php?id=20418
927935
* @see testExampleUri
928936
*/
937+
#[PHPUnit\Framework\Attributes\DataProvider('provideComposedAndNormalized')]
929938
public function testComponentRecompositionAndNormalization($uri)
930939
{
931940
$url = new Net_URL2($uri);
@@ -942,6 +951,7 @@ public function testComponentRecompositionAndNormalization($uri)
942951
* @coversNothing
943952
* @return void
944953
*/
954+
#[PHPUnit\Framework\Attributes\DataProvider('provideEquivalentUrlLists')]
945955
public function testConstructSelf()
946956
{
947957
$urls = func_get_args();

tests/bootstrap.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/**
4+
* Net_URL2, a class representing a URL as per RFC 3986.
5+
*
6+
* PHP version 5
7+
*
8+
* @category Networking
9+
* @package Net_URL2
10+
* @author Some Pear Developers <pear@php.net>
11+
* @license https://spdx.org/licenses/BSD-3-Clause BSD-3-Clause
12+
* @link https://tools.ietf.org/html/rfc3986
13+
*/
14+
15+
if (!class_exists('PHPUnit_Framework_TestCase'))
16+
{
17+
class_alias('PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase');
18+
}
19+
20+
function shutdown($error_log)
21+
{
22+
if (is_file($error_log))
23+
{
24+
printf("%s:\n", $error_log);
25+
fpassthru(fopen($error_log, 'r'));
26+
printf("%s: found. STOP.\n", $error_log);
27+
exit(1);
28+
}
29+
}
30+
31+
ini_set('error_reporting', '-1');
32+
ini_set('error_log', dirname(dirname(__FILE__)) . vsprintf('/.php-%d.%d.%d-error.log', sscanf(PHP_VERSION, '%d.%d.%d')));
33+
ini_set('log_errors', '1');
34+
shutdown(ini_get('error_log'));
35+
register_shutdown_function('shutdown', ini_get('error_log'));
36+
ini_set('display_errors', 'stderr');
37+
38+
require dirname(__FILE__) . '/../Net/URL2.php';

0 commit comments

Comments
 (0)