Don't trigger PHP errors for unused Shell\Command
authorMax Semenik <maxsem.wiki@gmail.com>
Wed, 18 Oct 2017 01:54:17 +0000 (18:54 -0700)
committerMax Semenik <maxsem.wiki@gmail.com>
Wed, 18 Oct 2017 01:55:11 +0000 (18:55 -0700)
Change-Id: Id29da4f21a44ccb18d8a2ae11348d69ca3233aa5

includes/shell/Command.php
tests/phpunit/includes/shell/CommandTest.php

index 59f40bf..a16f4af 100644 (file)
@@ -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 );
                }
        }
 
index 34434b9..32d855e 100644 (file)
@@ -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.' );