mirror of
				https://github.com/yiisoft/yii2.git
				synced 2025-10-31 10:39:59 +08:00 
			
		
		
		
	Replace deprecated PHPUnit mock builder setMethods() usage with createPartialMock(), onlyMethods() and addMethods() methods. (#20616)
				
					
				
			This commit is contained in:
		| @ -168,9 +168,8 @@ class BaseYiiTest extends TestCase | |||||||
|      */ |      */ | ||||||
|     public function testLog(): void |     public function testLog(): void | ||||||
|     { |     { | ||||||
|         $logger = $this->getMockBuilder('yii\\log\\Logger') |         $logger = $this->createPartialMock(Logger::class, ['log']); | ||||||
|             ->setMethods(['log']) |  | ||||||
|             ->getMock(); |  | ||||||
|         BaseYii::setLogger($logger); |         BaseYii::setLogger($logger); | ||||||
|  |  | ||||||
|         $logger->expects($this->exactly(6)) |         $logger->expects($this->exactly(6)) | ||||||
|  | |||||||
| @ -119,13 +119,11 @@ class CacheableWidgetBehaviorTest extends TestCase | |||||||
|      */ |      */ | ||||||
|     private function getWidgetMock($widgetClass) |     private function getWidgetMock($widgetClass) | ||||||
|     { |     { | ||||||
|         $widgetMock = $this->getMockBuilder($widgetClass) |         return $this->getMockBuilder($widgetClass) | ||||||
|             ->setMethods(['run']) |             ->onlyMethods(['run']) | ||||||
|             ->enableOriginalConstructor() |             ->enableOriginalConstructor() | ||||||
|             ->enableProxyingToOriginalMethods() |             ->enableProxyingToOriginalMethods() | ||||||
|             ->getMock(); |             ->getMock(); | ||||||
|  |  | ||||||
|         return $widgetMock; |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | |||||||
| @ -10,6 +10,7 @@ namespace yiiunit\framework\console\controllers; | |||||||
|  |  | ||||||
| use Exception; | use Exception; | ||||||
| use Yii; | use Yii; | ||||||
|  | use yii\base\Module; | ||||||
| use yii\console\controllers\AssetController; | use yii\console\controllers\AssetController; | ||||||
| use yii\helpers\ArrayHelper; | use yii\helpers\ArrayHelper; | ||||||
| use yii\helpers\FileHelper; | use yii\helpers\FileHelper; | ||||||
| @ -74,10 +75,11 @@ class AssetControllerTest extends TestCase | |||||||
|      */ |      */ | ||||||
|     protected function createAssetController() |     protected function createAssetController() | ||||||
|     { |     { | ||||||
|         $module = $this->getMockBuilder('yii\\base\\Module') |         $module = $this->getMockBuilder(Module::class) | ||||||
|             ->setMethods(['fake']) |             ->addMethods(['fake']) | ||||||
|             ->setConstructorArgs(['console']) |             ->setConstructorArgs(['console']) | ||||||
|             ->getMock(); |             ->getMock(); | ||||||
|  |  | ||||||
|         $assetController = new AssetControllerMock('asset', $module); |         $assetController = new AssetControllerMock('asset', $module); | ||||||
|         $assetController->interactive = false; |         $assetController->interactive = false; | ||||||
|         $assetController->jsCompressor = 'cp {from} {to}'; |         $assetController->jsCompressor = 'cp {from} {to}'; | ||||||
|  | |||||||
| @ -9,6 +9,7 @@ | |||||||
| namespace yiiunit\framework\console\controllers; | namespace yiiunit\framework\console\controllers; | ||||||
|  |  | ||||||
| use Yii; | use Yii; | ||||||
|  | use yii\base\Module; | ||||||
| use yii\console\controllers\MessageController; | use yii\console\controllers\MessageController; | ||||||
| use yii\helpers\FileHelper; | use yii\helpers\FileHelper; | ||||||
| use yii\helpers\VarDumper; | use yii\helpers\VarDumper; | ||||||
| @ -62,10 +63,11 @@ abstract class BaseMessageControllerTest extends TestCase | |||||||
|      */ |      */ | ||||||
|     protected function createMessageController() |     protected function createMessageController() | ||||||
|     { |     { | ||||||
|         $module = $this->getMockBuilder('yii\\base\\Module') |         $module = $this->getMockBuilder(Module::class) | ||||||
|             ->setMethods(['fake']) |             ->addMethods(['fake']) | ||||||
|             ->setConstructorArgs(['console']) |             ->setConstructorArgs(['console']) | ||||||
|             ->getMock(); |             ->getMock(); | ||||||
|  |  | ||||||
|         $messageController = new MessageControllerMock('message', $module); |         $messageController = new MessageControllerMock('message', $module); | ||||||
|         $messageController->interactive = false; |         $messageController->interactive = false; | ||||||
|  |  | ||||||
|  | |||||||
| @ -8,6 +8,7 @@ | |||||||
|  |  | ||||||
| namespace yiiunit\framework\console\controllers; | namespace yiiunit\framework\console\controllers; | ||||||
|  |  | ||||||
|  | use yii\base\Module; | ||||||
| use yii\console\controllers\HelpController; | use yii\console\controllers\HelpController; | ||||||
| use yii\helpers\Console; | use yii\helpers\Console; | ||||||
| use yiiunit\TestCase; | use yiiunit\TestCase; | ||||||
| @ -33,10 +34,11 @@ class HelpControllerTest extends TestCase | |||||||
|      */ |      */ | ||||||
|     protected function createController() |     protected function createController() | ||||||
|     { |     { | ||||||
|         $module = $this->getMockBuilder('yii\\base\\Module') |         $module = $this->getMockBuilder(Module::class) | ||||||
|             ->setMethods(['fake']) |             ->addMethods(['fake']) | ||||||
|             ->setConstructorArgs(['console']) |             ->setConstructorArgs(['console']) | ||||||
|             ->getMock(); |             ->getMock(); | ||||||
|  |  | ||||||
|         return new BufferedHelpController('help', $module); |         return new BufferedHelpController('help', $module); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | |||||||
| @ -9,6 +9,7 @@ | |||||||
| namespace yiiunit\framework\console\controllers; | namespace yiiunit\framework\console\controllers; | ||||||
|  |  | ||||||
| use Yii; | use Yii; | ||||||
|  | use yii\base\Module; | ||||||
| use yii\console\controllers\BaseMigrateController; | use yii\console\controllers\BaseMigrateController; | ||||||
| use yii\console\ExitCode; | use yii\console\ExitCode; | ||||||
| use yii\helpers\FileHelper; | use yii\helpers\FileHelper; | ||||||
| @ -78,14 +79,16 @@ trait MigrateControllerTestTrait | |||||||
|      */ |      */ | ||||||
|     protected function createMigrateController(array $config = []) |     protected function createMigrateController(array $config = []) | ||||||
|     { |     { | ||||||
|         $module = $this->getMockBuilder('yii\\base\\Module') |         $module = $this->getMockBuilder(Module::class) | ||||||
|             ->setMethods(['fake']) |             ->addMethods(['fake']) | ||||||
|             ->setConstructorArgs(['console']) |             ->setConstructorArgs(['console']) | ||||||
|             ->getMock(); |             ->getMock(); | ||||||
|  |  | ||||||
|         $class = $this->migrateControllerClass; |         $class = $this->migrateControllerClass; | ||||||
|         $migrateController = new $class('migrate', $module); |         $migrateController = new $class('migrate', $module); | ||||||
|         $migrateController->interactive = false; |         $migrateController->interactive = false; | ||||||
|         $migrateController->migrationPath = $this->migrationPath; |         $migrateController->migrationPath = $this->migrationPath; | ||||||
|  |  | ||||||
|         return Yii::configure($migrateController, $config); |         return Yii::configure($migrateController, $config); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | |||||||
| @ -32,7 +32,7 @@ class ServeControllerTest extends TestCase | |||||||
|         /** @var ServeController $serveController */ |         /** @var ServeController $serveController */ | ||||||
|         $serveController = $this->getMockBuilder(ServeControllerMocK::class) |         $serveController = $this->getMockBuilder(ServeControllerMocK::class) | ||||||
|             ->setConstructorArgs(['serve', Yii::$app]) |             ->setConstructorArgs(['serve', Yii::$app]) | ||||||
|             ->setMethods(['isAddressTaken', 'runCommand']) |             ->onlyMethods(['isAddressTaken', 'runCommand']) | ||||||
|             ->getMock(); |             ->getMock(); | ||||||
|  |  | ||||||
|         $serveController->expects($this->once())->method('isAddressTaken')->willReturn(true); |         $serveController->expects($this->once())->method('isAddressTaken')->willReturn(true); | ||||||
| @ -57,7 +57,7 @@ class ServeControllerTest extends TestCase | |||||||
|         /** @var ServeController $serveController */ |         /** @var ServeController $serveController */ | ||||||
|         $serveController = $this->getMockBuilder(ServeControllerMock::class) |         $serveController = $this->getMockBuilder(ServeControllerMock::class) | ||||||
|             ->setConstructorArgs(['serve', Yii::$app]) |             ->setConstructorArgs(['serve', Yii::$app]) | ||||||
|             ->setMethods(['runCommand']) |             ->onlyMethods(['runCommand']) | ||||||
|             ->getMock(); |             ->getMock(); | ||||||
|  |  | ||||||
|         $serveController->docroot = $docroot; |         $serveController->docroot = $docroot; | ||||||
| @ -83,7 +83,7 @@ class ServeControllerTest extends TestCase | |||||||
|         /** @var ServeController $serveController */ |         /** @var ServeController $serveController */ | ||||||
|         $serveController = $this->getMockBuilder(ServeControllerMock::class) |         $serveController = $this->getMockBuilder(ServeControllerMock::class) | ||||||
|             ->setConstructorArgs(['serve', Yii::$app]) |             ->setConstructorArgs(['serve', Yii::$app]) | ||||||
|             ->setMethods(['runCommand']) |             ->onlyMethods(['runCommand']) | ||||||
|             ->getMock(); |             ->getMock(); | ||||||
|  |  | ||||||
|         $serveController->docroot = $docroot; |         $serveController->docroot = $docroot; | ||||||
| @ -107,7 +107,7 @@ class ServeControllerTest extends TestCase | |||||||
|         /** @var ServeController $serveController */ |         /** @var ServeController $serveController */ | ||||||
|         $serveController = $this->getMockBuilder(ServeControllerMock::class) |         $serveController = $this->getMockBuilder(ServeControllerMock::class) | ||||||
|             ->setConstructorArgs(['serve', Yii::$app]) |             ->setConstructorArgs(['serve', Yii::$app]) | ||||||
|             ->setMethods(['runCommand']) |             ->onlyMethods(['runCommand']) | ||||||
|             ->getMock(); |             ->getMock(); | ||||||
|  |  | ||||||
|         $serveController->docroot = $docroot; |         $serveController->docroot = $docroot; | ||||||
| @ -133,7 +133,7 @@ class ServeControllerTest extends TestCase | |||||||
|         /** @var ServeController $serveController */ |         /** @var ServeController $serveController */ | ||||||
|         $serveController = $this->getMockBuilder(ServeControllerMock::class) |         $serveController = $this->getMockBuilder(ServeControllerMock::class) | ||||||
|             ->setConstructorArgs(['serve', Yii::$app]) |             ->setConstructorArgs(['serve', Yii::$app]) | ||||||
|             ->setMethods(['runCommand']) |             ->onlyMethods(['runCommand']) | ||||||
|             ->getMock(); |             ->getMock(); | ||||||
|  |  | ||||||
|         $serveController->docroot = $docroot; |         $serveController->docroot = $docroot; | ||||||
|  | |||||||
| @ -43,9 +43,7 @@ class AccessRuleTest extends TestCase | |||||||
|     protected function mockRequest($method = 'GET') |     protected function mockRequest($method = 'GET') | ||||||
|     { |     { | ||||||
|         /** @var Request $request */ |         /** @var Request $request */ | ||||||
|         $request = $this->getMockBuilder('\yii\web\Request') |         $request = $this->createPartialMock(Request::class, ['getMethod']); | ||||||
|             ->setMethods(['getMethod']) |  | ||||||
|             ->getMock(); |  | ||||||
|         $request->method('getMethod')->willReturn($method); |         $request->method('getMethod')->willReturn($method); | ||||||
|  |  | ||||||
|         return $request; |         return $request; | ||||||
|  | |||||||
| @ -27,9 +27,7 @@ class AjaxFilterTest extends TestCase | |||||||
|     protected function mockRequest($isAjax) |     protected function mockRequest($isAjax) | ||||||
|     { |     { | ||||||
|         /** @var Request $request */ |         /** @var Request $request */ | ||||||
|         $request = $this->getMockBuilder('\yii\web\Request') |         $request = $this->createPartialMock(Request::class, ['getIsAjax']); | ||||||
|             ->setMethods(['getIsAjax']) |  | ||||||
|             ->getMock(); |  | ||||||
|         $request->method('getIsAjax')->willReturn($isAjax); |         $request->method('getIsAjax')->willReturn($isAjax); | ||||||
|  |  | ||||||
|         return $request; |         return $request; | ||||||
|  | |||||||
| @ -39,11 +39,10 @@ class AuthMethodTest extends TestCase | |||||||
|      */ |      */ | ||||||
|     protected function createFilter($authenticateCallback) |     protected function createFilter($authenticateCallback) | ||||||
|     { |     { | ||||||
|         $filter = $this->getMockBuilder(AuthMethod::class) |         $filter = $this->createPartialMock(AuthMethod::class, ['authenticate']); | ||||||
|             ->setMethods(['authenticate']) |  | ||||||
|             ->getMock(); |  | ||||||
|         $filter->method('authenticate')->willReturnCallback($authenticateCallback); |         $filter->method('authenticate')->willReturnCallback($authenticateCallback); | ||||||
|  |  | ||||||
|  |  | ||||||
|         return $filter; |         return $filter; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | |||||||
| @ -23,6 +23,7 @@ namespace yiiunit\framework\log { | |||||||
|     use yii\base\UserException; |     use yii\base\UserException; | ||||||
|     use yii\log\Dispatcher; |     use yii\log\Dispatcher; | ||||||
|     use yii\log\Logger; |     use yii\log\Logger; | ||||||
|  |     use yii\log\Target; | ||||||
|     use yiiunit\TestCase; |     use yiiunit\TestCase; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @ -154,11 +155,9 @@ namespace yiiunit\framework\log { | |||||||
|          */ |          */ | ||||||
|         public function testDispatchWithDisabledTarget(): void |         public function testDispatchWithDisabledTarget(): void | ||||||
|         { |         { | ||||||
|             $target = $this->getMockBuilder('yii\\log\\Target') |             $target = $this->createPartialMock(Target::class, ['collect', 'export']); | ||||||
|                 ->setMethods(['collect']) |  | ||||||
|                 ->getMockForAbstractClass(); |  | ||||||
|  |  | ||||||
|             $target->expects($this->never())->method($this->anything()); |             $target->expects($this->never())->method($this->anything()); | ||||||
|  |  | ||||||
|             $target->enabled = false; |             $target->enabled = false; | ||||||
|  |  | ||||||
|             $dispatcher = new Dispatcher(['targets' => ['fakeTarget' => $target]]); |             $dispatcher = new Dispatcher(['targets' => ['fakeTarget' => $target]]); | ||||||
| @ -170,10 +169,7 @@ namespace yiiunit\framework\log { | |||||||
|          */ |          */ | ||||||
|         public function testDispatchWithSuccessTargetCollect(): void |         public function testDispatchWithSuccessTargetCollect(): void | ||||||
|         { |         { | ||||||
|             $target = $this->getMockBuilder('yii\\log\\Target') |             $target = $this->createPartialMock(Target::class, ['collect', 'export']); | ||||||
|                 ->setMethods(['collect']) |  | ||||||
|                 ->getMockForAbstractClass(); |  | ||||||
|  |  | ||||||
|             $target->expects($this->once()) |             $target->expects($this->once()) | ||||||
|                 ->method('collect') |                 ->method('collect') | ||||||
|                 ->with( |                 ->with( | ||||||
| @ -191,13 +187,8 @@ namespace yiiunit\framework\log { | |||||||
|         public function testDispatchWithFakeTarget2ThrowExceptionWhenCollect(): void |         public function testDispatchWithFakeTarget2ThrowExceptionWhenCollect(): void | ||||||
|         { |         { | ||||||
|             static::$microtimeIsMocked = true; |             static::$microtimeIsMocked = true; | ||||||
|             $target1 = $this->getMockBuilder('yii\\log\\Target') |             $target1 = $this->createPartialMock(Target::class, ['collect', 'export']); | ||||||
|                 ->setMethods(['collect']) |             $target2 = $this->createPartialMock(Target::class, ['collect', 'export']); | ||||||
|                 ->getMockForAbstractClass(); |  | ||||||
|  |  | ||||||
|             $target2 = $this->getMockBuilder('yii\\log\\Target') |  | ||||||
|                 ->setMethods(['collect']) |  | ||||||
|                 ->getMockForAbstractClass(); |  | ||||||
|  |  | ||||||
|             $target1->expects($this->exactly(2)) |             $target1->expects($this->exactly(2)) | ||||||
|                 ->method('collect') |                 ->method('collect') | ||||||
|  | |||||||
| @ -10,6 +10,8 @@ namespace yiiunit\framework\log; | |||||||
|  |  | ||||||
| use yii\base\InvalidConfigException; | use yii\base\InvalidConfigException; | ||||||
| use yii\log\EmailTarget; | use yii\log\EmailTarget; | ||||||
|  | use yii\mail\BaseMailer; | ||||||
|  | use yii\mail\BaseMessage; | ||||||
| use yiiunit\TestCase; | use yiiunit\TestCase; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @ -29,9 +31,7 @@ class EmailTargetTest extends TestCase | |||||||
|     protected function setUp(): void |     protected function setUp(): void | ||||||
|     { |     { | ||||||
|         parent::setUp(); |         parent::setUp(); | ||||||
|         $this->mailer = $this->getMockBuilder('yii\\mail\\BaseMailer') |         $this->mailer = $this->createPartialMock(BaseMailer::class, ['compose', 'sendMessage']); | ||||||
|             ->setMethods(['compose']) |  | ||||||
|             ->getMockForAbstractClass(); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @ -65,8 +65,8 @@ class EmailTargetTest extends TestCase | |||||||
|         $messages = [$message1, $message2]; |         $messages = [$message1, $message2]; | ||||||
|         $textBody = wordwrap(implode("\n", [$message1[0], $message2[0]]), 70); |         $textBody = wordwrap(implode("\n", [$message1[0], $message2[0]]), 70); | ||||||
|  |  | ||||||
|         $message = $this->getMockBuilder('yii\\mail\\BaseMessage') |         $message = $this->getMockBuilder(BaseMessage::class) | ||||||
|             ->setMethods(['setTextBody', 'send', 'setSubject']) |             ->onlyMethods(['setTextBody', 'send', 'setSubject']) | ||||||
|             ->getMockForAbstractClass(); |             ->getMockForAbstractClass(); | ||||||
|         $message->method('send')->willReturn(true); |         $message->method('send')->willReturn(true); | ||||||
|  |  | ||||||
| @ -76,8 +76,9 @@ class EmailTargetTest extends TestCase | |||||||
|         $message->expects($this->once())->method('send')->with($this->equalTo($this->mailer)); |         $message->expects($this->once())->method('send')->with($this->equalTo($this->mailer)); | ||||||
|         $message->expects($this->once())->method('setSubject')->with($this->equalTo('Hello world')); |         $message->expects($this->once())->method('setSubject')->with($this->equalTo('Hello world')); | ||||||
|  |  | ||||||
|         $mailTarget = $this->getMockBuilder('yii\\log\\EmailTarget') |         /** @var EmailTarget $mailTarget */ | ||||||
|             ->setMethods(['formatMessage']) |         $mailTarget = $this->getMockBuilder(EmailTarget::class) | ||||||
|  |             ->onlyMethods(['formatMessage']) | ||||||
|             ->setConstructorArgs([ |             ->setConstructorArgs([ | ||||||
|                 [ |                 [ | ||||||
|                     'mailer' => $this->mailer, |                     'mailer' => $this->mailer, | ||||||
| @ -110,8 +111,8 @@ class EmailTargetTest extends TestCase | |||||||
|         $messages = [$message1, $message2]; |         $messages = [$message1, $message2]; | ||||||
|         $textBody = wordwrap(implode("\n", [$message1[0], $message2[0]]), 70); |         $textBody = wordwrap(implode("\n", [$message1[0], $message2[0]]), 70); | ||||||
|  |  | ||||||
|         $message = $this->getMockBuilder('yii\\mail\\BaseMessage') |         $message = $this->getMockBuilder(BaseMessage::class) | ||||||
|             ->setMethods(['setTextBody', 'send', 'setSubject']) |             ->onlyMethods(['setTextBody', 'send', 'setSubject']) | ||||||
|             ->getMockForAbstractClass(); |             ->getMockForAbstractClass(); | ||||||
|         $message->method('send')->willReturn(true); |         $message->method('send')->willReturn(true); | ||||||
|  |  | ||||||
| @ -121,8 +122,9 @@ class EmailTargetTest extends TestCase | |||||||
|         $message->expects($this->once())->method('send')->with($this->equalTo($this->mailer)); |         $message->expects($this->once())->method('send')->with($this->equalTo($this->mailer)); | ||||||
|         $message->expects($this->once())->method('setSubject')->with($this->equalTo('Application Log')); |         $message->expects($this->once())->method('setSubject')->with($this->equalTo('Application Log')); | ||||||
|  |  | ||||||
|         $mailTarget = $this->getMockBuilder('yii\\log\\EmailTarget') |         /** @var EmailTarget $mailTarget */ | ||||||
|             ->setMethods(['formatMessage']) |         $mailTarget = $this->getMockBuilder(EmailTarget::class) | ||||||
|  |             ->onlyMethods(['formatMessage']) | ||||||
|             ->setConstructorArgs([ |             ->setConstructorArgs([ | ||||||
|                 [ |                 [ | ||||||
|                     'mailer' => $this->mailer, |                     'mailer' => $this->mailer, | ||||||
| @ -150,13 +152,15 @@ class EmailTargetTest extends TestCase | |||||||
|      */ |      */ | ||||||
|     public function testExportWithSendFailure(): void |     public function testExportWithSendFailure(): void | ||||||
|     { |     { | ||||||
|         $message = $this->getMockBuilder('yii\\mail\\BaseMessage') |         $message = $this->getMockBuilder(BaseMessage::class) | ||||||
|             ->setMethods(['send']) |             ->onlyMethods(['send']) | ||||||
|             ->getMockForAbstractClass(); |             ->getMockForAbstractClass(); | ||||||
|         $message->method('send')->willReturn(false); |         $message->method('send')->willReturn(false); | ||||||
|         $this->mailer->expects($this->once())->method('compose')->willReturn($message); |         $this->mailer->expects($this->once())->method('compose')->willReturn($message); | ||||||
|         $mailTarget = $this->getMockBuilder('yii\\log\\EmailTarget') |  | ||||||
|             ->setMethods(['formatMessage']) |         /** @var EmailTarget $mailTarget */ | ||||||
|  |         $mailTarget = $this->getMockBuilder(EmailTarget::class) | ||||||
|  |             ->onlyMethods(['formatMessage']) | ||||||
|             ->setConstructorArgs([ |             ->setConstructorArgs([ | ||||||
|                 [ |                 [ | ||||||
|                     'mailer' => $this->mailer, |                     'mailer' => $this->mailer, | ||||||
| @ -166,6 +170,7 @@ class EmailTargetTest extends TestCase | |||||||
|                 ], |                 ], | ||||||
|             ]) |             ]) | ||||||
|             ->getMock(); |             ->getMock(); | ||||||
|  |  | ||||||
|         $this->expectException('yii\log\LogRuntimeException'); |         $this->expectException('yii\log\LogRuntimeException'); | ||||||
|         $mailTarget->export(); |         $mailTarget->export(); | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -30,9 +30,7 @@ class LoggerTest extends TestCase | |||||||
|     protected function setUp(): void |     protected function setUp(): void | ||||||
|     { |     { | ||||||
|         $this->logger = new Logger(); |         $this->logger = new Logger(); | ||||||
|         $this->dispatcher = $this->getMockBuilder('yii\log\Dispatcher') |         $this->dispatcher = $this->createPartialMock(Dispatcher::class, ['dispatch']); | ||||||
|             ->setMethods(['dispatch']) |  | ||||||
|             ->getMock(); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @ -72,7 +70,7 @@ class LoggerTest extends TestCase | |||||||
|         $this->assertEquals('application', $this->logger->messages[0][2]); |         $this->assertEquals('application', $this->logger->messages[0][2]); | ||||||
|         $this->assertEquals([ |         $this->assertEquals([ | ||||||
|             'file' => __FILE__, |             'file' => __FILE__, | ||||||
|             'line' => 68, |             'line' => 66, | ||||||
|             'function' => 'log', |             'function' => 'log', | ||||||
|             'class' => get_class($this->logger), |             'class' => get_class($this->logger), | ||||||
|             'type' => '->', |             'type' => '->', | ||||||
| @ -87,10 +85,10 @@ class LoggerTest extends TestCase | |||||||
|     public function testLogWithFlush(): void |     public function testLogWithFlush(): void | ||||||
|     { |     { | ||||||
|         /** @var Logger|\PHPUnit_Framework_MockObject_MockObject $logger */ |         /** @var Logger|\PHPUnit_Framework_MockObject_MockObject $logger */ | ||||||
|         $logger = $this->getMockBuilder('yii\log\Logger') |         $logger = $this->createPartialMock(Logger::class, ['flush']); | ||||||
|             ->setMethods(['flush']) |  | ||||||
|             ->getMock(); |  | ||||||
|         $logger->flushInterval = 1; |         $logger->flushInterval = 1; | ||||||
|  |  | ||||||
|         $logger->expects($this->exactly(1))->method('flush'); |         $logger->expects($this->exactly(1))->method('flush'); | ||||||
|         $logger->log('test1', Logger::LEVEL_INFO); |         $logger->log('test1', Logger::LEVEL_INFO); | ||||||
|     } |     } | ||||||
| @ -151,13 +149,12 @@ class LoggerTest extends TestCase | |||||||
|         ]; |         ]; | ||||||
|  |  | ||||||
|         /** @var Logger|\PHPUnit_Framework_MockObject_MockObject $logger */ |         /** @var Logger|\PHPUnit_Framework_MockObject_MockObject $logger */ | ||||||
|         $logger = $this->getMockBuilder('yii\log\Logger') |         $logger = $this->createPartialMock(Logger::class, ['getProfiling']); | ||||||
|             ->setMethods(['getProfiling']) |  | ||||||
|             ->getMock(); |  | ||||||
|         $logger->method('getProfiling')->willReturn($timings); |         $logger->method('getProfiling')->willReturn($timings); | ||||||
|         $logger->expects($this->once()) |         $logger->expects($this->once()) | ||||||
|             ->method('getProfiling') |             ->method('getProfiling') | ||||||
|             ->with($this->equalTo(['yii\db\Command::query', 'yii\db\Command::execute'])); |             ->with($this->equalTo(['yii\db\Command::query', 'yii\db\Command::execute'])); | ||||||
|  |  | ||||||
|         $this->assertEquals([3, 50], $logger->getDbProfiling()); |         $this->assertEquals([3, 50], $logger->getDbProfiling()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @ -348,12 +345,12 @@ class LoggerTest extends TestCase | |||||||
|     { |     { | ||||||
|         $messages = ['anyData']; |         $messages = ['anyData']; | ||||||
|         $returnValue = 'return value'; |         $returnValue = 'return value'; | ||||||
|  |  | ||||||
|         /** @var Logger|\PHPUnit_Framework_MockObject_MockObject $logger */ |         /** @var Logger|\PHPUnit_Framework_MockObject_MockObject $logger */ | ||||||
|         $logger = $this->getMockBuilder('yii\log\Logger') |         $logger = $this->createPartialMock(Logger::class, ['calculateTimings']); | ||||||
|             ->setMethods(['calculateTimings']) |  | ||||||
|             ->getMock(); |  | ||||||
|  |  | ||||||
|         $logger->messages = $messages; |         $logger->messages = $messages; | ||||||
|  |  | ||||||
|         $logger->method('calculateTimings')->willReturn($returnValue); |         $logger->method('calculateTimings')->willReturn($returnValue); | ||||||
|         $logger->expects($this->once())->method('calculateTimings')->with($messages); |         $logger->expects($this->once())->method('calculateTimings')->with($messages); | ||||||
|         $this->assertEquals($returnValue, $logger->getProfiling()); |         $this->assertEquals($returnValue, $logger->getProfiling()); | ||||||
| @ -376,11 +373,10 @@ class LoggerTest extends TestCase | |||||||
|             ], |             ], | ||||||
|         ]; |         ]; | ||||||
|         /** @var Logger|\PHPUnit_Framework_MockObject_MockObject $logger */ |         /** @var Logger|\PHPUnit_Framework_MockObject_MockObject $logger */ | ||||||
|         $logger = $this->getMockBuilder('yii\log\Logger') |         $logger = $this->createPartialMock(Logger::class, ['calculateTimings']); | ||||||
|             ->setMethods(['calculateTimings']) |  | ||||||
|             ->getMock(); |  | ||||||
|  |  | ||||||
|         $logger->messages = $messages; |         $logger->messages = $messages; | ||||||
|  |  | ||||||
|         $logger->method('calculateTimings')->willReturn($returnValue); |         $logger->method('calculateTimings')->willReturn($returnValue); | ||||||
|         $logger->expects($this->once())->method('calculateTimings')->with($messages); |         $logger->expects($this->once())->method('calculateTimings')->with($messages); | ||||||
|         $this->assertEquals([], $logger->getProfiling(['not-matched-category'])); |         $this->assertEquals([], $logger->getProfiling(['not-matched-category'])); | ||||||
| @ -416,11 +412,10 @@ class LoggerTest extends TestCase | |||||||
|          * Matched by category name |          * Matched by category name | ||||||
|          */ |          */ | ||||||
|         /** @var Logger|\PHPUnit_Framework_MockObject_MockObject $logger */ |         /** @var Logger|\PHPUnit_Framework_MockObject_MockObject $logger */ | ||||||
|         $logger = $this->getMockBuilder('yii\log\Logger') |         $logger = $this->createPartialMock(Logger::class, ['calculateTimings']); | ||||||
|             ->setMethods(['calculateTimings']) |  | ||||||
|             ->getMock(); |  | ||||||
|  |  | ||||||
|         $logger->messages = $messages; |         $logger->messages = $messages; | ||||||
|  |  | ||||||
|         $logger->method('calculateTimings')->willReturn($returnValue); |         $logger->method('calculateTimings')->willReturn($returnValue); | ||||||
|         $logger->expects($this->once())->method('calculateTimings')->with($messages); |         $logger->expects($this->once())->method('calculateTimings')->with($messages); | ||||||
|         $this->assertEquals([$matchedByCategoryName], $logger->getProfiling(['category'])); |         $this->assertEquals([$matchedByCategoryName], $logger->getProfiling(['category'])); | ||||||
| @ -429,11 +424,10 @@ class LoggerTest extends TestCase | |||||||
|          * Matched by prefix |          * Matched by prefix | ||||||
|          */ |          */ | ||||||
|         /** @var Logger|\PHPUnit_Framework_MockObject_MockObject $logger */ |         /** @var Logger|\PHPUnit_Framework_MockObject_MockObject $logger */ | ||||||
|         $logger = $this->getMockBuilder('yii\log\Logger') |         $logger = $this->createPartialMock(Logger::class, ['calculateTimings']); | ||||||
|             ->setMethods(['calculateTimings']) |  | ||||||
|             ->getMock(); |  | ||||||
|  |  | ||||||
|         $logger->messages = $messages; |         $logger->messages = $messages; | ||||||
|  |  | ||||||
|         $logger->method('calculateTimings')->willReturn($returnValue); |         $logger->method('calculateTimings')->willReturn($returnValue); | ||||||
|         $logger->expects($this->once())->method('calculateTimings')->with($messages); |         $logger->expects($this->once())->method('calculateTimings')->with($messages); | ||||||
|         $this->assertEquals([$matchedByCategoryName, $secondCategory], $logger->getProfiling(['category*'])); |         $this->assertEquals([$matchedByCategoryName, $secondCategory], $logger->getProfiling(['category*'])); | ||||||
| @ -478,11 +472,10 @@ class LoggerTest extends TestCase | |||||||
|          * Exclude by category name |          * Exclude by category name | ||||||
|          */ |          */ | ||||||
|         /** @var Logger|\PHPUnit_Framework_MockObject_MockObject $logger */ |         /** @var Logger|\PHPUnit_Framework_MockObject_MockObject $logger */ | ||||||
|         $logger = $this->getMockBuilder('yii\log\Logger') |         $logger = $this->createPartialMock(Logger::class, ['calculateTimings']); | ||||||
|             ->setMethods(['calculateTimings']) |  | ||||||
|             ->getMock(); |  | ||||||
|  |  | ||||||
|         $logger->messages = $messages; |         $logger->messages = $messages; | ||||||
|  |  | ||||||
|         $logger->method('calculateTimings')->willReturn($returnValue); |         $logger->method('calculateTimings')->willReturn($returnValue); | ||||||
|         $logger->expects($this->once())->method('calculateTimings')->with($messages); |         $logger->expects($this->once())->method('calculateTimings')->with($messages); | ||||||
|         $this->assertEquals([$fistCategory, $secondCategory], $logger->getProfiling(['cat*'], ['category3'])); |         $this->assertEquals([$fistCategory, $secondCategory], $logger->getProfiling(['cat*'], ['category3'])); | ||||||
| @ -491,11 +484,10 @@ class LoggerTest extends TestCase | |||||||
|          * Exclude by category prefix |          * Exclude by category prefix | ||||||
|          */ |          */ | ||||||
|         /** @var Logger|\PHPUnit_Framework_MockObject_MockObject $logger */ |         /** @var Logger|\PHPUnit_Framework_MockObject_MockObject $logger */ | ||||||
|         $logger = $this->getMockBuilder('yii\log\Logger') |         $logger = $this->createPartialMock(Logger::class, ['calculateTimings']); | ||||||
|             ->setMethods(['calculateTimings']) |  | ||||||
|             ->getMock(); |  | ||||||
|  |  | ||||||
|         $logger->messages = $messages; |         $logger->messages = $messages; | ||||||
|  |  | ||||||
|         $logger->method('calculateTimings')->willReturn($returnValue); |         $logger->method('calculateTimings')->willReturn($returnValue); | ||||||
|         $logger->expects($this->once())->method('calculateTimings')->with($messages); |         $logger->expects($this->once())->method('calculateTimings')->with($messages); | ||||||
|         $this->assertEquals([$fistCategory], $logger->getProfiling(['cat*'], ['category*'])); |         $this->assertEquals([$fistCategory], $logger->getProfiling(['cat*'], ['category*'])); | ||||||
|  | |||||||
| @ -27,6 +27,7 @@ namespace yiiunit\framework\log { | |||||||
|     use PHPUnit_Framework_MockObject_MockObject; |     use PHPUnit_Framework_MockObject_MockObject; | ||||||
|     use yii\helpers\VarDumper; |     use yii\helpers\VarDumper; | ||||||
|     use yii\log\Logger; |     use yii\log\Logger; | ||||||
|  |     use yii\log\SyslogTarget; | ||||||
|     use yiiunit\TestCase; |     use yiiunit\TestCase; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @ -53,9 +54,7 @@ namespace yiiunit\framework\log { | |||||||
|          */ |          */ | ||||||
|         protected function setUp(): void |         protected function setUp(): void | ||||||
|         { |         { | ||||||
|             $this->syslogTarget = $this->getMockBuilder('yii\\log\\SyslogTarget') |             $this->syslogTarget = $this->createPartialMock('yii\\log\\SyslogTarget', ['getMessagePrefix']); | ||||||
|                 ->setMethods(['getMessagePrefix']) |  | ||||||
|                 ->getMock(); |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /** |         /** | ||||||
| @ -75,8 +74,11 @@ namespace yiiunit\framework\log { | |||||||
|                 ['profile begin message', Logger::LEVEL_PROFILE_BEGIN], |                 ['profile begin message', Logger::LEVEL_PROFILE_BEGIN], | ||||||
|                 ['profile end message', Logger::LEVEL_PROFILE_END], |                 ['profile end message', Logger::LEVEL_PROFILE_END], | ||||||
|             ]; |             ]; | ||||||
|             $syslogTarget = $this->getMockBuilder('yii\\log\\SyslogTarget') |  | ||||||
|                 ->setMethods(['openlog', 'syslog', 'formatMessage', 'closelog']) |             /** @var SyslogTarget $syslogTarget */ | ||||||
|  |             $syslogTarget = $this->getMockBuilder(SyslogTarget::class) | ||||||
|  |                 ->addMethods(['openlog', 'syslog', 'closelog']) | ||||||
|  |                 ->onlyMethods(['formatMessage']) | ||||||
|                 ->getMock(); |                 ->getMock(); | ||||||
|  |  | ||||||
|             $syslogTarget->identity = $identity; |             $syslogTarget->identity = $identity; | ||||||
| @ -151,9 +153,12 @@ namespace yiiunit\framework\log { | |||||||
|          */ |          */ | ||||||
|         public function testFailedExport(): void |         public function testFailedExport(): void | ||||||
|         { |         { | ||||||
|             $syslogTarget = $this->getMockBuilder('yii\\log\\SyslogTarget') |             /** @var SyslogTarget $syslogTarget */ | ||||||
|                 ->setMethods(['openlog', 'syslog', 'formatMessage', 'closelog']) |             $syslogTarget = $this->getMockBuilder(SyslogTarget::class) | ||||||
|  |                 ->addMethods(['openlog', 'syslog', 'closelog']) | ||||||
|  |                 ->onlyMethods(['formatMessage']) | ||||||
|                 ->getMock(); |                 ->getMock(); | ||||||
|  |  | ||||||
|             $syslogTarget->method('syslog')->willReturn(false); |             $syslogTarget->method('syslog')->willReturn(false); | ||||||
|  |  | ||||||
|             $syslogTarget->identity = 'identity string'; |             $syslogTarget->identity = 'identity string'; | ||||||
|  | |||||||
| @ -245,9 +245,7 @@ class TargetTest extends TestCase | |||||||
|  |  | ||||||
|     public function testBreakProfilingWithFlushWithProfilingDisabled(): void |     public function testBreakProfilingWithFlushWithProfilingDisabled(): void | ||||||
|     { |     { | ||||||
|         $dispatcher = $this->getMockBuilder('yii\log\Dispatcher') |         $dispatcher = $this->createPartialMock('yii\log\Dispatcher', ['dispatch']); | ||||||
|             ->setMethods(['dispatch']) |  | ||||||
|             ->getMock(); |  | ||||||
|         $dispatcher->expects($this->once())->method('dispatch')->with($this->callback(function ($messages) { |         $dispatcher->expects($this->once())->method('dispatch')->with($this->callback(function ($messages) { | ||||||
|             return count($messages) === 2 |             return count($messages) === 2 | ||||||
|                 && $messages[0][0] === 'token.a' |                 && $messages[0][0] === 'token.a' | ||||||
| @ -267,9 +265,7 @@ class TargetTest extends TestCase | |||||||
|  |  | ||||||
|     public function testNotBreakProfilingWithFlushWithProfilingEnabled(): void |     public function testNotBreakProfilingWithFlushWithProfilingEnabled(): void | ||||||
|     { |     { | ||||||
|         $dispatcher = $this->getMockBuilder('yii\log\Dispatcher') |         $dispatcher = $this->createPartialMock('yii\log\Dispatcher', ['dispatch']); | ||||||
|             ->setMethods(['dispatch']) |  | ||||||
|             ->getMock(); |  | ||||||
|         $dispatcher->expects($this->exactly(2))->method('dispatch')->withConsecutive( |         $dispatcher->expects($this->exactly(2))->method('dispatch')->withConsecutive( | ||||||
|             [ |             [ | ||||||
|                 $this->callback(function ($messages) { |                 $this->callback(function ($messages) { | ||||||
| @ -302,9 +298,7 @@ class TargetTest extends TestCase | |||||||
|  |  | ||||||
|     public function testFlushingWithProfilingEnabledAndOverflow(): void |     public function testFlushingWithProfilingEnabledAndOverflow(): void | ||||||
|     { |     { | ||||||
|         $dispatcher = $this->getMockBuilder('yii\log\Dispatcher') |         $dispatcher = $this->createPartialMock('yii\log\Dispatcher', ['dispatch']); | ||||||
|             ->setMethods(['dispatch']) |  | ||||||
|             ->getMock(); |  | ||||||
|         $dispatcher->expects($this->exactly(3))->method('dispatch')->withConsecutive( |         $dispatcher->expects($this->exactly(3))->method('dispatch')->withConsecutive( | ||||||
|             [ |             [ | ||||||
|                 $this->callback(function ($messages) { |                 $this->callback(function ($messages) { | ||||||
|  | |||||||
| @ -301,11 +301,18 @@ TEXT | |||||||
|     { |     { | ||||||
|         $message = new Message(); |         $message = new Message(); | ||||||
|  |  | ||||||
|         $mailerMock = $this->getMockBuilder('yiiunit\framework\mail\Mailer') |         /** @var Mailer $mailerMock */ | ||||||
|             ->setMethods(['beforeSend', 'afterSend']) |         $mailerMock = $this->createPartialMock( | ||||||
|             ->getMock(); |             Mailer::class, | ||||||
|  |             [ | ||||||
|  |                 'afterSend', | ||||||
|  |                 'beforeSend', | ||||||
|  |             ], | ||||||
|  |         ); | ||||||
|  |  | ||||||
|         $mailerMock->expects($this->once())->method('beforeSend')->with($message)->will($this->returnValue(true)); |         $mailerMock->expects($this->once())->method('beforeSend')->with($message)->will($this->returnValue(true)); | ||||||
|         $mailerMock->expects($this->once())->method('afterSend')->with($message, true); |         $mailerMock->expects($this->once())->method('afterSend')->with($message, true); | ||||||
|  |  | ||||||
|         $mailerMock->send($message); |         $mailerMock->send($message); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -417,9 +417,13 @@ class UrlManagerParseUrlTest extends TestCase | |||||||
|  |  | ||||||
|     public function testRulesCacheIsUsed(): void |     public function testRulesCacheIsUsed(): void | ||||||
|     { |     { | ||||||
|         $arrayCache = $this->getMockBuilder('yii\caching\ArrayCache') |         $arrayCache = $this->createPartialMock( | ||||||
|             ->setMethods(['get', 'set']) |             ArrayCache::class, | ||||||
|             ->getMock(); |             [ | ||||||
|  |                 'get', | ||||||
|  |                 'set', | ||||||
|  |             ], | ||||||
|  |         ); | ||||||
|  |  | ||||||
|         $manager = $this->getUrlManager([ |         $manager = $this->getUrlManager([ | ||||||
|             'rules' => ['post/<id:\d+>' => 'post/view'], |             'rules' => ['post/<id:\d+>' => 'post/view'], | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Wilmer Arambula
					Wilmer Arambula