Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['8.1', '8.2', '8.3', '8.4', '8.5']
php-version: ['8.3', '8.4', '8.5']
db: ['sqlite', 'mysql']
steps:
- uses: niden/actions-memcached@v7
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"require-dev": {
"rector/rector": "^0.12.5",
"phpunit/phpunit": "^10.0"
"phpunit/phpunit": "^12.0"
},
"config": {
"vendor-dir": "vendors/",
Expand Down
744 changes: 395 additions & 349 deletions composer.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/Cake/Core/Configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public static function bootstrap($boot = true) {
);
}
restore_error_handler();
restore_exception_handler();

static::_setErrorHandlers(
static::$_values['Error'],
Expand Down
11 changes: 10 additions & 1 deletion lib/Cake/I18n/I18n.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,22 @@ public static function translate($singular, $plural = null, $domain = null, $cat
}

/**
* Clears the domains internal data array. Useful for testing i18n.
* Resets the internal translation state. Useful for testing i18n.
*
* Besides emptying the loaded domains, it drops the resolved language and
* recreates the L10n instance so a stale default language captured at
* construction time cannot leak between consecutive translations.
*
* @return void
*/
public static function clear() {
$self = I18n::getInstance();
$self->_domains = array();
$self->_lang = null;
$self->_noLocale = false;
$self->domain = null;
$self->category = 'LC_MESSAGES';
$self->l10n = new L10n();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Network/CakeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ public function clientIp($safe = true) {
} else {
$ipaddr = env('REMOTE_ADDR');
}
return trim($ipaddr);
return trim((string)$ipaddr);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/Cache/Engine/ApcEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ApcEngineTest extends CakeTestCase {
* @var string
*/
protected $_apcExtension = 'apc';
private ?bool $_cacheDisable;
private ?bool $_cacheDisable = null;

/**
* setUp method
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/Cache/Engine/MemcacheEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function setMemcache($memcache) {
*/
class MemcacheEngineTest extends CakeTestCase {

private ?bool $_cacheDisable;
private ?bool $_cacheDisable = null;
/**
* setUp method
*
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/Cache/Engine/RedisEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
class RedisEngineTest extends CakeTestCase {

private ?bool $_cacheDisable;
private ?bool $_cacheDisable = null;
/**
* setUp method
*
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/Cache/Engine/WincacheEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
class WincacheEngineTest extends CakeTestCase {

private ?bool $_cacheDisable;
private ?bool $_cacheDisable = null;
/**
* setUp method
*
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/Cache/Engine/XcacheEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
class XcacheEngineTest extends CakeTestCase {

private ?bool $_cacheDisable;
private ?bool $_cacheDisable = null;
/**
* setUp method
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ public function testGetNameValidIndex() {
*/
public function testGetNameInvalidIndex() {
$this->Task->interactive = true;
$invalidIndex = count($this->Task->listAll('test')) + 1;
$this->Task->expects($this->any())->method('in')
->will($this->onConsecutiveCalls(50, 'q'));
->will($this->onConsecutiveCalls($invalidIndex, 'q'));

$this->Task->expects($this->once())->method('err');
$this->Task->expects($this->once())->method('_stop');
Expand Down Expand Up @@ -548,9 +549,9 @@ public static function nameVariations() {
/**
* test that both plural and singular forms work for controller baking.
*
* @dataProvider nameVariations
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('nameVariations')]
public function testExecuteWithControllerNameVariations($name) {
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
Expand Down
5 changes: 3 additions & 2 deletions lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ public function testGetNameValidOption() {
* @return void
*/
public function testGetNameWithOutOfBoundsOption() {
$this->Task->expects($this->any())->method('in')->will($this->onConsecutiveCalls(99, 1));
$invalidIndex = count($this->Task->listAll('test')) + 1;
$this->Task->expects($this->any())->method('in')->will($this->onConsecutiveCalls($invalidIndex, 1));
$this->Task->expects($this->once())->method('err');

$this->Task->getName('test');
Expand Down Expand Up @@ -1002,9 +1003,9 @@ public static function nameVariations() {
/**
* test that execute passes with different inflections of the same name.
*
* @dataProvider nameVariations
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('nameVariations')]
public function testExecuteWithNamedModelVariations($name) {
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Test/Case/Console/Command/Task/TestTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,9 +646,9 @@ public static function caseFileNameProvider() {
/**
* Test filename generation for each type + plugins
*
* @dataProvider caseFileNameProvider
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('caseFileNameProvider')]
public function testTestCaseFileName($type, $class, $expected) {
$this->Task->path = DS . 'my' . DS . 'path' . DS . 'tests' . DS;

Expand Down Expand Up @@ -747,9 +747,9 @@ public static function mapTypeProvider() {
/**
* Test that mapType returns the correct package names.
*
* @dataProvider mapTypeProvider
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('mapTypeProvider')]
public function testMapType($original, $plugin, $expected) {
$this->assertEquals($expected, $this->Task->mapType($original, $plugin));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/Console/Command/Task/ViewTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,9 @@ public static function nameVariations() {
/**
* test that both plural and singular forms can be used for baking views.
*
* @dataProvider nameVariations
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('nameVariations')]
public function testExecuteWithControllerVariations($name) {
$this->Task->args = array($name);

Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/Console/ShellTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,8 @@ public function testShellNaming()
/**
* Test reading params
*
* @dataProvider paramReadingDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('paramReadingDataProvider')]
public function testParamReading($toRead, $expected)
{
$this->Shell->params = [
Expand Down
7 changes: 3 additions & 4 deletions lib/Cake/Test/Case/Controller/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -748,9 +748,9 @@ public static function statusCodeProvider() {
/**
* testRedirect method
*
* @dataProvider statusCodeProvider
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('statusCodeProvider')]
public function testRedirectByCode($code, $msg) {
$Controller = new Controller(null);
$Controller->response = $this->getMock('CakeResponse', array('header', 'statusCode'));
Expand All @@ -769,9 +769,9 @@ public function testRedirectByCode($code, $msg) {
/**
* test redirecting by message
*
* @dataProvider statusCodeProvider
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('statusCodeProvider')]
public function testRedirectByMessage($code, $msg) {
$Controller = new Controller(null);
$Controller->response = $this->getMock('CakeResponse', array('header', 'statusCode'));
Expand Down Expand Up @@ -1019,7 +1019,6 @@ public function testReferer() {
$this->assertEquals('/posts/index', $result);

$Controller = new Controller($request);
$request->setReturnValue('referer', '/', array(true));
$result = $Controller->referer(array('controller' => 'posts', 'action' => 'index'), true);
$this->assertEquals('/posts/index', $result);

Expand Down Expand Up @@ -1214,9 +1213,9 @@ public static function dangerousPostConditionsProvider() {
/**
* test postConditions raising an exception on unsafe keys.
*
* @dataProvider dangerousPostConditionsProvider
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('dangerousPostConditionsProvider')]
public function testPostConditionsDangerous($data) {
$this->expectException(\RuntimeException::class);
$request = new CakeRequest('controller_posts/index');
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/Core/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -842,9 +842,9 @@ public function testPluginLibClasses() {
/**
* Test that increaseMemoryLimit increases the maximum amount of memory actually
*
* @dataProvider memoryVariationProvider
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('memoryVariationProvider')]
public function testIncreaseMemoryLimit($memoryLimit, $additionalKb, $expected) {
$this->skipIf(!function_exists('ini_set'));

Expand Down
5 changes: 5 additions & 0 deletions lib/Cake/Test/Case/Core/ConfigureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public function testBootstrap() {

$this->assertEquals($expected['foo'], $result['foo']);
$this->assertFalse($result['base']);

// Configure::bootstrap() installs CakePHP's error/exception handlers;
// restore them so the test leaves the handler stack as it found it.
restore_error_handler();
restore_exception_handler();
}

/**
Expand Down
9 changes: 1 addition & 8 deletions lib/Cake/Test/Case/Error/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ public function testHandleErrorDebugOn() {
$this->assertMatchesRegularExpression('/<pre class="cake-error">/', $result);
$this->assertMatchesRegularExpression('/<b>(Notice|Warning)<\/b>/', $result);
$this->assertMatchesRegularExpression('/variable\:?\s+\$?wrong/', $result);
restore_error_handler();
}

/**
Expand All @@ -128,9 +127,9 @@ public static function errorProvider() {
/**
* test error mappings
*
* @dataProvider errorProvider
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('errorProvider')]
public function testErrorMapping($error, $expected) {
set_error_handler('ErrorHandler::handleError');
$this->_restoreError = true;
Expand All @@ -142,7 +141,6 @@ public function testErrorMapping($error, $expected) {

$result = ob_get_clean();
$this->assertMatchesRegularExpression('/<b>' . $expected . '<\/b>/', $result);
restore_error_handler();
}

/**
Expand All @@ -165,7 +163,6 @@ public function testErrorSuppressed() {
}else{
$this->assertTrue(empty($result));
}
restore_error_handler();
}

/**
Expand Down Expand Up @@ -196,7 +193,6 @@ public function testHandleErrorDebugOff() {
if (file_exists(LOGS . 'debug.log')) {
unlink(LOGS . 'debug.log');
}
restore_error_handler();
}

public function testHandleErrorDebugOffPHP8() {
Expand All @@ -222,7 +218,6 @@ public function testHandleErrorDebugOffPHP8() {
if (file_exists(LOGS . 'error.log')) {
unlink(LOGS . 'error.log');
}
restore_error_handler();
}

/**
Expand Down Expand Up @@ -254,7 +249,6 @@ public function testHandleErrorLoggingTrace() {
if (file_exists(LOGS . 'debug.log')) {
unlink(LOGS . 'debug.log');
}
restore_error_handler();
}

public function testHandleErrorLoggingTracePHP8() {
Expand Down Expand Up @@ -282,7 +276,6 @@ public function testHandleErrorLoggingTracePHP8() {
if (file_exists(LOGS . 'error.log')) {
unlink(LOGS . 'error.log');
}
restore_error_handler();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/Error/ExceptionRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,9 @@ public static function errorProvider() {
/**
* Test the various CakeException sub classes
*
* @dataProvider errorProvider
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('errorProvider')]
public function testCakeExceptionHandling($exception, $patterns, $code) {
$ExceptionRenderer = new ExceptionRenderer($exception);
$ExceptionRenderer->controller->response = $this->getMock('CakeResponse', array('statusCode', '_sendHeader'));
Expand Down
8 changes: 8 additions & 0 deletions lib/Cake/Test/Case/I18n/I18nTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public function setUp(): void {
Configure::write('Session', array('defaults' => 'php'));
CakeSession::destroy();

// Each test selects its own language; start from a clean slate so a
// language left over from a previous test cannot become the stale
// default captured by the L10n instance.
Configure::delete('Config.language');
I18n::clear();

Cache::delete('object_map', '_cake_core_');
App::build(array(
'Locale' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Locale' . DS),
Expand All @@ -59,6 +65,8 @@ public function setUp(): void {
public function tearDown(): void {
parent::tearDown();

Configure::delete('Config.language');
I18n::clear();
Cache::delete('object_map', '_cake_core_');
CakeSession::destroy();
App::build();
Expand Down
6 changes: 6 additions & 0 deletions lib/Cake/Test/Case/I18n/L10nTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,14 @@ public function testGetAutoLanguage() {
/**
* testGet method with deprecated constant DEFAULT_LANGUAGE
*
* Runs in a separate process: it defines the DEFAULT_LANGUAGE constant,
* which cannot be undefined and would otherwise become a permanent stale
* default for every L10n instance created afterwards in the same process.
*
* @return void
*/
#[\PHPUnit\Framework\Attributes\RunInSeparateProcess]
#[\PHPUnit\Framework\Attributes\PreserveGlobalState(false)]
public function testGetWithDeprecatedConstant() {
$this->skipIf(defined('DEFAULT_LANGUAGE'), 'Cannot re-define already defined constant.');

Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/Log/Engine/SyslogLogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public function testOpenLog() {
/**
* Tests that single lines are written to syslog
*
* @dataProvider typesProvider
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('typesProvider')]
public function testWriteOneLine($type, $expected) {
$log = $this->getMock('SyslogLog', array('_open', '_write'));
$log->expects($this->once())->method('_write')->with($expected, $type . ': Foo');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,7 @@ public function testFieldsRestoreAfterBind() {
$this->loadFixtures('Translate', 'TranslatedItem');

$TestModel = new TranslatedItem();
$TestModel->locale = 'eng';

$translations = array('title' => 'Title');
$TestModel->bindTranslation($translations);
Expand Down
Loading
Loading