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 May 5, 2024
2 parents deb74d5 + ac06cff commit 1a8a1f1
Show file tree
Hide file tree
Showing 331 changed files with 1,270 additions and 1,597 deletions.
3 changes: 2 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@

$overrides = [
// for updating to coding-standard
'modernize_strpos' => true,
'modernize_strpos' => true,
'php_unit_attributes' => true,
];

$options = [
Expand Down
3 changes: 2 additions & 1 deletion .php-cs-fixer.no-header.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@

$overrides = [
// for updating to coding-standard
'modernize_strpos' => true,
'modernize_strpos' => true,
'php_unit_attributes' => true,
];

$options = [
Expand Down
3 changes: 2 additions & 1 deletion .php-cs-fixer.tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
$overrides = [
'void_return' => true,
// for updating to coding-standard
'modernize_strpos' => true,
'modernize_strpos' => true,
'php_unit_attributes' => true,
];

$options = [
Expand Down
3 changes: 2 additions & 1 deletion .php-cs-fixer.user-guide.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
'leading_backslash_in_global_namespace' => true,
],
// for updating to coding-standard
'modernize_strpos' => true,
'modernize_strpos' => true,
'php_unit_attributes' => true,
];

$options = [
Expand Down
11 changes: 0 additions & 11 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<?php declare(strict_types = 1);

$ignoreErrors = [];
$ignoreErrors[] = [
'message' => '#^PHPDoc type array\\<string, array\\<int, string\\>\\> of property Config\\\\Filters\\:\\:\\$methods is not the same as PHPDoc type array of overridden property CodeIgniter\\\\Config\\\\Filters\\:\\:\\$methods\\.$#',
'count' => 1,
'path' => __DIR__ . '/app/Config/Filters.php',
];
$ignoreErrors[] = [
'message' => '#^PHPDoc type array\\<string, array\\<string, array\\<int, string\\>\\>\\> of property Config\\\\Filters\\:\\:\\$filters is not the same as PHPDoc type array of overridden property CodeIgniter\\\\Config\\\\Filters\\:\\:\\$filters\\.$#',
'count' => 1,
Expand Down Expand Up @@ -1151,11 +1145,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Config/Filters.php',
];
$ignoreErrors[] = [
'message' => '#^Property CodeIgniter\\\\Config\\\\Filters\\:\\:\\$methods type has no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Config/Filters.php',
];
$ignoreErrors[] = [
'message' => '#^Accessing offset \'SERVER_PROTOCOL\' directly on \\$_SERVER is discouraged\\.$#',
'count' => 1,
Expand Down
2 changes: 2 additions & 0 deletions system/Config/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ class Filters extends BaseConfig
* If you use this, you should disable auto-routing because auto-routing
* permits any HTTP method to access a controller. Accessing the controller
* with a method you don't expect could bypass the filter.
*
* @var array<string, list<string>>
*/
public array $methods = [];

Expand Down
17 changes: 17 additions & 0 deletions system/Database/SQLSRV/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,23 @@ private function getFullName(string $table): string
}

if ($this->db->escapeChar === '"') {
if (str_contains($table, '.') && ! str_starts_with($table, '.') && ! str_ends_with($table, '.')) {
$dbInfo = explode('.', $table);
$database = $this->db->getDatabase();
$table = $dbInfo[0];

if (count($dbInfo) === 3) {
$database = str_replace('"', '', $dbInfo[0]);
$schema = str_replace('"', '', $dbInfo[1]);
$tableName = str_replace('"', '', $dbInfo[2]);
} else {
$schema = str_replace('"', '', $dbInfo[0]);
$tableName = str_replace('"', '', $dbInfo[1]);
}

return '"' . $database . '"."' . $schema . '"."' . str_replace('"', '', $tableName) . '"' . $alias;
}

return '"' . $this->db->getDatabase() . '"."' . $this->db->schema . '"."' . str_replace('"', '', $table) . '"' . $alias;
}

Expand Down
3 changes: 1 addition & 2 deletions system/Test/Mock/MockCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@ public function remember(string $key, int $ttl, Closure $callback)
* @param string $key Cache item name
* @param mixed $value the data to save
* @param int $ttl Time To Live, in seconds (default 60)
* @param bool $raw Whether to store the raw value.
*
* @return bool
*/
public function save(string $key, $value, int $ttl = 60, bool $raw = false)
public function save(string $key, $value, int $ttl = 60)
{
if ($this->bypass) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions tests/system/API/ResponseTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace CodeIgniter\API;

use PHPUnit\Framework\Attributes\Group;
use CodeIgniter\Config\Factories;
use CodeIgniter\Format\FormatterInterface;
use CodeIgniter\Format\JSONFormatter;
Expand All @@ -28,9 +29,8 @@

/**
* @internal
*
* @group Others
*/
#[Group('Others')]
final class ResponseTraitTest extends CIUnitTestCase
{
private ?MockIncomingRequest $request = null;
Expand Down
8 changes: 4 additions & 4 deletions tests/system/AutoReview/ComposerJsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@

namespace CodeIgniter\AutoReview;

use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\Attributes\Group;
use InvalidArgumentException;
use JsonException;
use PHPUnit\Framework\TestCase;

/**
* @internal
*
* @coversNothing
*
* @group AutoReview
*/
#[CoversNothing]
#[Group('AutoReview')]
final class ComposerJsonTest extends TestCase
{
private array $devComposer;
Expand Down
37 changes: 21 additions & 16 deletions tests/system/AutoReview/FrameworkCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,28 @@

namespace CodeIgniter\AutoReview;

use PHPUnit\Framework\Attributes\DataProvider;
use FilesystemIterator;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use ReflectionAttribute;
use ReflectionClass;
use SplFileInfo;

/**
* @internal
*
* @group AutoReview
*/
#[Group('AutoReview')]
final class FrameworkCodeTest extends TestCase
{
/**
* Cache of discovered test class names.
*/
private static array $testClasses = [];

private static array $recognizedGroupAnnotations = [
private static array $recognizedGroupAttributeNames = [

Check failure on line 37 in tests/system/AutoReview/FrameworkCodeTest.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Property CodeIgniter\AutoReview\FrameworkCodeTest::$recognizedGroupAttributeNames type has no value type specified in iterable type array.
'AutoReview',
'CacheLive',
'DatabaseLive',
Expand All @@ -41,11 +43,10 @@ final class FrameworkCodeTest extends TestCase
];

/**
* @dataProvider provideEachTestClassHasCorrectGroupAnnotation
*
* @param class-string $class
*/
public function testEachTestClassHasCorrectGroupAnnotation(string $class): void
#[DataProvider('provideEachTestClassHasCorrectGroupAttributeName')]
public function testEachTestClassHasCorrectGroupAttributeName(string $class): void
{
$reflection = new ReflectionClass($class);

Expand All @@ -55,27 +56,31 @@ public function testEachTestClassHasCorrectGroupAnnotation(string $class): void
return;
}

$docComment = (string) $reflection->getDocComment();
$this->assertNotEmpty($docComment, sprintf('[%s] Test class is missing a class-level PHPDoc.', $class));
$attributes = $reflection->getAttributes(Group::class);
$this->assertNotEmpty($attributes, sprintf('[%s] Test class is missing a #[Group] attribute.', $class));

preg_match_all('/@group (\S+)/', $docComment, $matches);
array_shift($matches);
$this->assertNotEmpty($matches[0], sprintf('[%s] Test class is missing a @group annotation.', $class));
$unrecognizedGroups = array_diff(
array_map(static function (ReflectionAttribute $attribute): string {
$groupAttribute = $attribute->newInstance();
assert($groupAttribute instanceof Group);

$unrecognizedGroups = array_diff($matches[0], self::$recognizedGroupAnnotations);
return $groupAttribute->name();
}, $attributes),
self::$recognizedGroupAttributeNames
);
$this->assertEmpty($unrecognizedGroups, sprintf(
"[%s] Unexpected @group annotation%s:\n%s\nExpected annotations to be in \"%s\".",
"[%s] Unexpected #[Group] attribute%s:\n%s\nExpected group names to be in \"%s\".",
$class,
count($unrecognizedGroups) > 1 ? 's' : '',
implode("\n", array_map(
static fn (string $group): string => sprintf(' * @group %s', $group),
static fn (string $group): string => sprintf(' * #[Group(\'%s\')]', $group),
$unrecognizedGroups
)),
implode(', ', self::$recognizedGroupAnnotations)
implode(', ', self::$recognizedGroupAttributeNames)
));
}

public static function provideEachTestClassHasCorrectGroupAnnotation(): iterable
public static function provideEachTestClassHasCorrectGroupAttributeName(): iterable

Check failure on line 83 in tests/system/AutoReview/FrameworkCodeTest.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Method CodeIgniter\AutoReview\FrameworkCodeTest::provideEachTestClassHasCorrectGroupAttributeName() return type has no value type specified in iterable type iterable.
{
foreach (self::getTestClasses() as $class) {
yield $class => [$class];
Expand Down
12 changes: 6 additions & 6 deletions tests/system/Autoloader/AutoloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

namespace CodeIgniter\Autoloader;

use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use App\Controllers\Home;
use Closure;
use CodeIgniter\Exceptions\ConfigException;
Expand All @@ -27,9 +30,8 @@

/**
* @internal
*
* @group Others
*/
#[Group('Others')]
final class AutoloaderTest extends CIUnitTestCase
{
use ReflectionHelper;
Expand Down Expand Up @@ -390,10 +392,8 @@ public function testAutoloaderLoadsNonClassFiles(): void
$loader->unregister();
}

/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testLoadHelpers(): void
{
// Workaround for errors on PHPUnit 10 and PHP 8.3.
Expand Down
4 changes: 2 additions & 2 deletions tests/system/Autoloader/FileLocatorCachedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@

namespace CodeIgniter\Autoloader;

use PHPUnit\Framework\Attributes\Group;
use CodeIgniter\Cache\FactoriesCache\FileVarExportHandler;
use Config\Autoload;
use Config\Modules;

/**
* @internal
*
* @group Others
*/
#[Group('Others')]
final class FileLocatorCachedTest extends FileLocatorTest
{
private FileVarExportHandler $handler;
Expand Down
3 changes: 2 additions & 1 deletion tests/system/Autoloader/FileLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace CodeIgniter\Autoloader;

use PHPUnit\Framework\Attributes\Group;
use CodeIgniter\HTTP\Header;
use CodeIgniter\Test\CIUnitTestCase;
use Config\Autoload;
Expand All @@ -21,9 +22,9 @@
/**
* @internal
*
* @group Others
* @no-final
*/
#[Group('Others')]
class FileLocatorTest extends CIUnitTestCase
{
protected FileLocatorInterface $locator;
Expand Down
8 changes: 4 additions & 4 deletions tests/system/CLI/CLITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace CodeIgniter\CLI;

use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\DataProvider;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\PhpStreamWrapper;
use CodeIgniter\Test\StreamFilterTrait;
Expand All @@ -21,9 +23,8 @@

/**
* @internal
*
* @group Others
*/
#[Group('Others')]
final class CLITest extends CIUnitTestCase
{
use StreamFilterTrait;
Expand Down Expand Up @@ -452,12 +453,11 @@ public function testWindow(): void
}

/**
* @dataProvider provideTable
*
* @param array $tbody
* @param array $thead
* @param array $expected
*/
#[DataProvider('provideTable')]
public function testTable($tbody, $thead, $expected): void
{
CLI::table($tbody, $thead);
Expand Down
4 changes: 2 additions & 2 deletions tests/system/CLI/ConsoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace CodeIgniter\CLI;

use PHPUnit\Framework\Attributes\Group;
use CodeIgniter\CodeIgniter;
use CodeIgniter\Config\DotEnv;
use CodeIgniter\Events\Events;
Expand All @@ -23,9 +24,8 @@

/**
* @internal
*
* @group Others
*/
#[Group('Others')]
final class ConsoleTest extends CIUnitTestCase
{
use StreamFilterTrait;
Expand Down
4 changes: 2 additions & 2 deletions tests/system/Cache/CacheFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@

namespace CodeIgniter\Cache;

use PHPUnit\Framework\Attributes\Group;
use CodeIgniter\Cache\Exceptions\CacheException;
use CodeIgniter\Cache\Handlers\DummyHandler;
use CodeIgniter\Test\CIUnitTestCase;
use Config\Cache;

/**
* @internal
*
* @group Others
*/
#[Group('Others')]
final class CacheFactoryTest extends CIUnitTestCase
{
private static string $directory = 'CacheFactory';
Expand Down
4 changes: 2 additions & 2 deletions tests/system/Cache/CacheMockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@

namespace CodeIgniter\Cache;

use PHPUnit\Framework\Attributes\Group;
use CodeIgniter\Cache\Handlers\BaseHandler;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\Mock\MockCache;

/**
* @internal
*
* @group Others
*/
#[Group('Others')]
final class CacheMockTest extends CIUnitTestCase
{
public function testMockReturnsMockCacheClass(): void
Expand Down
Loading

0 comments on commit 1a8a1f1

Please sign in to comment.