Skip to content

Commit

Permalink
DEP Use phpunit 11
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Sep 6, 2024
1 parent 1a53bc1 commit aff6913
Show file tree
Hide file tree
Showing 98 changed files with 354 additions and 241 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
"m1/env": "^2.2.0",
"masterminds/html5": "^2.7.6",
"monolog/monolog": "^3.2.0",
"nikic/php-parser": "^4.15.0",
"nikic/php-parser": "^5.1.0",
"psr/container": "^1.1 || ^2.0",
"psr/http-message": "^1",
"sebastian/diff": "^4.0",
"sebastian/diff": "^6.0",
"silverstripe/config": "^3",
"silverstripe/assets": "^3",
"silverstripe/vendor-plugin": "^2",
Expand Down Expand Up @@ -63,7 +63,7 @@
},
"require-dev": {
"composer/semver": "^3.4",
"phpunit/phpunit": "^9.6",
"phpunit/phpunit": "^11.3",
"silverstripe/versioned": "^3",
"squizlabs/php_codesniffer": "^3.7",
"silverstripe/standards": "^1",
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Manifest/ClassManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public function init($includeTests = false, $forceRegen = false)
public function getParser()
{
if (!$this->parser) {
$this->parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$this->parser = (new ParserFactory)->createForHostVersion();
}

return $this->parser;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Manifest/ClassManifestErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct($pathname)
$this->pathname = $pathname;
}

public function handleError(Error $error)
public function handleError(Error $error): void
{
$newMessage = sprintf('%s in %s', $error->getRawMessage(), $this->pathname);
$error->setRawMessage($newMessage);
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Control/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ public function testJoinLinks()
);
}

public function provideNormaliseTrailingSlash(): array
public static function provideNormaliseTrailingSlash(): array
{
// note 93.184.215.14 is the IP address for example.com
return [
Expand Down
6 changes: 3 additions & 3 deletions tests/php/Control/DirectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public function testIsAbsolute($path, $result)
$this->assertEquals($result, Director::is_absolute($path));
}

public function provideAbsolutePaths()
public static function provideAbsolutePaths()
{
return [
['C:/something', true],
Expand Down Expand Up @@ -294,7 +294,7 @@ public function testIsRelativeUrl()
/**
* @return array
*/
public function providerMakeRelative()
public static function providerMakeRelative()
{
return [
// Resilience to slash position
Expand Down Expand Up @@ -543,7 +543,7 @@ public function testResetGlobalsAfterTestRequest()
);
}

public function providerTestTestRequestCarriesGlobals()
public static function providerTestTestRequestCarriesGlobals()
{
$tests = [];
$fixture = ['somekey' => 'sometestvalue'];
Expand Down
6 changes: 3 additions & 3 deletions tests/php/Control/Email/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ public function testInvalidEmailAddress($email): void
$this->assertFalse(Email::is_valid_address($email));
}

public function provideValidEmailAddresses(): array
public static function provideValidEmailAddresses(): array
{
return [
['[email protected]', '[email protected]'],
];
}

public function provideInvalidEmailAddresses(): array
public static function provideInvalidEmailAddresses(): array
{
return [
['foo.bar@', '@example.com', 'foo@'],
Expand Down Expand Up @@ -553,7 +553,7 @@ public function testCreateAddressArray(string|array $address, string $name, arra
}
}

public function provideCreateAddressArray(): array
public static function provideCreateAddressArray(): array
{
return [
[
Expand Down
29 changes: 27 additions & 2 deletions tests/php/Control/HTTPRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,35 @@
use SilverStripe\Control\Middleware\TrustedProxyMiddleware;
use SilverStripe\Control\Session;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Control\Tests\HTTPRequestTest\HTTPRequestTestException;

class HTTPRequestTest extends SapphireTest
{
protected static $fixture_file = null;

/**
* @param callable|null $oldHandler
*/
private $oldHandler = null;

protected function setup(): void
{
// Use custom error handler to allow the use of expectException() to catch warnings
// which is required in testWildCardWithFurtherParams().
// PHPUnit does not support expecting warnings
parent::setup();
$this->oldHandler = set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) {
throw new HTTPRequestTestException($errstr);
});
}

protected function tearDown(): void
{
restore_error_handler();
$this->oldHandler = null;
parent::tearDown();
}

public function testMatch()
{
$request = new HTTPRequest("GET", "admin/crm/add");
Expand Down Expand Up @@ -55,7 +79,8 @@ public function testWildCardMatch()
*/
public function testWildCardWithFurtherParams()
{
$this->expectWarning();
$this->expectException(HTTPRequestTestException::class);
$this->expectExceptionMessage('All URL params after wildcard parameter $@ will be ignored');
$request = new HTTPRequest('GET', 'admin/crm/test');
// all parameters after the first wildcard parameter are ignored
$request->match('admin/$Action/$@/$Other/$*', true);
Expand Down Expand Up @@ -150,7 +175,7 @@ public function detectMethodDataProvider()
];
}

public function setHttpMethodDataProvider()
public static function setHttpMethodDataProvider()
{
return [
'POST request' => ['POST','POST'],
Expand Down
10 changes: 10 additions & 0 deletions tests/php/Control/HTTPRequestTest/HTTPRequestTestException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace SilverStripe\Control\Tests\HTTPRequestTest;

use SilverStripe\Dev\TestOnly;
use Exception;

class HTTPRequestTestException extends Exception implements TestOnly
{
}
4 changes: 2 additions & 2 deletions tests/php/Control/HTTPResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testRemoveHeader()
$this->assertEmpty($response->getHeader('X-Animal'));
}

public function providerSanitiseHeaders()
public static function providerSanitiseHeaders()
{
return [
'plain text is retained' => ['some arbitrary value1', 'some arbitrary value1'],
Expand All @@ -65,7 +65,7 @@ public function testSanitiseHeaders(string $expected, string $value)
$this->assertSame($expected, $response->getHeader('X-Sanitised'));
}

public function providerTestValidStatusCodes()
public static function providerTestValidStatusCodes()
{
return [
[200, 'OK'],
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Control/Middleware/CanonicalURLMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function testGetForceBasicAuthToSSL()
$this->assertFalse($middleware->getForceBasicAuthToSSL(), 'Explicitly set is returned');
}

public function provideRedirectTrailingSlash()
public static function provideRedirectTrailingSlash()
{
$testScenarios = [];
foreach ([true, false] as $forceRedirect) {
Expand Down Expand Up @@ -147,7 +147,7 @@ private function performRedirectTest(string $requestURL, CanonicalURLMiddleware
}
}

public function provideRedirectTrailingSlashIgnorePaths()
public static function provideRedirectTrailingSlashIgnorePaths()
{
return [
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function setUp(): void
HTTPCacheControlMiddleware::reset();
}

public function provideCacheStates()
public static function provideCacheStates()
{
return [
['enableCache', false],
Expand Down
34 changes: 29 additions & 5 deletions tests/php/Control/RequestHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Control\RequestHandler;
use SilverStripe\Control\Tests\RequestHandlerTest\RequestHandlerTestException;
use SilverStripe\Dev\SapphireTest;

/**
Expand All @@ -14,7 +15,30 @@ class RequestHandlerTest extends SapphireTest
{
protected $usesDatabase = false;

public function provideTestLink(): array
/**
* @param callable|null $oldHandler
*/
private $oldHandler = null;

protected function setup(): void
{
// Use custom error handler to allow the use of expectException() to catch warnings
// which is required in testLink() and testAbsoluteLink() which expect warnings.
// PHPUnit does not support expecting warnings
parent::setup();
$this->oldHandler = set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) {
throw new RequestHandlerTestException($errstr);
});
}

protected function tearDown(): void
{
restore_error_handler();
$this->oldHandler = null;
parent::tearDown();
}

public static function provideTestLink(): array
{
return [
// If there's no url segment, there's no link
Expand Down Expand Up @@ -48,8 +72,8 @@ public function provideTestLink(): array
public function testLink(?string $urlSegment, ?string $action, ?string $expected)
{
if ($urlSegment === null) {
$this->expectWarning();
$this->expectWarningMessage('Request handler SilverStripe\Control\RequestHandler does not have a url_segment defined. Relying on this link may be an application error');
$this->expectException(RequestHandlerTestException::class);
$this->expectExceptionMessage('Request handler SilverStripe\Control\RequestHandler does not have a url_segment defined. Relying on this link may be an application error');
}

$handler = new RequestHandler();
Expand All @@ -73,8 +97,8 @@ public function testLink(?string $urlSegment, ?string $action, ?string $expected
public function testAbsoluteLink(?string $urlSegment, ?string $action, ?string $expected)
{
if ($urlSegment === null) {
$this->expectWarning();
$this->expectWarningMessage('Request handler SilverStripe\Control\RequestHandler does not have a url_segment defined. Relying on this link may be an application error');
$this->expectException(RequestHandlerTestException::class);
$this->expectExceptionMessage('Request handler SilverStripe\Control\RequestHandler does not have a url_segment defined. Relying on this link may be an application error');
}

$handler = new RequestHandler();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace SilverStripe\Control\Tests\RequestHandlerTest;

use SilverStripe\Dev\TestOnly;
use Exception;

class RequestHandlerTestException extends Exception implements TestOnly
{
}
2 changes: 1 addition & 1 deletion tests/php/Control/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ public function testBuildCookieParams(): void
);
}

public function provideSecureSamesiteData(): array
public static function provideSecureSamesiteData(): array
{
$data = [];
foreach ([true, false] as $secure) {
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Core/Cache/DefaultCacheFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class DefaultCacheFactoryTest extends SapphireTest
{
public function provideCreate(): array
public static function provideCreate(): array
{
$scenarios = [
[
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Core/ClassInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public function testHasMethod($object, $method, $output)
);
}

public function provideHasMethodCases()
public static function provideHasMethodCases()
{
return [
'Basic object' => [
Expand Down Expand Up @@ -336,7 +336,7 @@ public function testParseClassSpec($input, $output)
);
}

public function provideClassSpecCases()
public static function provideClassSpecCases()
{
return [
'Standard class' => [
Expand Down
6 changes: 3 additions & 3 deletions tests/php/Core/ConvertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public function testMemString2Bytes($memString, $expected)
/**
* @return array
*/
public function memString2BytesProvider()
public static function memString2BytesProvider()
{
return [
'infinite' => ['-1', -1],
Expand Down Expand Up @@ -459,7 +459,7 @@ public function testBytes2MemString($bytes, $expected)
/**
* @return array
*/
public function bytes2MemStringProvider()
public static function bytes2MemStringProvider()
{
return [
[0, '0B'],
Expand All @@ -472,7 +472,7 @@ public function bytes2MemStringProvider()
];
}

public function providerTestSlashes()
public static function providerTestSlashes()
{
return [
['bob/bob', '/', true, 'bob/bob'],
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Core/EnvironmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class EnvironmentTest extends SapphireTest
{
public function providerTestPutEnv()
public static function providerTestPutEnv()
{
return [
['_ENVTEST_BOOL=true', '_ENVTEST_BOOL', true],
Expand Down Expand Up @@ -68,7 +68,7 @@ public function testGetVariables()
$this->assertEquals('global', $GLOBALS['test']);
}

public function provideHasEnv()
public static function provideHasEnv()
{
$setAsOptions = [
'.env',
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Core/Injector/InjectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ public function testConvertServicePropertyBackTicks($value, $expected)
$this->assertSame($expected, $actual);
}

public function provideConvertServicePropertyBackTicks()
public static function provideConvertServicePropertyBackTicks()
{
return [
['`INJECTOR_TEST_CSP_A`', 'ABC'],
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Core/Manifest/ClassManifestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function setUp(): void
/**
* @return array
*/
public function providerTestGetItemPath()
public static function providerTestGetItemPath()
{
$paths = [
['CLASSA', 'module/classes/ClassA.php'],
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Core/Manifest/ModuleManifestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function testGetResourcePathOnRoot()
/**
* @return array
*/
public function providerTestGetModuleByPath()
public static function providerTestGetModuleByPath()
{
return [
['vendor/silverstripe/modulec/code/VendorClassA.php', 'silverstripe/modulec'],
Expand Down
Loading

0 comments on commit aff6913

Please sign in to comment.