From 4d9a95f97005705ade05c71d4c1a64fd3844272c Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Tue, 17 Oct 2017 18:54:17 -0700 Subject: [PATCH] Don't trigger PHP errors for unused Shell\Command Change-Id: Id29da4f21a44ccb18d8a2ae11348d69ca3233aa5 --- includes/shell/Command.php | 8 +++++--- tests/phpunit/includes/shell/CommandTest.php | 11 ----------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/includes/shell/Command.php b/includes/shell/Command.php index 59f40bff26..a16f4af32f 100644 --- a/includes/shell/Command.php +++ b/includes/shell/Command.php @@ -83,12 +83,14 @@ class Command { */ public function __destruct() { if ( !$this->everExecuted ) { + $context = [ 'command' => $this->command ]; $message = __CLASS__ . " was instantiated, but execute() was never called."; if ( $this->method ) { - $message .= " Calling method: {$this->method}."; + $message .= ' Calling method: {method}.'; + $context['method'] = $this->method; } - $message .= " Command: {$this->command}"; - trigger_error( $message, E_USER_NOTICE ); + $message .= ' Command: {command}'; + $this->logger->warning( $message, $context ); } } diff --git a/tests/phpunit/includes/shell/CommandTest.php b/tests/phpunit/includes/shell/CommandTest.php index 34434b9aaf..32d855ea39 100644 --- a/tests/phpunit/includes/shell/CommandTest.php +++ b/tests/phpunit/includes/shell/CommandTest.php @@ -6,17 +6,6 @@ use MediaWiki\Shell\Command; * @group Shell */ class CommandTest extends PHPUnit_Framework_TestCase { - /** - * @expectedException PHPUnit_Framework_Error_Notice - */ - public function testDestruct() { - if ( defined( 'HHVM_VERSION' ) ) { - $this->markTestSkipped( 'destructors are unreliable in HHVM' ); - } - $command = new Command(); - $command->params( 'true' ); - } - private function requirePosix() { if ( wfIsWindows() ) { $this->markTestSkipped( 'This test requires a POSIX environment.' ); -- 2.20.1