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

allow PHPUnit 11 and adjust tests for PHPUnit 11 #1015

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"require-dev": {
"cakephp/authorization": "^3.0",
"cakephp/cakephp-codesniffer": "^5.0",
"phpunit/phpunit": "^10.5.5"
"phpunit/phpunit": "^10.5.5 || ^11.1.3"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ parameters:
path: src/Command/BenchmarkCommand.php

-
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\\}\\}\\.$#"
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\\}\\}\\.$#"
count: 1
path: src/Mailer/Transport/DebugKitTransport.php

Expand Down
14 changes: 0 additions & 14 deletions tests/TestCase/Controller/MailPreviewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
*/
namespace DebugKit\Test\TestCase\Controller;

use Cake\Routing\Router;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
use DebugKit\Test\TestCase\FixtureFactoryTrait;
use DebugKit\TestApp\Application;

/**
* Mail preview controller test
Expand All @@ -29,18 +27,6 @@ class MailPreviewControllerTest extends TestCase
use FixtureFactoryTrait;
use IntegrationTestTrait;

/**
* Setup method.
*
* @return void
*/
public function setUp(): void
{
parent::setUp();
Router::createRouteBuilder('/')->connect('/users/{action}/*', ['controller' => 'Users']);
$this->configApplication(Application::class, []);
}

/**
* Test that plugin is passed to the view in email action
*
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Controller/ToolbarControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ public function testClearCache()
$mock = $this->getMockBuilder('Cake\Cache\CacheEngine')->getMock();
$mock->expects($this->once())
->method('init')
->will($this->returnValue(true));
->willReturn(true);
$mock->expects($this->once())
->method('clear')
->will($this->returnValue(true));
->willReturn(true);
Cache::setConfig('testing', $mock);

$this->configRequest(['headers' => ['Accept' => 'application/json']]);
Expand Down
5 changes: 3 additions & 2 deletions tests/TestCase/Database/Log/DebugLogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Cake\Database\Log\LoggedQuery;
use Cake\TestSuite\TestCase;
use DebugKit\Database\Log\DebugLog;
use PHPUnit\Framework\Attributes\DataProvider;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;

Expand Down Expand Up @@ -69,9 +70,9 @@ public function testLog()
/**
* Test log ignores schema reflection
*
* @dataProvider schemaQueryProvider
* @return void
*/
#[DataProvider('schemaQueryProvider')]
public function testLogIgnoreReflection($sql)
{
$query = new LoggedQuery();
Expand All @@ -90,9 +91,9 @@ public function testLogIgnoreReflection($sql)
/**
* Test config setting turns off schema ignores
*
* @dataProvider schemaQueryProvider
* @return void
*/
#[DataProvider('schemaQueryProvider')]
public function testLogIgnoreReflectionDisabled($sql)
{
$query = new LoggedQuery();
Expand Down
19 changes: 13 additions & 6 deletions tests/TestCase/Mailer/Transport/DebugKitTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,19 @@ class DebugKitTransportTest extends TestCase
public function setUp(): void
{
$this->log = new ArrayObject();
$this->wrapped = $this->getMockBuilder(AbstractTransport::class)
->onlyMethods(['send'])
->addMethods(['customMethod'])
->getMock();
$this->wrapped = new class extends AbstractTransport {
public string $property;

public function send(Message $message): array
{
return [];
}

public function customMethod(): string
{
return 'bloop';
}
};
$this->transport = new DebugKitTransport(
['debugKitLog' => $this->log],
$this->wrapped
Expand All @@ -55,8 +64,6 @@ public function testPropertyProxies()

public function testMethodProxy()
{
$this->wrapped->method('customMethod')
->will($this->returnValue('bloop'));
$this->assertSame('bloop', $this->transport->customMethod());
}

Expand Down
1 change: 1 addition & 0 deletions tests/TestCase/Panel/DeprecationsPanelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function setUp(): void
parent::setUp();
DeprecationsPanel::clearDeprecatedErrors();

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

set_error_handler(function ($code, $message, $file, $line, $context = null) {
Expand Down
3 changes: 2 additions & 1 deletion tests/TestCase/Panel/PackagesPanelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use Cake\TestSuite\TestCase;
use DebugKit\Panel\PackagesPanel;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* Class PackagesPanelTest
Expand Down Expand Up @@ -55,9 +56,9 @@ public static function packagesProvider()
/**
* test data
*
* @dataProvider packagesProvider
* @return void
*/
#[DataProvider('packagesProvider')]
public function testData($package)
{
$data = $this->panel->data();
Expand Down
19 changes: 9 additions & 10 deletions tests/TestCase/Panel/VariablesPanelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,15 @@ public function testShutdown()
$update = $requests->updateQuery();
$debugInfoException = $requests->query()->contain('NonExistentAssociation');

$unserializable = new stdClass();
$unserializable->pdo = new PDO('sqlite::memory:');
$unserializableDebugInfo = new class extends stdClass {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this approach much better than mocks. We should do more of this 👏

public function __debugInfo()
{
$unserializable = new stdClass();
$unserializable->pdo = new PDO('sqlite::memory:');

$unserializableDebugInfo = $this
->getMockBuilder('\stdClass')
->addMethods(['__debugInfo'])
->getMock();
$unserializableDebugInfo->expects($this->any())->method('__debugInfo')->willReturn([
'unserializable' => $unserializable,
]);
return ['unserializable' => $unserializable];
}
};

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

Expand All @@ -87,7 +86,7 @@ public function testShutdown()
};
$vars = [
'resource' => $resource,
// 'unserializableDebugInfo' => $unserializableDebugInfo,
'unserializableDebugInfo' => $unserializableDebugInfo,
'debugInfoException' => $debugInfoException,
'updateQuery' => $update,
'query' => $query,
Expand Down
5 changes: 3 additions & 2 deletions tests/TestCase/ToolbarServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Cake\TestSuite\TestCase;
use DebugKit\Model\Entity\Request as RequestEntity;
use DebugKit\ToolbarService;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* Test the debug bar
Expand Down Expand Up @@ -100,7 +101,7 @@ public function testDisablePanels()
$bar = new ToolbarService($this->events, ['panels' => [
'DebugKit.SqlLog' => false,
'DebugKit.Cache' => true,
'DebugKit.Session',
'DebugKit.Session' => true,
]]);
$bar->loadPanels();

Expand Down Expand Up @@ -407,9 +408,9 @@ public function testIsEnabled()
*
* @param string $domain The domain name where the app is hosted
* @param bool $isEnabled The expectation for isEnabled()
* @dataProvider domainsProvider
* @return void
*/
#[DataProvider('domainsProvider')]
public function testIsEnabledProductionEnv($domain, $isEnabled)
{
Configure::write('debug', true);
Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase/View/Helper/CredentialsHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Cake\TestSuite\TestCase;
use Cake\View\View;
use DebugKit\View\Helper\CredentialsHelper;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* Class CredentialsHelperTestCase
Expand Down Expand Up @@ -65,6 +66,7 @@ public function tearDown(): void
* @dataProvider credentialsProvider
* @return void
*/
#[DataProvider('credentialsProvider')]
public function testFilter($in, $out)
{
$this->assertSame($out, $this->Helper->filter($in));
Expand Down
11 changes: 11 additions & 0 deletions tests/test_app/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Cake\Http\MiddlewareQueue;
use Cake\Routing\Middleware\AssetMiddleware;
use Cake\Routing\Middleware\RoutingMiddleware;
use Cake\Routing\RouteBuilder;

/**
* Application setup class.
Expand All @@ -39,6 +40,16 @@ public function bootstrap(): void
$this->addPlugin('DebugKit');
}

/**
* @param \Cake\Routing\RouteBuilder $routes
* @return void
*/
public function routes(RouteBuilder $routes): void
{
parent::routes($routes);
$routes->connect('/users/{action}/*', ['controller' => 'Users']);
}

/**
* Setup the middleware queue your application will use.
*
Expand Down
Loading