diff --git a/composer.json b/composer.json index 539bd9a4..fa2a6ca9 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 52d8b990..36a49710 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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\\, 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\\, message\\: array\\{text\\: string, html\\: string\\}\\}\\.$#" count: 1 path: src/Mailer/Transport/DebugKitTransport.php diff --git a/tests/TestCase/Controller/MailPreviewControllerTest.php b/tests/TestCase/Controller/MailPreviewControllerTest.php index 841e2e82..ab5617f3 100644 --- a/tests/TestCase/Controller/MailPreviewControllerTest.php +++ b/tests/TestCase/Controller/MailPreviewControllerTest.php @@ -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 @@ -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 * diff --git a/tests/TestCase/Controller/ToolbarControllerTest.php b/tests/TestCase/Controller/ToolbarControllerTest.php index 7c461faf..dddac6ac 100644 --- a/tests/TestCase/Controller/ToolbarControllerTest.php +++ b/tests/TestCase/Controller/ToolbarControllerTest.php @@ -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']]); diff --git a/tests/TestCase/Database/Log/DebugLogTest.php b/tests/TestCase/Database/Log/DebugLogTest.php index 170ba2cf..b60834a6 100644 --- a/tests/TestCase/Database/Log/DebugLogTest.php +++ b/tests/TestCase/Database/Log/DebugLogTest.php @@ -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; @@ -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(); @@ -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(); diff --git a/tests/TestCase/Mailer/Transport/DebugKitTransportTest.php b/tests/TestCase/Mailer/Transport/DebugKitTransportTest.php index a32daf8f..8d58f276 100644 --- a/tests/TestCase/Mailer/Transport/DebugKitTransportTest.php +++ b/tests/TestCase/Mailer/Transport/DebugKitTransportTest.php @@ -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 @@ -55,8 +64,6 @@ public function testPropertyProxies() public function testMethodProxy() { - $this->wrapped->method('customMethod') - ->will($this->returnValue('bloop')); $this->assertSame('bloop', $this->transport->customMethod()); } diff --git a/tests/TestCase/Panel/DeprecationsPanelTest.php b/tests/TestCase/Panel/DeprecationsPanelTest.php index 797007f0..9b81b76c 100644 --- a/tests/TestCase/Panel/DeprecationsPanelTest.php +++ b/tests/TestCase/Panel/DeprecationsPanelTest.php @@ -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) { diff --git a/tests/TestCase/Panel/PackagesPanelTest.php b/tests/TestCase/Panel/PackagesPanelTest.php index 0f6e5d21..ceaaee23 100644 --- a/tests/TestCase/Panel/PackagesPanelTest.php +++ b/tests/TestCase/Panel/PackagesPanelTest.php @@ -17,6 +17,7 @@ use Cake\TestSuite\TestCase; use DebugKit\Panel\PackagesPanel; +use PHPUnit\Framework\Attributes\DataProvider; /** * Class PackagesPanelTest @@ -55,9 +56,9 @@ public static function packagesProvider() /** * test data * - * @dataProvider packagesProvider * @return void */ + #[DataProvider('packagesProvider')] public function testData($package) { $data = $this->panel->data(); diff --git a/tests/TestCase/Panel/VariablesPanelTest.php b/tests/TestCase/Panel/VariablesPanelTest.php index d163a037..3e4787c0 100644 --- a/tests/TestCase/Panel/VariablesPanelTest.php +++ b/tests/TestCase/Panel/VariablesPanelTest.php @@ -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 { + 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'); @@ -87,7 +86,7 @@ public function testShutdown() }; $vars = [ 'resource' => $resource, - // 'unserializableDebugInfo' => $unserializableDebugInfo, + 'unserializableDebugInfo' => $unserializableDebugInfo, 'debugInfoException' => $debugInfoException, 'updateQuery' => $update, 'query' => $query, diff --git a/tests/TestCase/ToolbarServiceTest.php b/tests/TestCase/ToolbarServiceTest.php index 5bda2582..2922ccab 100644 --- a/tests/TestCase/ToolbarServiceTest.php +++ b/tests/TestCase/ToolbarServiceTest.php @@ -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 @@ -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(); @@ -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); diff --git a/tests/TestCase/View/Helper/CredentialsHelperTest.php b/tests/TestCase/View/Helper/CredentialsHelperTest.php index aaccfc96..904c97dd 100644 --- a/tests/TestCase/View/Helper/CredentialsHelperTest.php +++ b/tests/TestCase/View/Helper/CredentialsHelperTest.php @@ -19,6 +19,7 @@ use Cake\TestSuite\TestCase; use Cake\View\View; use DebugKit\View\Helper\CredentialsHelper; +use PHPUnit\Framework\Attributes\DataProvider; /** * Class CredentialsHelperTestCase @@ -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)); diff --git a/tests/test_app/Application.php b/tests/test_app/Application.php index bb99a461..d7f67d29 100644 --- a/tests/test_app/Application.php +++ b/tests/test_app/Application.php @@ -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. @@ -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. *