Skip to content

Commit

Permalink
WIP: Update test and cs-fix
Browse files Browse the repository at this point in the history
Signed-off-by: neznaika0 <[email protected]>
  • Loading branch information
neznaika0 committed Dec 14, 2024
1 parent 77b85c4 commit ea9be93
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 86 deletions.
14 changes: 4 additions & 10 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -12235,12 +12235,6 @@
'count' => 1,
'path' => __DIR__ . '/tests/system/CommonFunctionsTest.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\CommonFunctionsTest\\:\\:provideCleanPathActuallyCleaningThePaths\\(\\) return type has no value type specified in iterable type iterable\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/CommonFunctionsTest.php',
];
$ignoreErrors[] = [
// identifier: codeigniter.modelArgumentType
'message' => '#^Parameter \\#1 \\$name of function model expects a valid class string, \'JobModel\' given\\.$#',
Expand Down Expand Up @@ -13071,15 +13065,15 @@
];
$ignoreErrors[] = [
// identifier: property.notFound
'message' => '#^Access to an undefined property CodeIgniter\\\\Database\\\\BaseConnection\\:\\:\\$numberNative\\.$#',
'message' => '#^Access to an undefined property CodeIgniter\\\\Database\\\\BaseConnection\\:\\:\\$foundRows\\.$#',
'count' => 2,
'path' => __DIR__ . '/tests/system/Database/Live/MySQLi/NumberNativeTest.php',
'path' => __DIR__ . '/tests/system/Database/Live/MySQLi/FoundRowsTest.php',
];
$ignoreErrors[] = [
// identifier: property.notFound
'message' => '#^Access to an undefined property CodeIgniter\\\\Database\\\\BaseConnection\\:\\:\\$foundRows\\.$#',
'message' => '#^Access to an undefined property CodeIgniter\\\\Database\\\\BaseConnection\\:\\:\\$numberNative\\.$#',
'count' => 2,
'path' => __DIR__ . '/tests/system/Database/Live/MySQLi/FoundRowsTest.php',
'path' => __DIR__ . '/tests/system/Database/Live/MySQLi/NumberNativeTest.php',
];
$ignoreErrors[] = [
// identifier: missingType.property
Expand Down
6 changes: 1 addition & 5 deletions system/Autoloader/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,7 @@ private function loadComposerNamespaces(ClassLoader $composer, array $composerPa

$newPaths = [];

$namespacePaths = array_map(static function (array $paths) {
return array_map(function(string $path) {
return normalize_path($path);
}, $paths);
}, $namespacePaths);
$namespacePaths = array_map(static fn (array $paths) => array_map(static fn (string $path) => normalize_path($path), $paths), $namespacePaths);

foreach ($namespacePaths as $namespace => $srcPaths) {
$add = false;
Expand Down
4 changes: 2 additions & 2 deletions system/CLI/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public static function promptByMultipleKeys(string $text, array $options): array
$optsKey[] = $key;
}
$extraOutput = '[' . $extraOutputDefault . ', ' . implode(', ', $optsKey) . ']';
$extraOutput = 'You can specify multiple values separated by commas.' . "/n" . $extraOutput;
$extraOutput = 'You can specify multiple values separated by commas./n' . $extraOutput;
}

CLI::write($text);
Expand Down Expand Up @@ -1098,7 +1098,7 @@ public static function table(array $tbody, array $thead = [])
}

// Set the columns borders
$table .= '| ' . implode(' | ', $tableRows[$row]) . ' |' . "\n";
$table .= '| ' . implode(' | ', $tableRows[$row]) . " |\n";

// Set the thead and table borders-bottom
if (($row === 0 && $thead !== []) || ($row + 1 === $totalRows)) {
Expand Down
2 changes: 1 addition & 1 deletion system/Commands/Translation/LocalizationFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private function findTranslationsInFile($file): array
}

foreach ($matches[1] as $phraseKey) {
$phraseKeys = explode('.', $phraseKey);
$phraseKeys = explode('.', $phraseKey);
$realPathFile = normalize_path($file->getRealPath());

// Language key not have Filename or Lang key
Expand Down
1 change: 0 additions & 1 deletion system/Commands/Utilities/ConfigCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use CodeIgniter\CLI\CLI;
use CodeIgniter\Config\BaseConfig;
use Config\Optimize;
use Ergebnis\Json\Json;
use Kint\Kint;

/**
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/filesystem_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ function get_file_info(string $file, $returnedValues = ['name', 'server_path', '
{
$file = _realpath($file);

if ($file !== false && ! is_file($file)) {
if ($file === false || ! is_file($file)) {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions system/View/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n
$this->renderVars['file'] = clean_path($this->renderVars['file']);
$this->renderVars['file'] = ++$this->viewsCount . ' ' . $this->renderVars['file'];

$output = '<!-- DEBUG-VIEW START ' . $this->renderVars['file'] . ' -->' . "\n"
$output = '<!-- DEBUG-VIEW START ' . $this->renderVars['file'] . " -->\n"
. $output . "\n"
. '<!-- DEBUG-VIEW ENDED ' . $this->renderVars['file'] . ' -->' . "\n";
. '<!-- DEBUG-VIEW ENDED ' . $this->renderVars['file'] . " -->\n";
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/system/Autoloader/FileLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public function testListFilesSimple(): void
{
$files = $this->locator->listFiles('Config/');

$this->assertTrue(in_array(APPPATH . 'Config/App.php', $files, true));
$this->assertContains(APPPATH . 'Config/App.php', $files);
}

public function testListFilesDoesNotContainDirectories(): void
Expand Down
102 changes: 51 additions & 51 deletions tests/system/CLI/CLITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,31 +323,31 @@ public function testWrite(): void
{
CLI::write('test');

$expected = "\n" . 'test' . "\n";
$expected = "\ntest\n";
$this->assertSame($expected, $this->getStreamFilterBuffer());
}

public function testWriteForeground(): void
{
CLI::write('test', 'red');

$expected = "\033[0;31mtest\033[0m" . "\n";
$expected = "\033[0;31mtest\033[0m\n";
$this->assertSame($expected, $this->getStreamFilterBuffer());
}

public function testWriteForegroundWithColorBefore(): void
{
CLI::write(CLI::color('green', 'green') . ' red', 'red');

$expected = "\033[0;32mgreen\033[0m\033[0;31m red\033[0m" . "\n";
$expected = "\033[0;32mgreen\033[0m\033[0;31m red\033[0m\n";
$this->assertSame($expected, $this->getStreamFilterBuffer());
}

public function testWriteForegroundWithColorAfter(): void
{
CLI::write('red ' . CLI::color('green', 'green'), 'red');

$expected = "\033[0;31mred \033[0m\033[0;32mgreen\033[0m" . "\n";
$expected = "\033[0;31mred \033[0m\033[0;32mgreen\033[0m\n";
$this->assertSame($expected, $this->getStreamFilterBuffer());
}

Expand All @@ -361,15 +361,15 @@ public function testWriteForegroundWithColorTwice(): void
'red'
);

$expected = "\033[0;32mgreen\033[0m\033[0;31m red \033[0m\033[0;32mgreen\033[0m" . "\n";
$expected = "\033[0;32mgreen\033[0m\033[0;31m red \033[0m\033[0;32mgreen\033[0m\n";
$this->assertSame($expected, $this->getStreamFilterBuffer());
}

public function testWriteBackground(): void
{
CLI::write('test', 'red', 'green');

$expected = "\033[0;31m\033[42mtest\033[0m" . "\n";
$expected = "\033[0;31m\033[42mtest\033[0m\n";
$this->assertSame($expected, $this->getStreamFilterBuffer());
}

Expand All @@ -378,23 +378,23 @@ public function testError(): void
CLI::error('test');

// red expected cuz stderr
$expected = "\033[1;31mtest\033[0m" . "\n";
$expected = "\033[1;31mtest\033[0m\n";
$this->assertSame($expected, $this->getStreamFilterBuffer());
}

public function testErrorForeground(): void
{
CLI::error('test', 'purple');

$expected = "\033[0;35mtest\033[0m" . "\n";
$expected = "\033[0;35mtest\033[0m\n";
$this->assertSame($expected, $this->getStreamFilterBuffer());
}

public function testErrorBackground(): void
{
CLI::error('test', 'purple', 'green');

$expected = "\033[0;35m\033[42mtest\033[0m" . "\n";
$expected = "\033[0;35m\033[42mtest\033[0m\n";
$this->assertSame($expected, $this->getStreamFilterBuffer());
}

Expand All @@ -411,16 +411,16 @@ public function testShowProgress(): void
CLI::write('third.');
CLI::showProgress(1, 20);

$expected = 'first.' . "\n" .
"[\033[32m#.........\033[0m] 5% Complete" . "\n" .
"\033[1A[\033[32m#####.....\033[0m] 50% Complete" . "\n" .
"\033[1A[\033[32m##########\033[0m] 100% Complete" . "\n" .
'second.' . "\n" .
"[\033[32m#.........\033[0m] 5% Complete" . "\n" .
"\033[1A[\033[32m#####.....\033[0m] 50% Complete" . "\n" .
"\033[1A[\033[32m##########\033[0m] 100% Complete" . "\n" .
'third.' . "\n" .
"[\033[32m#.........\033[0m] 5% Complete" . "\n";
$expected = "first.\n" .
"[\033[32m#.........\033[0m] 5% Complete\n" .
"\033[1A[\033[32m#####.....\033[0m] 50% Complete\n" .
"\033[1A[\033[32m##########\033[0m] 100% Complete\n" .
"second.\n" .
"[\033[32m#.........\033[0m] 5% Complete\n" .
"\033[1A[\033[32m#####.....\033[0m] 50% Complete\n" .
"\033[1A[\033[32m##########\033[0m] 100% Complete\n" .
"third.\n" .
"[\033[32m#.........\033[0m] 5% Complete\n";
$this->assertSame($expected, $this->getStreamFilterBuffer());
}

Expand All @@ -431,24 +431,24 @@ public function testShowProgressWithoutBar(): void
CLI::showProgress(false, 20);
CLI::showProgress(false, 20);

$expected = 'first.' . "\n" . "\007\007\007";
$expected = "first.\n\007\007\007";
$this->assertSame($expected, $this->getStreamFilterBuffer());
}

public function testWrap(): void
{
$this->assertSame('', CLI::wrap(''));
$this->assertSame(
'1234' . "\n" . ' 5678' . "\n" . ' 90' . "\n" . ' abc' . "\n" . ' de' . "\n" . ' fghij' . "\n" . ' 0987654321',
CLI::wrap('1234 5678 90' . "\n" . 'abc de fghij' . "\n" . '0987654321', 5, 1)
"1234\n 5678\n 90\n abc\n de\n fghij\n 0987654321",
CLI::wrap("1234 5678 90\nabc de fghij\n0987654321", 5, 1)
);
$this->assertSame(
'1234 5678 90' . "\n" . ' abc de fghij' . "\n" . ' 0987654321',
CLI::wrap('1234 5678 90' . "\n" . 'abc de fghij' . "\n" . '0987654321', 999, 2)
"1234 5678 90\n abc de fghij\n 0987654321",
CLI::wrap("1234 5678 90\nabc de fghij\n0987654321", 999, 2)
);
$this->assertSame(
'1234 5678 90' . "\n" . 'abc de fghij' . "\n" . '0987654321',
CLI::wrap('1234 5678 90' . "\n" . 'abc de fghij' . "\n" . '0987654321')
"1234 5678 90\nabc de fghij\n0987654321",
CLI::wrap("1234 5678 90\nabc de fghij\n0987654321")
);
}

Expand Down Expand Up @@ -605,38 +605,38 @@ public static function provideTable(): iterable
[
$oneRow,
[],
'+---+-----+' . "\n" .
'| 1 | bar |' . "\n" .
'+---+-----+' . "\n" . "\n",
"+---+-----+\n" .
"| 1 | bar |\n" .
"+---+-----+\n\n",
],
[
$oneRow,
$head,
'+----+-------+' . "\n" .
'| ID | Title |' . "\n" .
'+----+-------+' . "\n" .
'| 1 | bar |' . "\n" .
'+----+-------+' . "\n" . "\n",
"+----+-------+\n" .
"| ID | Title |\n" .
"+----+-------+\n" .
"| 1 | bar |\n" .
"+----+-------+\n\n",
],
[
$manyRows,
[],
'+---+-----------------+' . "\n" .
'| 1 | bar |' . "\n" .
'| 2 | bar * 2 |' . "\n" .
'| 3 | bar + bar + bar |' . "\n" .
'+---+-----------------+' . "\n" . "\n",
"+---+-----------------+\n" .
"| 1 | bar |\n" .
"| 2 | bar * 2 |\n" .
"| 3 | bar + bar + bar |\n" .
"+---+-----------------+\n\n",
],
[
$manyRows,
$head,
'+----+-----------------+' . "\n" .
'| ID | Title |' . "\n" .
'+----+-----------------+' . "\n" .
'| 1 | bar |' . "\n" .
'| 2 | bar * 2 |' . "\n" .
'| 3 | bar + bar + bar |' . "\n" .
'+----+-----------------+' . "\n" . "\n",
"+----+-----------------+\n" .
"| ID | Title |\n" .
"+----+-----------------+\n" .
"| 1 | bar |\n" .
"| 2 | bar * 2 |\n" .
"| 3 | bar + bar + bar |\n" .
"+----+-----------------+\n\n",
],
// Multibyte letters
[
Expand All @@ -650,11 +650,11 @@ public static function provideTable(): iterable
'ID',
'タイトル',
],
'+------+----------+' . "\n" .
'| ID | タイトル |' . "\n" .
'+------+----------+' . "\n" .
'| ほげ | bar |' . "\n" .
'+------+----------+' . "\n" . "\n",
"+------+----------+\n" .
"| ID | タイトル |\n" .
"+------+----------+\n" .
"| ほげ | bar |\n" .
"+------+----------+\n\n",
],
];
}
Expand Down
6 changes: 5 additions & 1 deletion tests/system/Files/FileCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ public function testResolveDirectorySymlink(): void

$this->assertSame($this->directory, $method($link));

rmdir($link);
if (is_windows() && is_dir($link)) {
rmdir($link);
} else {
unlink($link);
}
}

public function testResolveFileFile(): void
Expand Down
1 change: 0 additions & 1 deletion tests/system/HTTP/Files/FileMovingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,4 +382,3 @@ function rrmdir($src): void
closedir($dir);
rmdir($src);
}

18 changes: 9 additions & 9 deletions tests/system/Test/BootstrapFCPATHTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ private function deleteFiles(): void
private function fileContents()
{
$fileContents = '';
$fileContents .= '<?php' . "\n";
$fileContents .= "define('HOMEPATH', '" . $this->currentDir . "' . '/../../../');" . "\n";
$fileContents .= "define('CONFIGPATH', '" . $this->currentDir . "' . '/../../../app/Config/');" . "\n";
$fileContents .= "define('PUBLICPATH', '" . $this->currentDir . "' . '/../../../public/');" . "\n";
$fileContents .= "include_once '" . $this->currentDir . "' . '/../../../vendor/autoload.php';" . "\n";
$fileContents .= "include_once '" . $this->currentDir . "' . '/../../../system/Test/bootstrap.php';" . "\n";
$fileContents .= '// return value of FCPATH' . "\n";

return $fileContents . ('echo FCPATH;' . "\n");
$fileContents .= "<?php\n";
$fileContents .= "define('HOMEPATH', '" . $this->currentDir . "' . '/../../../');\n";
$fileContents .= "define('CONFIGPATH', '" . $this->currentDir . "' . '/../../../app/Config/');\n";
$fileContents .= "define('PUBLICPATH', '" . $this->currentDir . "' . '/../../../public/');\n";
$fileContents .= "include_once '" . $this->currentDir . "' . '/../../../vendor/autoload.php';\n";
$fileContents .= "include_once '" . $this->currentDir . "' . '/../../../system/Test/bootstrap.php';\n";
$fileContents .= "// return value of FCPATH\n";

return $fileContents . ("echo FCPATH;\n");
}

private function readOutput(string $file)
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Test/TestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function testEventTriggering(): void
public function testStreamFilter(): void
{
CLI::write('first.');
$expected = "\n" . 'first.' . "\n";
$expected = "\nfirst.\n";
$this->assertSame($expected, $this->getStreamFilterBuffer());
}

Expand Down

0 comments on commit ea9be93

Please sign in to comment.