Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into 4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Jun 24, 2024
2 parents d4fee13 + ab64aeb commit b805b16
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 7 deletions.
2 changes: 1 addition & 1 deletion phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -3070,7 +3070,7 @@
$ignoreErrors[] = [
// identifier: empty.notAllowed
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 5,
'count' => 2,
'path' => __DIR__ . '/system/Database/OCI8/Connection.php',
];
$ignoreErrors[] = [
Expand Down
2 changes: 1 addition & 1 deletion system/CLI/Commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function discoverCommands()
/** @var BaseCommand $class */
$class = new $className($this->logger, $this);

if (isset($class->group)) {
if (isset($class->group) && ! isset($this->commands[$class->name])) {
$this->commands[$class->name] = [
'class' => $className,
'file' => $file,
Expand Down
10 changes: 7 additions & 3 deletions system/Database/OCI8/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ class Connection extends BaseConnection
*/
private function isValidDSN(): bool
{
if ($this->DSN === null || $this->DSN === '') {
return false;
}

foreach ($this->validDSNs as $regexp) {
if (preg_match($regexp, $this->DSN)) {
return true;
Expand All @@ -120,13 +124,13 @@ private function isValidDSN(): bool
*/
public function connect(bool $persistent = false)
{
if (empty($this->DSN) && ! $this->isValidDSN()) {
if (! $this->isValidDSN()) {
$this->buildDSN();
}

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

return empty($this->charset)
return ($this->charset === '')
? $func($this->username, $this->password, $this->DSN)
: $func($this->username, $this->password, $this->DSN, $this->charset);
}
Expand Down Expand Up @@ -632,7 +636,7 @@ protected function buildDSN()
}

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

if ($isEasyConnectableHostName && ($easyConnectablePort !== '' || $easyConnectableDatabase !== '')) {
Expand Down
59 changes: 59 additions & 0 deletions tests/_support/_command/ListCommands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <[email protected]>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace App\Commands;

use CodeIgniter\CLI\CLI;
use CodeIgniter\Commands\ListCommands as BaseListCommands;

class ListCommands extends BaseListCommands
{
/**
* The group the command is lumped under
* when listing commands.
*
* @var string
*/
protected $group = 'App';

/**
* The Command's name
*
* @var string
*/
protected $name = 'list';

/**
* the Command's short description
*
* @var string
*/
protected $description = 'This is testing to override `list` command.';

/**
* the Command's usage
*
* @var string
*/
protected $usage = 'list';

/**
* Displays the help for the spark cli script itself.
*/
public function run(array $params)
{
CLI::write('This is ' . self::class);

return EXIT_SUCCESS;
}
}
64 changes: 64 additions & 0 deletions tests/system/Commands/CommandOverrideTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <[email protected]>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace CodeIgniter\Commands;

use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\StreamFilterTrait;
use PHPUnit\Framework\Attributes\Group;

/**
* @internal
*/
#[Group('Others')]
final class CommandOverrideTest extends CIUnitTestCase
{
use StreamFilterTrait;

protected function setUp(): void
{
$this->resetServices();

parent::setUp();
}

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

public function testOverrideListCommands(): void
{
$this->copyListCommands();

command('list');

$this->assertStringContainsString('This is App\Commands\ListCommands', $this->getBuffer());
$this->assertStringNotContainsString('Displays basic usage information.', $this->getBuffer());

$this->deleteListCommands();
}

private function copyListCommands(): void
{
if (! is_dir(APPPATH . 'Commands')) {
mkdir(APPPATH . 'Commands');
}
copy(SUPPORTPATH . '_command/ListCommands.php', APPPATH . 'Commands/ListCommands.php');
}

private function deleteListCommands(): void
{
unlink(APPPATH . 'Commands/ListCommands.php');
}
}
2 changes: 1 addition & 1 deletion tests/system/Config/BaseConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function testEnvironmentOverrides(): void
// override config with shortPrefix ENV var
$this->assertSame('hubbahubba', $config->delta);
// incorrect env name should not inject property
$this->assertFalse(property_exists($config, 'notthere'));
$this->assertObjectNotHasProperty('notthere', $config);
// empty ENV var should not affect config setting
$this->assertSame('pineapple', $config->fruit);
// non-empty ENV var should overrideconfig setting
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Test/FabricatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public function testCreateMockSetsDatabaseFields(): void
$this->assertIsInt($result->created_at);
$this->assertIsInt($result->updated_at);

$this->assertTrue(property_exists($result, 'deleted_at'));
$this->assertObjectHasProperty('deleted_at', $result);
$this->assertNull($result->deleted_at);
}

Expand Down

0 comments on commit b805b16

Please sign in to comment.