Skip to content

Commit

Permalink
Merge branch 'develop' into 4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan committed Dec 1, 2024
2 parents cdf78ab + 4c8b782 commit 9fba8c7
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 227 deletions.
6 changes: 0 additions & 6 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -12133,12 +12133,6 @@
'count' => 1,
'path' => __DIR__ . '/tests/system/Commands/Translation/LocalizationFinderTest.php',
];
$ignoreErrors[] = [
// identifier: missingType.return
'message' => '#^Method CodeIgniter\\\\Commands\\\\Utilities\\\\ConfigCheckTest\\:\\:getBuffer\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/Commands/Utilities/ConfigCheckTest.php',
];
$ignoreErrors[] = [
// identifier: missingType.return
'message' => '#^Method CodeIgniter\\\\Commands\\\\Utilities\\\\NamespacesTest\\:\\:getBuffer\\(\\) has no return type specified\\.$#',
Expand Down
2 changes: 1 addition & 1 deletion system/Config/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public static function curlrequest(array $options = [], ?ResponseInterface $resp

return new CURLRequest(
$config,
new URI($options['base_uri'] ?? null),
new URI($options['baseURI'] ?? null),
$response,
$options
);
Expand Down
5 changes: 3 additions & 2 deletions system/Database/Postgre/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ private function convertDSN()
*/
public function reconnect()
{
if (pg_ping($this->connID) === false) {
$this->connID = false;
if ($this->connID === false || pg_ping($this->connID) === false) {
$this->close();
$this->initialize();
}
}

Expand Down
4 changes: 2 additions & 2 deletions system/HTTP/ContentSecurityPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,9 @@ public function reportOnly(bool $value = true)
}

/**
* Adds a new base_uri value. Can be either a URI class or a simple string.
* Adds a new baseURI value. Can be either a URI class or a simple string.
*
* base_uri restricts the URLs that can appear in a page's <base> element.
* baseURI restricts the URLs that can appear in a page's <base> element.
*
* @see http://www.w3.org/TR/CSP/#directive-base-uri
*
Expand Down
226 changes: 66 additions & 160 deletions tests/system/Commands/Utilities/ConfigCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@

namespace CodeIgniter\Commands\Utilities;

use Closure;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\StreamFilterTrait;
use Config\App;
use Kint\Kint;
use Kint\Renderer\CliRenderer;
use PHPUnit\Framework\Attributes\Group;

/**
Expand All @@ -26,6 +29,26 @@ final class ConfigCheckTest extends CIUnitTestCase
{
use StreamFilterTrait;

public static function setUpBeforeClass(): void
{
App::$override = false;

putenv('NO_COLOR=1');
CliRenderer::$cli_colors = false;

parent::setUpBeforeClass();
}

public static function tearDownAfterClass(): void
{
App::$override = true;

putenv('NO_COLOR');
CliRenderer::$cli_colors = true;

parent::tearDownAfterClass();
}

protected function setUp(): void
{
$this->resetServices();
Expand All @@ -38,188 +61,71 @@ protected function tearDown(): void
parent::tearDown();
}

protected function getBuffer()
{
return $this->getStreamFilterBuffer();
}

public function testCommandConfigCheckNoArg(): void
public function testCommandConfigCheckWithNoArgumentPassed(): void
{
command('config:check');

$this->assertStringContainsString(
'You must specify a Config classname.',
$this->getBuffer()
);
}

public function testCommandConfigCheckApp(): void
{
command('config:check App');
$this->assertSame(
<<<'EOF'
You must specify a Config classname.
Usage: config:check <classname>
Example: config:check App
config:check 'CodeIgniter\Shield\Config\Auth'

$this->assertStringContainsString(App::class, $this->getBuffer());
$this->assertStringContainsString("public 'baseURL", $this->getBuffer());
EOF,
str_replace("\n\n", "\n", $this->getStreamFilterBuffer())
);
}

public function testCommandConfigCheckNonexistentClass(): void
{
command('config:check Nonexistent');

$this->assertStringContainsString(
'No such Config class: Nonexistent',
$this->getBuffer()
$this->assertSame(
"No such Config class: Nonexistent\n",
$this->getStreamFilterBuffer()
);
}

public function testGetKintD(): void
public function testConfigCheckWithKintEnabledUsesKintD(): void
{
$command = new ConfigCheck(service('logger'), service('commands'));
$getKintD = $this->getPrivateMethodInvoker($command, 'getKintD');

$output = $getKintD(new App());

$output = preg_replace(
'/(\033\[[0-9;]+m)|(\035\[[0-9;]+m)/u',
'',
$output
/** @var Closure(object): string $command */
$command = $this->getPrivateMethodInvoker(
new ConfigCheck(service('logger'), service('commands')),
'getKintD'
);

$this->assertStringContainsString(
'Config\App#',
$output
);
$this->assertStringContainsString(
<<<'EOL'
(
public 'baseURL' -> string (19) "http://example.com/"
public 'allowedHostnames' -> array (0) []
public 'indexPage' -> string (9) "index.php"
public 'uriProtocol' -> string (11) "REQUEST_URI"
public 'permittedURIChars' -> string (14) "a-z 0-9~%.:_\-"
public 'defaultLocale' -> string (2) "en"
public 'negotiateLocale' -> boolean false
public 'supportedLocales' -> array (1) [
0 => string (2) "en"
]
public 'appTimezone' -> string (3) "UTC"
public 'charset' -> string (5) "UTF-8"
public 'forceGlobalSecureRequests' -> boolean false
public 'proxyIPs' -> array (0) []
public 'CSPEnabled' -> boolean false
EOL,
$output
command('config:check App');

$this->assertSame(
$command(config('App')) . "\n",
preg_replace('/\s+Config Caching: \S+/', '', $this->getStreamFilterBuffer())
);
}

public function testGetVarDump(): void
public function testConfigCheckWithKintDisabledUsesVarDump(): void
{
$command = new ConfigCheck(service('logger'), service('commands'));
$getVarDump = $this->getPrivateMethodInvoker($command, 'getVarDump');

$output = $getVarDump(new App());

if (
ini_get('xdebug.mode')
&& in_array(
'develop',
explode(',', ini_get('xdebug.mode')),
true
)
) {
// Xdebug force adds colors on xdebug.cli_color=2
$output = preg_replace(
'/(\033\[[0-9;]+m)|(\035\[[0-9;]+m)/u',
'',
$output
);
/** @var Closure(object): string $command */
$command = $this->getPrivateMethodInvoker(
new ConfigCheck(service('logger'), service('commands')),
'getVarDump'
);
$clean = static fn (string $input): string => trim(preg_replace(
'/(\033\[[0-9;]+m)|(\035\[[0-9;]+m)/u',
'',
$input
));

// Xdebug overloads var_dump().
$this->assertStringContainsString(
'class Config\App#',
$output
);
$this->assertStringContainsString(
<<<'EOL'
{
public string $baseURL =>
string(19) "http://example.com/"
public array $allowedHostnames =>
array(0) {
}
public string $indexPage =>
string(9) "index.php"
public string $uriProtocol =>
string(11) "REQUEST_URI"
public string $permittedURIChars =>
string(14) "a-z 0-9~%.:_\-"
public string $defaultLocale =>
string(2) "en"
public bool $negotiateLocale =>
bool(false)
public array $supportedLocales =>
array(1) {
[0] =>
string(2) "en"
}
public string $appTimezone =>
string(3) "UTC"
public string $charset =>
string(5) "UTF-8"
public bool $forceGlobalSecureRequests =>
bool(false)
public array $proxyIPs =>
array(0) {
}
public bool $CSPEnabled =>
bool(false)
}
EOL,
$output
);
} else {
// PHP's var_dump().
$this->assertStringContainsString(
'object(Config\App)#',
$output
);
$this->assertStringContainsString(
<<<'EOL'
{
["baseURL"]=>
string(19) "http://example.com/"
["allowedHostnames"]=>
array(0) {
}
["indexPage"]=>
string(9) "index.php"
["uriProtocol"]=>
string(11) "REQUEST_URI"
["permittedURIChars"]=>
string(14) "a-z 0-9~%.:_\-"
["defaultLocale"]=>
string(2) "en"
["negotiateLocale"]=>
bool(false)
["supportedLocales"]=>
array(1) {
[0]=>
string(2) "en"
}
["appTimezone"]=>
string(3) "UTC"
["charset"]=>
string(5) "UTF-8"
["forceGlobalSecureRequests"]=>
bool(false)
["proxyIPs"]=>
array(0) {
}
["CSPEnabled"]=>
bool(false)
}
EOL,
$output
try {
Kint::$enabled_mode = false;
command('config:check App');

$this->assertSame(
$clean($command(config('App'))),
$clean(preg_replace('/\s+Config Caching: \S+/', '', $this->getStreamFilterBuffer()))
);
} finally {
Kint::$enabled_mode = true;
}
}
}
8 changes: 4 additions & 4 deletions tests/system/HTTP/CURLRequestShareOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class CURLRequestShareOptionsTest extends CURLRequestTest
{
protected function getRequest(array $options = []): MockCURLRequest
{
$uri = isset($options['base_uri']) ? new URI($options['base_uri']) : new URI();
$uri = isset($options['baseURI']) ? new URI($options['baseURI']) : new URI();
$app = new App();

$config = new ConfigCURLRequest();
Expand All @@ -43,7 +43,7 @@ protected function getRequest(array $options = []): MockCURLRequest
public function testHeaderContentLengthNotSharedBetweenRequests(): void
{
$options = [
'base_uri' => 'http://www.foo.com/api/v1/',
'baseURI' => 'http://www.foo.com/api/v1/',
];
$request = $this->getRequest($options);

Expand All @@ -61,8 +61,8 @@ public function testHeaderContentLengthNotSharedBetweenRequests(): void
public function testBodyIsResetOnSecondRequest(): void
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 100,
'baseURI' => 'http://www.foo.com/api/v1/',
'delay' => 100,
]);
$request->setBody('name=George');
$request->setOutput('Hi there');
Expand Down
Loading

0 comments on commit 9fba8c7

Please sign in to comment.