Skip to content

Commit feedfb6

Browse files
authored
Merge pull request #1015 from cakephp/phpunit11
allow PHPUnit 11 and adjust tests for PHPUnit 11
2 parents 55745af + a92943e commit feedfb6

File tree

12 files changed

+48
-39
lines changed

12 files changed

+48
-39
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"require-dev": {
3131
"cakephp/authorization": "^3.0",
3232
"cakephp/cakephp-codesniffer": "^5.0",
33-
"phpunit/phpunit": "^10.5.5"
33+
"phpunit/phpunit": "^10.5.5 || ^11.1.3"
3434
},
3535
"autoload": {
3636
"psr-4": {

phpstan-baseline.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ parameters:
1616
path: src/Command/BenchmarkCommand.php
1717

1818
-
19-
message: "#^Method DebugKit\\\\Mailer\\\\Transport\\\\DebugKitTransport\\:\\:send\\(\\) should return array\\{headers\\: string, message\\: string\\} but returns array\\{headers\\: non\\-empty\\-array\\<string\\>, message\\: array\\{text\\: string, html\\: string\\}\\}\\.$#"
19+
message: "#^Method DebugKit\\\\Mailer\\\\Transport\\\\DebugKitTransport\\:\\:send\\(\\) should return array\\{headers\\: string, message\\: string\\} but returns array\\{headers\\: non\\-empty\\-array\\<string, string\\>, message\\: array\\{text\\: string, html\\: string\\}\\}\\.$#"
2020
count: 1
2121
path: src/Mailer/Transport/DebugKitTransport.php
2222

tests/TestCase/Controller/MailPreviewControllerTest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
*/
1616
namespace DebugKit\Test\TestCase\Controller;
1717

18-
use Cake\Routing\Router;
1918
use Cake\TestSuite\IntegrationTestTrait;
2019
use Cake\TestSuite\TestCase;
2120
use DebugKit\Test\TestCase\FixtureFactoryTrait;
22-
use DebugKit\TestApp\Application;
2321

2422
/**
2523
* Mail preview controller test
@@ -29,18 +27,6 @@ class MailPreviewControllerTest extends TestCase
2927
use FixtureFactoryTrait;
3028
use IntegrationTestTrait;
3129

32-
/**
33-
* Setup method.
34-
*
35-
* @return void
36-
*/
37-
public function setUp(): void
38-
{
39-
parent::setUp();
40-
Router::createRouteBuilder('/')->connect('/users/{action}/*', ['controller' => 'Users']);
41-
$this->configApplication(Application::class, []);
42-
}
43-
4430
/**
4531
* Test that plugin is passed to the view in email action
4632
*

tests/TestCase/Controller/ToolbarControllerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ public function testClearCache()
5959
$mock = $this->getMockBuilder('Cake\Cache\CacheEngine')->getMock();
6060
$mock->expects($this->once())
6161
->method('init')
62-
->will($this->returnValue(true));
62+
->willReturn(true);
6363
$mock->expects($this->once())
6464
->method('clear')
65-
->will($this->returnValue(true));
65+
->willReturn(true);
6666
Cache::setConfig('testing', $mock);
6767

6868
$this->configRequest(['headers' => ['Accept' => 'application/json']]);

tests/TestCase/Database/Log/DebugLogTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Cake\Database\Log\LoggedQuery;
1818
use Cake\TestSuite\TestCase;
1919
use DebugKit\Database\Log\DebugLog;
20+
use PHPUnit\Framework\Attributes\DataProvider;
2021
use Psr\Log\LoggerInterface;
2122
use Psr\Log\LogLevel;
2223

@@ -69,9 +70,9 @@ public function testLog()
6970
/**
7071
* Test log ignores schema reflection
7172
*
72-
* @dataProvider schemaQueryProvider
7373
* @return void
7474
*/
75+
#[DataProvider('schemaQueryProvider')]
7576
public function testLogIgnoreReflection($sql)
7677
{
7778
$query = new LoggedQuery();
@@ -90,9 +91,9 @@ public function testLogIgnoreReflection($sql)
9091
/**
9192
* Test config setting turns off schema ignores
9293
*
93-
* @dataProvider schemaQueryProvider
9494
* @return void
9595
*/
96+
#[DataProvider('schemaQueryProvider')]
9697
public function testLogIgnoreReflectionDisabled($sql)
9798
{
9899
$query = new LoggedQuery();

tests/TestCase/Mailer/Transport/DebugKitTransportTest.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,19 @@ class DebugKitTransportTest extends TestCase
3131
public function setUp(): void
3232
{
3333
$this->log = new ArrayObject();
34-
$this->wrapped = $this->getMockBuilder(AbstractTransport::class)
35-
->onlyMethods(['send'])
36-
->addMethods(['customMethod'])
37-
->getMock();
34+
$this->wrapped = new class extends AbstractTransport {
35+
public string $property;
36+
37+
public function send(Message $message): array
38+
{
39+
return [];
40+
}
41+
42+
public function customMethod(): string
43+
{
44+
return 'bloop';
45+
}
46+
};
3847
$this->transport = new DebugKitTransport(
3948
['debugKitLog' => $this->log],
4049
$this->wrapped
@@ -55,8 +64,6 @@ public function testPropertyProxies()
5564

5665
public function testMethodProxy()
5766
{
58-
$this->wrapped->method('customMethod')
59-
->will($this->returnValue('bloop'));
6067
$this->assertSame('bloop', $this->transport->customMethod());
6168
}
6269

tests/TestCase/Panel/DeprecationsPanelTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function setUp(): void
4040
parent::setUp();
4141
DeprecationsPanel::clearDeprecatedErrors();
4242

43+
$this->loadPlugins(['DebugKit']);
4344
$this->panel = new DeprecationsPanel();
4445

4546
set_error_handler(function ($code, $message, $file, $line, $context = null) {

tests/TestCase/Panel/PackagesPanelTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
use Cake\TestSuite\TestCase;
1919
use DebugKit\Panel\PackagesPanel;
20+
use PHPUnit\Framework\Attributes\DataProvider;
2021

2122
/**
2223
* Class PackagesPanelTest
@@ -55,9 +56,9 @@ public static function packagesProvider()
5556
/**
5657
* test data
5758
*
58-
* @dataProvider packagesProvider
5959
* @return void
6060
*/
61+
#[DataProvider('packagesProvider')]
6162
public function testData($package)
6263
{
6364
$data = $this->panel->data();

tests/TestCase/Panel/VariablesPanelTest.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,15 @@ public function testShutdown()
6969
$update = $requests->updateQuery();
7070
$debugInfoException = $requests->query()->contain('NonExistentAssociation');
7171

72-
$unserializable = new stdClass();
73-
$unserializable->pdo = new PDO('sqlite::memory:');
72+
$unserializableDebugInfo = new class extends stdClass {
73+
public function __debugInfo()
74+
{
75+
$unserializable = new stdClass();
76+
$unserializable->pdo = new PDO('sqlite::memory:');
7477

75-
$unserializableDebugInfo = $this
76-
->getMockBuilder('\stdClass')
77-
->addMethods(['__debugInfo'])
78-
->getMock();
79-
$unserializableDebugInfo->expects($this->any())->method('__debugInfo')->willReturn([
80-
'unserializable' => $unserializable,
81-
]);
78+
return ['unserializable' => $unserializable];
79+
}
80+
};
8281

8382
$resource = fopen('data:text/plain;base64,', 'r');
8483

@@ -87,7 +86,7 @@ public function testShutdown()
8786
};
8887
$vars = [
8988
'resource' => $resource,
90-
// 'unserializableDebugInfo' => $unserializableDebugInfo,
89+
'unserializableDebugInfo' => $unserializableDebugInfo,
9190
'debugInfoException' => $debugInfoException,
9291
'updateQuery' => $update,
9392
'query' => $query,

tests/TestCase/ToolbarServiceTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Cake\TestSuite\TestCase;
2727
use DebugKit\Model\Entity\Request as RequestEntity;
2828
use DebugKit\ToolbarService;
29+
use PHPUnit\Framework\Attributes\DataProvider;
2930

3031
/**
3132
* Test the debug bar
@@ -100,7 +101,7 @@ public function testDisablePanels()
100101
$bar = new ToolbarService($this->events, ['panels' => [
101102
'DebugKit.SqlLog' => false,
102103
'DebugKit.Cache' => true,
103-
'DebugKit.Session',
104+
'DebugKit.Session' => true,
104105
]]);
105106
$bar->loadPanels();
106107

@@ -407,9 +408,9 @@ public function testIsEnabled()
407408
*
408409
* @param string $domain The domain name where the app is hosted
409410
* @param bool $isEnabled The expectation for isEnabled()
410-
* @dataProvider domainsProvider
411411
* @return void
412412
*/
413+
#[DataProvider('domainsProvider')]
413414
public function testIsEnabledProductionEnv($domain, $isEnabled)
414415
{
415416
Configure::write('debug', true);

0 commit comments

Comments
 (0)