Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Improve for windows #9318

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
WIP: Update test and cs-fix
Signed-off-by: neznaika0 <[email protected]>
neznaika0 committed Dec 14, 2024
commit ea9be93b7507a392d74138d81a1865b44554be4d
14 changes: 4 additions & 10 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
@@ -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\\.$#',
@@ -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
6 changes: 1 addition & 5 deletions system/Autoloader/Autoloader.php
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 2 additions & 2 deletions system/CLI/CLI.php
Original file line number Diff line number Diff line change
@@ -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);
@@ -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)) {
2 changes: 1 addition & 1 deletion system/Commands/Translation/LocalizationFinder.php
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion system/Commands/Utilities/ConfigCheck.php
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@
use CodeIgniter\CLI\CLI;
use CodeIgniter\Config\BaseConfig;
use Config\Optimize;
use Ergebnis\Json\Json;
use Kint\Kint;

/**
2 changes: 1 addition & 1 deletion system/Helpers/filesystem_helper.php
Original file line number Diff line number Diff line change
@@ -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;
}

4 changes: 2 additions & 2 deletions system/View/View.php
Original file line number Diff line number Diff line change
@@ -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";
}
}

2 changes: 1 addition & 1 deletion tests/system/Autoloader/FileLocatorTest.php
Original file line number Diff line number Diff line change
@@ -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
102 changes: 51 additions & 51 deletions tests/system/CLI/CLITest.php
Original file line number Diff line number Diff line change
@@ -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());
}

@@ -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());
}

@@ -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());
}

@@ -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());
}

@@ -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")
);
}

@@ -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
[
@@ -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",
],
];
}
6 changes: 5 additions & 1 deletion tests/system/Files/FileCollectionTest.php
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion tests/system/HTTP/Files/FileMovingTest.php
Original file line number Diff line number Diff line change
@@ -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
@@ -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)
2 changes: 1 addition & 1 deletion tests/system/Test/TestCaseTest.php
Original file line number Diff line number Diff line change
@@ -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());
}


Unchanged files with check annotations Beta

$this->assertSame(200, $this->handler->getHeight());
}
public function testImageCreation(): void

Check warning on line 356 in tests/system/Images/ImageMagickHandlerTest.php

GitHub Actions / Others (8.2) / Sanity Tests

Took 1.4270s from 0.5000s limit to run CodeIgniter\\Images\\ImageMagickHandlerTest::testImageCreation
{
foreach (['gif', 'jpeg', 'png', 'webp'] as $type) {
if ($type === 'webp' && ! in_array('WEBP', Imagick::queryFormats(), true)) {
$this->assertSame(exif_imagetype($this->root . 'ci-logo.png'), IMAGETYPE_PNG);
}
public function testImageReorientLandscape(): void

Check warning on line 453 in tests/system/Images/ImageMagickHandlerTest.php

GitHub Actions / Others (8.2) / Sanity Tests

Took 0.5623s from 0.5000s limit to run CodeIgniter\\Images\\ImageMagickHandlerTest::testImageReorientLandscape
{
for ($i = 0; $i <= 8; $i++) {
$source = $this->origin . 'EXIFsamples/landscape_' . $i . '.jpg';
}
}
public function testImageReorientPortrait(): void

Check warning on line 472 in tests/system/Images/ImageMagickHandlerTest.php

GitHub Actions / Others (8.2) / Sanity Tests

Took 0.5282s from 0.5000s limit to run CodeIgniter\\Images\\ImageMagickHandlerTest::testImageReorientPortrait
{
for ($i = 0; $i <= 8; $i++) {
$source = $this->origin . 'EXIFsamples/portrait_' . $i . '.jpg';
$this->assertSame(0, Fabricator::getCount('giants'));
}
public function testUniqueSetsOutUniqueFieldValues(): void

Check warning on line 496 in tests/system/Test/FabricatorTest.php

GitHub Actions / Others (8.2) / Sanity Tests

Took 0.5832s from 0.5000s limit to run CodeIgniter\\Test\\FabricatorTest::testUniqueSetsOutUniqueFieldValues
{
$model = new class () extends Model {
protected $allowedFields = ['email'];
$this->forge->dropTable('', true);
}
public function testForeignKey(): void

Check warning on line 491 in tests/system/Database/Live/ForgeTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 2.8573s from 0.5000s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testForeignKey
{
$this->forge->dropTable('forge_test_invoices', true);
$this->forge->dropTable('forge_test_users', true);
$this->forge->dropTable('forge_test_1', true);
}
public function testSetKeyNames(): void

Check warning on line 1233 in tests/system/Database/Live/ForgeTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 1.0359s from 0.5000s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testSetKeyNames
{
$this->forge->dropTable('forge_test_1', true);
$this->forge->dropTable('forge_test_four', true);
}
public function testDropKey(): void

Check warning on line 1581 in tests/system/Database/Live/ForgeTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 0.8147s from 0.5000s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testDropKey
{
$this->forge->dropTable('key_test_users', true);
$keyName = 'key_test_users_id';
$this->forge->dropTable('forge_test_users', true);
}
public function testProcessIndexes(): void

Check warning on line 1674 in tests/system/Database/Live/ForgeTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 1.4133s from 0.5000s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testProcessIndexes
{
// make sure tables don't exist
$this->forge->dropTable('actions', true);
$this->assertSame('MySQLi', $this->getPrivateProperty($db1, 'DBDriver'));
}
public function testConnectWithFailover(): void

Check warning on line 97 in tests/system/Database/Live/ConnectTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 1.0947s from 0.5000s limit to run CodeIgniter\\Database\\Live\\ConnectTest::testConnectWithFailover
{
$this->tests['failover'][] = $this->tests;
unset($this->tests['failover'][0]['failover']);
$this->assertTrue($this->model->save($entity));
}
public function testSaveNewEntityWithDate(): void

Check warning on line 270 in tests/system/Models/SaveModelTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 0.9753s from 0.5000s limit to run CodeIgniter\\Models\\SaveModelTest::testSaveNewEntityWithDate
{
$entity = new class () extends Entity {
protected $id;
CLI::init();
}
public function testMigrateAllWithWithTwoNamespaces(): void

Check warning on line 77 in tests/system/Commands/Database/MigrateStatusTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 0.7314s from 0.5000s limit to run CodeIgniter\\Commands\\Database\\MigrateStatusTest::testMigrateAllWithWithTwoNamespaces
{
command('migrate --all');
$this->resetStreamFilterBuffer();
$this->createModel(UserModel::class)->insert([]);
}
public function testInsertPermitInsertNoData(): void

Check warning on line 239 in tests/system/Models/InsertModelTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 0.7282s from 0.5000s limit to run CodeIgniter\\Models\\InsertModelTest::testInsertPermitInsertNoData
{
$forge = Database::forge();
$forge->addField([
);
}
public function testDeleteBatchWithQuery(): void

Check warning on line 149 in tests/system/Database/Live/DeleteTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 0.6921s from 0.5000s limit to run CodeIgniter\\Database\\Live\\DeleteTest::testDeleteBatchWithQuery
{
$this->forge = Database::forge($this->DBGroup);
protected $refresh = true;
public function testCreateAddsToDatabase(): void

Check warning on line 34 in tests/system/Database/Live/FabricatorLiveTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 0.6583s from 0.5000s limit to run CodeIgniter\\Database\\Live\\FabricatorLiveTest::testCreateAddsToDatabase
{
$fabricator = new Fabricator(UserModel::class);