Skip to content

Commit 9fba8c7

Browse files
committed
Merge branch 'develop' into 4.6
2 parents cdf78ab + 4c8b782 commit 9fba8c7

File tree

9 files changed

+118
-227
lines changed

9 files changed

+118
-227
lines changed

phpstan-baseline.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12133,12 +12133,6 @@
1213312133
'count' => 1,
1213412134
'path' => __DIR__ . '/tests/system/Commands/Translation/LocalizationFinderTest.php',
1213512135
];
12136-
$ignoreErrors[] = [
12137-
// identifier: missingType.return
12138-
'message' => '#^Method CodeIgniter\\\\Commands\\\\Utilities\\\\ConfigCheckTest\\:\\:getBuffer\\(\\) has no return type specified\\.$#',
12139-
'count' => 1,
12140-
'path' => __DIR__ . '/tests/system/Commands/Utilities/ConfigCheckTest.php',
12141-
];
1214212136
$ignoreErrors[] = [
1214312137
// identifier: missingType.return
1214412138
'message' => '#^Method CodeIgniter\\\\Commands\\\\Utilities\\\\NamespacesTest\\:\\:getBuffer\\(\\) has no return type specified\\.$#',

system/Config/Services.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public static function curlrequest(array $options = [], ?ResponseInterface $resp
211211

212212
return new CURLRequest(
213213
$config,
214-
new URI($options['base_uri'] ?? null),
214+
new URI($options['baseURI'] ?? null),
215215
$response,
216216
$options
217217
);

system/Database/Postgre/Connection.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ private function convertDSN()
150150
*/
151151
public function reconnect()
152152
{
153-
if (pg_ping($this->connID) === false) {
154-
$this->connID = false;
153+
if ($this->connID === false || pg_ping($this->connID) === false) {
154+
$this->close();
155+
$this->initialize();
155156
}
156157
}
157158

system/HTTP/ContentSecurityPolicy.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,9 @@ public function reportOnly(bool $value = true)
356356
}
357357

358358
/**
359-
* Adds a new base_uri value. Can be either a URI class or a simple string.
359+
* Adds a new baseURI value. Can be either a URI class or a simple string.
360360
*
361-
* base_uri restricts the URLs that can appear in a page's <base> element.
361+
* baseURI restricts the URLs that can appear in a page's <base> element.
362362
*
363363
* @see http://www.w3.org/TR/CSP/#directive-base-uri
364364
*

tests/system/Commands/Utilities/ConfigCheckTest.php

Lines changed: 66 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313

1414
namespace CodeIgniter\Commands\Utilities;
1515

16+
use Closure;
1617
use CodeIgniter\Test\CIUnitTestCase;
1718
use CodeIgniter\Test\StreamFilterTrait;
1819
use Config\App;
20+
use Kint\Kint;
21+
use Kint\Renderer\CliRenderer;
1922
use PHPUnit\Framework\Attributes\Group;
2023

2124
/**
@@ -26,6 +29,26 @@ final class ConfigCheckTest extends CIUnitTestCase
2629
{
2730
use StreamFilterTrait;
2831

32+
public static function setUpBeforeClass(): void
33+
{
34+
App::$override = false;
35+
36+
putenv('NO_COLOR=1');
37+
CliRenderer::$cli_colors = false;
38+
39+
parent::setUpBeforeClass();
40+
}
41+
42+
public static function tearDownAfterClass(): void
43+
{
44+
App::$override = true;
45+
46+
putenv('NO_COLOR');
47+
CliRenderer::$cli_colors = true;
48+
49+
parent::tearDownAfterClass();
50+
}
51+
2952
protected function setUp(): void
3053
{
3154
$this->resetServices();
@@ -38,188 +61,71 @@ protected function tearDown(): void
3861
parent::tearDown();
3962
}
4063

41-
protected function getBuffer()
42-
{
43-
return $this->getStreamFilterBuffer();
44-
}
45-
46-
public function testCommandConfigCheckNoArg(): void
64+
public function testCommandConfigCheckWithNoArgumentPassed(): void
4765
{
4866
command('config:check');
4967

50-
$this->assertStringContainsString(
51-
'You must specify a Config classname.',
52-
$this->getBuffer()
53-
);
54-
}
55-
56-
public function testCommandConfigCheckApp(): void
57-
{
58-
command('config:check App');
68+
$this->assertSame(
69+
<<<'EOF'
70+
You must specify a Config classname.
71+
Usage: config:check <classname>
72+
Example: config:check App
73+
config:check 'CodeIgniter\Shield\Config\Auth'
5974

60-
$this->assertStringContainsString(App::class, $this->getBuffer());
61-
$this->assertStringContainsString("public 'baseURL", $this->getBuffer());
75+
EOF,
76+
str_replace("\n\n", "\n", $this->getStreamFilterBuffer())
77+
);
6278
}
6379

6480
public function testCommandConfigCheckNonexistentClass(): void
6581
{
6682
command('config:check Nonexistent');
6783

68-
$this->assertStringContainsString(
69-
'No such Config class: Nonexistent',
70-
$this->getBuffer()
84+
$this->assertSame(
85+
"No such Config class: Nonexistent\n",
86+
$this->getStreamFilterBuffer()
7187
);
7288
}
7389

74-
public function testGetKintD(): void
90+
public function testConfigCheckWithKintEnabledUsesKintD(): void
7591
{
76-
$command = new ConfigCheck(service('logger'), service('commands'));
77-
$getKintD = $this->getPrivateMethodInvoker($command, 'getKintD');
78-
79-
$output = $getKintD(new App());
80-
81-
$output = preg_replace(
82-
'/(\033\[[0-9;]+m)|(\035\[[0-9;]+m)/u',
83-
'',
84-
$output
92+
/** @var Closure(object): string $command */
93+
$command = $this->getPrivateMethodInvoker(
94+
new ConfigCheck(service('logger'), service('commands')),
95+
'getKintD'
8596
);
8697

87-
$this->assertStringContainsString(
88-
'Config\App#',
89-
$output
90-
);
91-
$this->assertStringContainsString(
92-
<<<'EOL'
93-
(
94-
public 'baseURL' -> string (19) "http://example.com/"
95-
public 'allowedHostnames' -> array (0) []
96-
public 'indexPage' -> string (9) "index.php"
97-
public 'uriProtocol' -> string (11) "REQUEST_URI"
98-
public 'permittedURIChars' -> string (14) "a-z 0-9~%.:_\-"
99-
public 'defaultLocale' -> string (2) "en"
100-
public 'negotiateLocale' -> boolean false
101-
public 'supportedLocales' -> array (1) [
102-
0 => string (2) "en"
103-
]
104-
public 'appTimezone' -> string (3) "UTC"
105-
public 'charset' -> string (5) "UTF-8"
106-
public 'forceGlobalSecureRequests' -> boolean false
107-
public 'proxyIPs' -> array (0) []
108-
public 'CSPEnabled' -> boolean false
109-
EOL,
110-
$output
98+
command('config:check App');
99+
100+
$this->assertSame(
101+
$command(config('App')) . "\n",
102+
preg_replace('/\s+Config Caching: \S+/', '', $this->getStreamFilterBuffer())
111103
);
112104
}
113105

114-
public function testGetVarDump(): void
106+
public function testConfigCheckWithKintDisabledUsesVarDump(): void
115107
{
116-
$command = new ConfigCheck(service('logger'), service('commands'));
117-
$getVarDump = $this->getPrivateMethodInvoker($command, 'getVarDump');
118-
119-
$output = $getVarDump(new App());
120-
121-
if (
122-
ini_get('xdebug.mode')
123-
&& in_array(
124-
'develop',
125-
explode(',', ini_get('xdebug.mode')),
126-
true
127-
)
128-
) {
129-
// Xdebug force adds colors on xdebug.cli_color=2
130-
$output = preg_replace(
131-
'/(\033\[[0-9;]+m)|(\035\[[0-9;]+m)/u',
132-
'',
133-
$output
134-
);
108+
/** @var Closure(object): string $command */
109+
$command = $this->getPrivateMethodInvoker(
110+
new ConfigCheck(service('logger'), service('commands')),
111+
'getVarDump'
112+
);
113+
$clean = static fn (string $input): string => trim(preg_replace(
114+
'/(\033\[[0-9;]+m)|(\035\[[0-9;]+m)/u',
115+
'',
116+
$input
117+
));
135118

136-
// Xdebug overloads var_dump().
137-
$this->assertStringContainsString(
138-
'class Config\App#',
139-
$output
140-
);
141-
$this->assertStringContainsString(
142-
<<<'EOL'
143-
{
144-
public string $baseURL =>
145-
string(19) "http://example.com/"
146-
public array $allowedHostnames =>
147-
array(0) {
148-
}
149-
public string $indexPage =>
150-
string(9) "index.php"
151-
public string $uriProtocol =>
152-
string(11) "REQUEST_URI"
153-
public string $permittedURIChars =>
154-
string(14) "a-z 0-9~%.:_\-"
155-
public string $defaultLocale =>
156-
string(2) "en"
157-
public bool $negotiateLocale =>
158-
bool(false)
159-
public array $supportedLocales =>
160-
array(1) {
161-
[0] =>
162-
string(2) "en"
163-
}
164-
public string $appTimezone =>
165-
string(3) "UTC"
166-
public string $charset =>
167-
string(5) "UTF-8"
168-
public bool $forceGlobalSecureRequests =>
169-
bool(false)
170-
public array $proxyIPs =>
171-
array(0) {
172-
}
173-
public bool $CSPEnabled =>
174-
bool(false)
175-
}
176-
EOL,
177-
$output
178-
);
179-
} else {
180-
// PHP's var_dump().
181-
$this->assertStringContainsString(
182-
'object(Config\App)#',
183-
$output
184-
);
185-
$this->assertStringContainsString(
186-
<<<'EOL'
187-
{
188-
["baseURL"]=>
189-
string(19) "http://example.com/"
190-
["allowedHostnames"]=>
191-
array(0) {
192-
}
193-
["indexPage"]=>
194-
string(9) "index.php"
195-
["uriProtocol"]=>
196-
string(11) "REQUEST_URI"
197-
["permittedURIChars"]=>
198-
string(14) "a-z 0-9~%.:_\-"
199-
["defaultLocale"]=>
200-
string(2) "en"
201-
["negotiateLocale"]=>
202-
bool(false)
203-
["supportedLocales"]=>
204-
array(1) {
205-
[0]=>
206-
string(2) "en"
207-
}
208-
["appTimezone"]=>
209-
string(3) "UTC"
210-
["charset"]=>
211-
string(5) "UTF-8"
212-
["forceGlobalSecureRequests"]=>
213-
bool(false)
214-
["proxyIPs"]=>
215-
array(0) {
216-
}
217-
["CSPEnabled"]=>
218-
bool(false)
219-
}
220-
EOL,
221-
$output
119+
try {
120+
Kint::$enabled_mode = false;
121+
command('config:check App');
122+
123+
$this->assertSame(
124+
$clean($command(config('App'))),
125+
$clean(preg_replace('/\s+Config Caching: \S+/', '', $this->getStreamFilterBuffer()))
222126
);
127+
} finally {
128+
Kint::$enabled_mode = true;
223129
}
224130
}
225131
}

tests/system/HTTP/CURLRequestShareOptionsTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class CURLRequestShareOptionsTest extends CURLRequestTest
3030
{
3131
protected function getRequest(array $options = []): MockCURLRequest
3232
{
33-
$uri = isset($options['base_uri']) ? new URI($options['base_uri']) : new URI();
33+
$uri = isset($options['baseURI']) ? new URI($options['baseURI']) : new URI();
3434
$app = new App();
3535

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

@@ -61,8 +61,8 @@ public function testHeaderContentLengthNotSharedBetweenRequests(): void
6161
public function testBodyIsResetOnSecondRequest(): void
6262
{
6363
$request = $this->getRequest([
64-
'base_uri' => 'http://www.foo.com/api/v1/',
65-
'delay' => 100,
64+
'baseURI' => 'http://www.foo.com/api/v1/',
65+
'delay' => 100,
6666
]);
6767
$request->setBody('name=George');
6868
$request->setOutput('Hi there');

0 commit comments

Comments
 (0)