/* Decoded by unphp.net */ globalConnection = $this->getMockBuilder('yii\db\Connection')->getMock(); $this->modelConnection = $this->getMockBuilder('yii\db\Connection')->getMock(); $this->mockApplication([ 'components' => [ 'db' => $this->globalConnection ] ]); ActiveRecord::$db = $this->modelConnection; } private function prepareConnectionMock($connection) { $command = $this->getMockBuilder('yii\db\Command')->getMock(); $command->method('queryOne')->willReturn(false); $connection->method('createCommand')->willReturn($command); $builder = $this->getMockBuilder('yii\db\QueryBuilder')->disableOriginalConstructor()->getMock(); $connection->expects($this->once())->method('getQueryBuilder')->willReturn($builder); } public function testEnsureModelConnectionForOne() { $this->globalConnection->expects($this->never())->method('getQueryBuilder'); $this->prepareConnectionMock($this->modelConnection); $query = new ActiveQuery(ActiveRecord::className()); $query->one(); } public function testEnsureGlobalConnectionForOne() { $this->modelConnection->expects($this->never())->method('getQueryBuilder'); $this->prepareConnectionMock($this->globalConnection); $query = new ActiveQuery(DefaultActiveRecord::className()); $query->one(); } public function testEnsureModelConnectionForAll() { $this->globalConnection->expects($this->never())->method('getQueryBuilder'); $this->prepareConnectionMock($this->modelConnection); $query = new ActiveQuery(ActiveRecord::className()); $query->all(); } public function testEnsureGlobalConnectionForAll() { $this->modelConnection->expects($this->never())->method('getQueryBuilder'); $this->prepareConnectionMock($this->globalConnection); $query = new ActiveQuery(DefaultActiveRecord::className()); $query->all(); } } ?>