Skip to content

Commit b805b16

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.6
2 parents d4fee13 + ab64aeb commit b805b16

File tree

7 files changed

+134
-7
lines changed

7 files changed

+134
-7
lines changed

phpstan-baseline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3070,7 +3070,7 @@
30703070
$ignoreErrors[] = [
30713071
// identifier: empty.notAllowed
30723072
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
3073-
'count' => 5,
3073+
'count' => 2,
30743074
'path' => __DIR__ . '/system/Database/OCI8/Connection.php',
30753075
];
30763076
$ignoreErrors[] = [

system/CLI/Commands.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function discoverCommands()
125125
/** @var BaseCommand $class */
126126
$class = new $className($this->logger, $this);
127127

128-
if (isset($class->group)) {
128+
if (isset($class->group) && ! isset($this->commands[$class->name])) {
129129
$this->commands[$class->name] = [
130130
'class' => $className,
131131
'file' => $file,

system/Database/OCI8/Connection.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ class Connection extends BaseConnection
104104
*/
105105
private function isValidDSN(): bool
106106
{
107+
if ($this->DSN === null || $this->DSN === '') {
108+
return false;
109+
}
110+
107111
foreach ($this->validDSNs as $regexp) {
108112
if (preg_match($regexp, $this->DSN)) {
109113
return true;
@@ -120,13 +124,13 @@ private function isValidDSN(): bool
120124
*/
121125
public function connect(bool $persistent = false)
122126
{
123-
if (empty($this->DSN) && ! $this->isValidDSN()) {
127+
if (! $this->isValidDSN()) {
124128
$this->buildDSN();
125129
}
126130

127131
$func = $persistent ? 'oci_pconnect' : 'oci_connect';
128132

129-
return empty($this->charset)
133+
return ($this->charset === '')
130134
? $func($this->username, $this->password, $this->DSN)
131135
: $func($this->username, $this->password, $this->DSN, $this->charset);
132136
}
@@ -632,7 +636,7 @@ protected function buildDSN()
632636
}
633637

634638
$isEasyConnectableHostName = $this->hostname !== '' && ! str_contains($this->hostname, '/') && ! str_contains($this->hostname, ':');
635-
$easyConnectablePort = ! empty($this->port) && ctype_digit($this->port) ? ':' . $this->port : '';
639+
$easyConnectablePort = ($this->port !== '') && ctype_digit((string) $this->port) ? ':' . $this->port : '';
636640
$easyConnectableDatabase = $this->database !== '' ? '/' . ltrim($this->database, '/') : '';
637641

638642
if ($isEasyConnectableHostName && ($easyConnectablePort !== '' || $easyConnectableDatabase !== '')) {
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of CodeIgniter 4 framework.
7+
*
8+
* (c) CodeIgniter Foundation <[email protected]>
9+
*
10+
* For the full copyright and license information, please view
11+
* the LICENSE file that was distributed with this source code.
12+
*/
13+
14+
namespace App\Commands;
15+
16+
use CodeIgniter\CLI\CLI;
17+
use CodeIgniter\Commands\ListCommands as BaseListCommands;
18+
19+
class ListCommands extends BaseListCommands
20+
{
21+
/**
22+
* The group the command is lumped under
23+
* when listing commands.
24+
*
25+
* @var string
26+
*/
27+
protected $group = 'App';
28+
29+
/**
30+
* The Command's name
31+
*
32+
* @var string
33+
*/
34+
protected $name = 'list';
35+
36+
/**
37+
* the Command's short description
38+
*
39+
* @var string
40+
*/
41+
protected $description = 'This is testing to override `list` command.';
42+
43+
/**
44+
* the Command's usage
45+
*
46+
* @var string
47+
*/
48+
protected $usage = 'list';
49+
50+
/**
51+
* Displays the help for the spark cli script itself.
52+
*/
53+
public function run(array $params)
54+
{
55+
CLI::write('This is ' . self::class);
56+
57+
return EXIT_SUCCESS;
58+
}
59+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of CodeIgniter 4 framework.
7+
*
8+
* (c) CodeIgniter Foundation <[email protected]>
9+
*
10+
* For the full copyright and license information, please view
11+
* the LICENSE file that was distributed with this source code.
12+
*/
13+
14+
namespace CodeIgniter\Commands;
15+
16+
use CodeIgniter\Test\CIUnitTestCase;
17+
use CodeIgniter\Test\StreamFilterTrait;
18+
use PHPUnit\Framework\Attributes\Group;
19+
20+
/**
21+
* @internal
22+
*/
23+
#[Group('Others')]
24+
final class CommandOverrideTest extends CIUnitTestCase
25+
{
26+
use StreamFilterTrait;
27+
28+
protected function setUp(): void
29+
{
30+
$this->resetServices();
31+
32+
parent::setUp();
33+
}
34+
35+
protected function getBuffer(): string
36+
{
37+
return $this->getStreamFilterBuffer();
38+
}
39+
40+
public function testOverrideListCommands(): void
41+
{
42+
$this->copyListCommands();
43+
44+
command('list');
45+
46+
$this->assertStringContainsString('This is App\Commands\ListCommands', $this->getBuffer());
47+
$this->assertStringNotContainsString('Displays basic usage information.', $this->getBuffer());
48+
49+
$this->deleteListCommands();
50+
}
51+
52+
private function copyListCommands(): void
53+
{
54+
if (! is_dir(APPPATH . 'Commands')) {
55+
mkdir(APPPATH . 'Commands');
56+
}
57+
copy(SUPPORTPATH . '_command/ListCommands.php', APPPATH . 'Commands/ListCommands.php');
58+
}
59+
60+
private function deleteListCommands(): void
61+
{
62+
unlink(APPPATH . 'Commands/ListCommands.php');
63+
}
64+
}

tests/system/Config/BaseConfigTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function testEnvironmentOverrides(): void
131131
// override config with shortPrefix ENV var
132132
$this->assertSame('hubbahubba', $config->delta);
133133
// incorrect env name should not inject property
134-
$this->assertFalse(property_exists($config, 'notthere'));
134+
$this->assertObjectNotHasProperty('notthere', $config);
135135
// empty ENV var should not affect config setting
136136
$this->assertSame('pineapple', $config->fruit);
137137
// non-empty ENV var should overrideconfig setting

tests/system/Test/FabricatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ public function testCreateMockSetsDatabaseFields(): void
413413
$this->assertIsInt($result->created_at);
414414
$this->assertIsInt($result->updated_at);
415415

416-
$this->assertTrue(property_exists($result, 'deleted_at'));
416+
$this->assertObjectHasProperty('deleted_at', $result);
417417
$this->assertNull($result->deleted_at);
418418
}
419419

0 commit comments

Comments
 (0)