本文整理汇总了PHP中CMTest_TH::callProtectedMethod方法的典型用法代码示例。如果您正苦于以下问题:PHP CMTest_TH::callProtectedMethod方法的具体用法?PHP CMTest_TH::callProtectedMethod怎么用?PHP CMTest_TH::callProtectedMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CMTest_TH
的用法示例。
在下文中一共展示了CMTest_TH::callProtectedMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAggregate
public function testAggregate()
{
$paging = $this->getMockBuilder('CM_Paging_Log_Abstract')->disableOriginalConstructor()->setMethods(array('getType'))->getMockForAbstractClass();
$paging->expects($this->any())->method('getType')->will($this->returnValue(1));
/** @var CM_Paging_Log_Abstract $paging */
$paging->__construct();
CMTest_TH::callProtectedMethod($paging, '_add', ['haha']);
CMTest_TH::callProtectedMethod($paging, '_add', ['huhu']);
CMTest_TH::timeDaysForward(1);
CMTest_TH::timeDaysForward(1);
CMTest_TH::callProtectedMethod($paging, '_add', ['haha']);
CMTest_TH::callProtectedMethod($paging, '_add', ['haha', array('id' => 123123, 'ip' => 1234123)]);
CMTest_TH::timeDaysForward(1);
CMTest_TH::callProtectedMethod($paging, '_add', ['ha']);
CMTest_TH::callProtectedMethod($paging, '_add', ['ha']);
CMTest_TH::callProtectedMethod($paging, '_add', ['ha']);
$paging->__construct(true, 2 * 86400);
$this->assertEquals(2, $paging->getCount());
$warning1 = $paging->getItem(0);
$warning2 = $paging->getItem(1);
$this->assertEquals(3, $warning1['count']);
$this->assertEquals(2, $warning2['count']);
$this->assertEquals('haha', $warning2['msg']);
$this->assertEquals('ha', $warning1['msg']);
}
示例2: test_encodeRecord
public function test_encodeRecord()
{
/** @var CM_Log_Handler_Fluentd|\Mocka\AbstractClassTrait $mock */
$mock = $this->mockClass('CM_Log_Handler_Fluentd')->newInstanceWithoutConstructor();
$this->assertSame([], CMTest_TH::callProtectedMethod($mock, '_encodeRecord', [[]]));
$record = ['foo' => ['id' => 123, 'bar' => (object) ['baz'], 'baz' => new DateTime('01-01-2001'), 'bax' => new CM_Model_Mock_Fluentd()]];
$this->assertSame(['foo' => ['id' => '123', 'bar' => ['class' => 'stdClass'], 'baz' => '2001-01-01T00:00:00+00:00', 'bax' => ['class' => 'CM_Model_Mock_Fluentd', 'id' => '42']]], CMTest_TH::callProtectedMethod($mock, '_encodeRecord', [$record]));
}
示例3: testGetScriptList
public function testGetScriptList()
{
$script1 = $this->mockClass('CM_Provision_Script_Abstract')->newInstanceWithoutConstructor();
$script2 = $this->mockClass('CM_Provision_Script_Abstract')->newInstanceWithoutConstructor();
$script2->mockMethod('getRunLevel')->set(10);
$script3 = $this->mockClass('CM_Provision_Script_Abstract')->newInstanceWithoutConstructor();
$script3->mockMethod('getRunLevel')->set(1);
$loader = new CM_Provision_Loader();
$loader->registerScript($script1);
$loader->registerScript($script2);
$loader->registerScript($script3);
$scriptList = CMTest_TH::callProtectedMethod($loader, '_getScriptList');
$expected = [$script3, $script1, $script2];
$this->assertSame($expected, $scriptList);
}
示例4: testFlushVariationCache
public function testFlushVariationCache()
{
$test = CM_Model_Splittest::create('foo', ['v1', 'v2']);
$variation1 = new CM_Model_SplittestVariation(CM_Db_Db::select('cm_splittestVariation', 'id', ['name' => 'v1'])->fetchColumn());
$variation2 = new CM_Model_SplittestVariation(CM_Db_Db::select('cm_splittestVariation', 'id', ['name' => 'v2'])->fetchColumn());
$variation2->setEnabled(false);
$fixture = $this->mockClass('CM_Splittest_Fixture')->newInstanceWithoutConstructor();
$fixture->mockMethod('getId')->set(1);
$fixture->mockMethod('getFixtureType')->set(1);
CMTest_TH::timeForward(1);
$variation = CMTest_TH::callProtectedMethod($test, '_getVariationFixture', [$fixture]);
$this->assertSame('v1', $variation);
$test->flush();
$variation2->setEnabled(true);
$variation1->setEnabled(false);
$variation = CMTest_TH::callProtectedMethod($test, '_getVariationFixture', [$fixture]);
$this->assertSame('v2', $variation);
}
示例5: testProcessExceptionCatching
public function testProcessExceptionCatching()
{
CM_Config::get()->CM_Http_Response_View_Abstract->catchPublicExceptions = true;
CM_Config::get()->CM_Http_Response_View_Abstract->exceptionsToCatch = ['CM_Exception_Nonexistent' => []];
$response = $this->mockClass('CM_Http_Response_View_Abstract')->newInstanceWithoutConstructor();
$response->mockMethod('_processView')->set(function () {
throw new CM_Exception_Invalid('foo', null, null, ['messagePublic' => new CM_I18n_Phrase('bar')]);
});
$response->mockMethod('getRender')->set(new CM_Frontend_Render());
/** @var CM_Http_Response_View_Abstract $response */
CMTest_TH::callProtectedMethod($response, '_process');
$this->assertViewResponseError($response, 'CM_Exception_Invalid', 'bar', true);
$response->mockMethod('_processView')->set(function () {
throw new CM_Exception_Nonexistent('foo');
});
CMTest_TH::callProtectedMethod($response, '_process');
$this->assertViewResponseError($response, 'CM_Exception_Nonexistent', 'Internal server error', false);
}
示例6: testListFiles
public function testListFiles()
{
$filesystem = $this->_mockFilesystem();
$this->_fillFilesystemWithRandomFiles($filesystem);
/** @var \Mocka\AbstractClassTrait $filesystem */
$listByPrefixMethod = $filesystem->mockMethod('listByPrefix')->set(function ($path, $noRecursion) use($filesystem) {
return $filesystem->callOriginalMethod('listByPrefix', [$path, $noRecursion]);
});
/** @var CM_File_Filesystem $filesystem */
$backupManager = $this->mockClass('S3Export_BackupManager')->newInstanceWithoutConstructor();
/** @var S3Export_BackupManager $backupManager */
$this->assertSame(0, $listByPrefixMethod->getCallCount());
$this->assertCount(15, CMTest_TH::callProtectedMethod($backupManager, '_getRandomFiles', [$filesystem, 15, 45]));
// 6 times, because it needs to list root folder and then list 5 additional folders (10 files each) to get 45 files
$this->assertSame(6, $listByPrefixMethod->getCallCount());
$this->assertCount(200, CMTest_TH::callProtectedMethod($backupManager, '_getRandomFiles', [$filesystem, 201, 500]));
$this->assertSame(6 + 21, $listByPrefixMethod->getCallCount());
}
示例7: testRunNonBlocking
public function testRunNonBlocking()
{
$process = $this->mockClass('CM_Process')->newInstanceWithoutConstructor();
$forkMock = $process->mockMethod('fork');
$forkMock->set(function () use($forkMock) {
$forkHandler = $this->mockClass('CM_Process_ForkHandler')->newInstanceWithoutConstructor();
$forkHandler->mockMethod('getIdentifier')->set($forkMock->getCallCount());
return $forkHandler;
});
$manager = $this->mockObject('CM_Clockwork_Manager');
$manager->mockMethod('_shouldRun')->set(true);
$manager->mockMethod('_getProcess')->set($process);
/** @var CM_Clockwork_Manager $manager */
$event1 = new CM_Clockwork_Event('1', '1 second');
$manager->registerEvent($event1);
$event2 = new CM_Clockwork_Event('2', '1 second');
$manager->registerEvent($event2);
$process->mockMethod('listenForChildren')->set([]);
// no events finish
$this->assertFalse(CMTest_TH::callProtectedMethod($manager, '_isRunning', [$event1]));
$this->assertFalse(CMTest_TH::callProtectedMethod($manager, '_isRunning', [$event2]));
$manager->runEvents();
$this->assertSame(2, $forkMock->getCallCount());
$this->assertTrue(CMTest_TH::callProtectedMethod($manager, '_isRunning', [$event1]));
$this->assertTrue(CMTest_TH::callProtectedMethod($manager, '_isRunning', [$event2]));
// event 2 finishes
$process->mockMethod('listenForChildren')->set([2 => new CM_Process_WorkloadResult()]);
$manager->runEvents();
$this->assertSame(2, $forkMock->getCallCount());
$this->assertTrue(CMTest_TH::callProtectedMethod($manager, '_isRunning', [$event1]));
$this->assertFalse(CMTest_TH::callProtectedMethod($manager, '_isRunning', [$event2]));
// no events finish, event 2 starts
$process->mockMethod('listenForChildren')->set([]);
$manager->runEvents();
$this->assertSame(3, $forkMock->getCallCount());
$this->assertTrue(CMTest_TH::callProtectedMethod($manager, '_isRunning', [$event1]));
$this->assertTrue(CMTest_TH::callProtectedMethod($manager, '_isRunning', [$event2]));
// both events finish, event 2 finishes with an error
$process->mockMethod('listenForChildren')->set([1 => new CM_Process_WorkloadResult(), 3 => (new CM_Process_WorkloadResult())->setException(new CM_Exception())]);
$manager->runEvents();
$this->assertFalse(CMTest_TH::callProtectedMethod($manager, '_isRunning', [$event1]));
$this->assertFalse(CMTest_TH::callProtectedMethod($manager, '_isRunning', [$event2]));
}
示例8: testProcessExceptionCatching
public function testProcessExceptionCatching()
{
CM_Config::get()->CM_Http_Response_View_Abstract->catchPublicExceptions = true;
CM_Config::get()->CM_Http_Response_View_Abstract->exceptionsToCatch = ['CM_Exception_Nonexistent' => []];
$response = $this->mockClass('CM_Http_Response_View_Abstract')->newInstanceWithoutConstructor();
$response->mockMethod('_processView')->set(function () {
throw new CM_Exception_Invalid('foo', null, ['messagePublic' => 'bar']);
});
$response->mockMethod('getRender')->set(new CM_Frontend_Render());
/** @var CM_Http_Response_View_Abstract $response */
CMTest_TH::callProtectedMethod($response, '_process');
$responseData = CM_Params::jsonDecode($response->getContent());
$this->assertSame(['error' => ['type' => 'CM_Exception_Invalid', 'msg' => 'bar', 'isPublic' => true]], $responseData);
$response->mockMethod('_processView')->set(function () {
throw new CM_Exception_Nonexistent('foo');
});
CMTest_TH::callProtectedMethod($response, '_process');
$responseData = CM_Params::jsonDecode($response->getContent());
$this->assertSame(['error' => ['type' => 'CM_Exception_Nonexistent', 'msg' => 'Internal server error', 'isPublic' => false]], $responseData);
}
示例9: test_instantiateJobSetServiceManager
public function test_instantiateJobSetServiceManager()
{
/** @var CM_Jobdistribution_Job_Abstract|\Mocka\AbstractClassTrait|CM_Service_ManagerAwareInterface $job */
$job = $this->mockClass('CM_Jobdistribution_Job_Abstract', ['CM_Service_ManagerAwareInterface'], ['CM_Service_ManagerAwareTrait'])->newInstance();
$queue = new CM_Jobdistribution_DelayedQueue($this->getServiceManager());
$job = CMTest_TH::callProtectedMethod($queue, '_instantiateJob', [get_class($job)]);
$this->assertEquals($this->getServiceManager(), $job->getServiceManager());
}
示例10: testIncreaseUpdateCountNewDeploy
public function testIncreaseUpdateCountNewDeploy()
{
$now = time();
$languageKey = $this->mockObject('CM_Model_LanguageKey');
$languageKey->mockMethod('_getDeployVersion')->set($now + 1);
/** @var CM_Model_LanguageKey $languageKey */
$languageKey->_set(['updateCountResetVersion' => $now, 'updateCount' => 5]);
CMTest_TH::callProtectedMethod($languageKey, '_increaseUpdateCount');
$this->assertSame($now + 1, $languageKey->_get('updateCountResetVersion'));
$this->assertSame(1, $languageKey->_get('updateCount'));
}
示例11: testRunWithCatching
public function testRunWithCatching()
{
$response = $this->mockClass('CM_Http_Response_Abstract')->newInstanceWithoutConstructor();
$className = get_class($response);
// test logging and errorCallback-execution
CM_Config::get()->{$className} = new stdClass();
CM_Config::get()->{$className}->exceptionsToCatch = ['CM_Exception_Nonexistent' => ['log' => 'CM_Paging_Log_NotFound', 'foo' => 'bar'], 'CM_Exception_InvalidParam' => ['log' => null]];
$exceptionCodeExecutionCounter = 0;
$errorCode = function (CM_Exception_Nonexistent $ex, $errorOptions) use(&$exceptionCodeExecutionCounter) {
$this->assertSame('bar', $errorOptions['foo']);
$exceptionCodeExecutionCounter++;
};
$this->assertSame(0, $exceptionCodeExecutionCounter);
$this->assertCount(0, new CM_Paging_Log_NotFound());
CMTest_TH::callProtectedMethod($response, '_runWithCatching', [function () {
}, $errorCode]);
$this->assertSame(0, $exceptionCodeExecutionCounter);
$this->assertCount(0, new CM_Paging_Log_NotFound());
CMTest_TH::callProtectedMethod($response, '_runWithCatching', [function () {
throw new CM_Exception_Nonexistent();
}, $errorCode]);
$this->assertSame(1, $exceptionCodeExecutionCounter);
$this->assertCount(1, new CM_Paging_Log_NotFound());
$errorCode = function (CM_Exception_InvalidParam $ex, $errorOptions) use(&$exceptionCodeExecutionCounter) {
$exceptionCodeExecutionCounter++;
};
CMTest_TH::callProtectedMethod($response, '_runWithCatching', [function () {
throw new CM_Exception_InvalidParam();
}, $errorCode]);
$this->assertSame(2, $exceptionCodeExecutionCounter);
$this->assertCount(1, new CM_Paging_Log_NotFound());
// test public/non-public exceptions not marked for catching
// public exception, no public exception catching
CM_Config::get()->{$className}->exceptionsToCatch = [];
$errorCode = function (CM_Exception_Nonexistent $ex, $errorOptions) use(&$exceptionCodeExecutionCounter) {
$exceptionCodeExecutionCounter++;
$this->assertTrue($ex->isPublic());
};
try {
CMTest_TH::callProtectedMethod($response, '_runWithCatching', [function () {
throw new CM_Exception_Nonexistent('foo', null, ['messagePublic' => 'bar']);
}, $errorCode]);
$this->fail('Caught public exception with public exception catching disabled');
} catch (CM_Exception_Nonexistent $ex) {
$this->assertTrue($ex->isPublic());
$this->assertSame('foo', $ex->getMessage());
}
$this->assertSame(2, $exceptionCodeExecutionCounter);
// non-public exception, public exception catching
CM_Config::get()->{$className}->catchPublicExceptions = true;
try {
CMTest_TH::callProtectedMethod($response, '_runWithCatching', [function () {
throw new CM_Exception_Nonexistent('foo');
}, $errorCode]);
$this->fail('Caught non-public exception that was not configured to be caught');
} catch (CM_Exception_Nonexistent $ex) {
$this->assertFalse($ex->isPublic());
$this->assertSame('foo', $ex->getMessage());
}
$this->assertSame(2, $exceptionCodeExecutionCounter);
// public exception, public exception catching
try {
$returnValue = CMTest_TH::callProtectedMethod($response, '_runWithCatching', [function () {
throw new CM_Exception_Nonexistent('foo', null, ['messagePublic' => 'bar']);
}, $errorCode]);
$this->assertNull($returnValue);
} catch (CM_Exception_Nonexistent $ex) {
$this->fail('Caught non-public exception');
}
$this->assertSame(3, $exceptionCodeExecutionCounter);
}
示例12: callProtectedMethod
/**
* @param mixed $object
* @param string $methodName
* @param array|null $arguments
* @return mixed
*/
public function callProtectedMethod($object, $methodName, array $arguments = null)
{
return CMTest_TH::callProtectedMethod($object, $methodName, $arguments);
}
示例13: test_checkResultForErrors
public function test_checkResultForErrors()
{
$mongoDb = CM_Service_Manager::getInstance()->getMongoDb();
CMTest_TH::callProtectedMethod($mongoDb, '_checkResultForErrors', [true]);
CMTest_TH::callProtectedMethod($mongoDb, '_checkResultForErrors', [['ok' => 1]]);
try {
CMTest_TH::callProtectedMethod($mongoDb, '_checkResultForErrors', [false]);
} catch (CM_MongoDb_Exception $ex) {
$this->assertSame(['result' => false], $ex->getMetaInfo());
}
try {
CMTest_TH::callProtectedMethod($mongoDb, '_checkResultForErrors', [['ok' => 0, 'errmsg' => 'foo']]);
} catch (CM_MongoDb_Exception $ex) {
$this->assertSame(['result' => ['ok' => 0, 'errmsg' => 'foo']], $ex->getMetaInfo());
}
}
示例14: testCreateNamespaceNoModule
/**
* @expectedException CM_Cli_Exception_Internal
* @expectedExceptionMessage Module `foo` must exist!
*/
public function testCreateNamespaceNoModule()
{
$app = $this->_mockAppInstallation();
$cli = $this->_mockGeneratorCli($app);
CMTest_TH::callProtectedMethod($cli, '_createNamespace', ['foo', 'bar']);
}
示例15: testRunWithCatching
public function testRunWithCatching()
{
/** @var CM_Http_Response_Abstract|\Mocka\AbstractClassTrait $response */
$response = $this->mockClass('CM_Http_Response_Abstract')->newInstanceWithoutConstructor();
$response->mockMethod('getRequest')->set(new CM_Http_Request_Get('/foo/bar/'));
$response->setServiceManager($this->getServiceManager());
$className = get_class($response);
// test logging and errorCallback-execution
CM_Config::get()->{$className} = new stdClass();
CM_Config::get()->{$className}->exceptionsToCatch = ['CM_Exception_Nonexistent' => ['log' => true, 'level' => CM_Log_Logger::INFO, 'foo' => 'bar'], 'CM_Exception_InvalidParam' => []];
$exceptionCodeExecutionCounter = 0;
$errorCode = function (CM_Exception_Nonexistent $ex, $errorOptions) use(&$exceptionCodeExecutionCounter) {
$this->assertSame('bar', $errorOptions['foo']);
$exceptionCodeExecutionCounter++;
};
$this->assertSame(0, $exceptionCodeExecutionCounter);
$this->assertCount(0, new CM_Paging_Log([CM_Log_Logger::INFO]));
CMTest_TH::callProtectedMethod($response, '_runWithCatching', [function () {
}, $errorCode]);
$this->assertSame(0, $exceptionCodeExecutionCounter);
$this->assertCount(0, new CM_Paging_Log([CM_Log_Logger::INFO]));
CMTest_TH::callProtectedMethod($response, '_runWithCatching', [function () {
throw new CM_Exception_Nonexistent();
}, $errorCode]);
$this->assertSame(1, $exceptionCodeExecutionCounter);
$this->assertCount(1, new CM_Paging_Log([CM_Log_Logger::INFO]));
$errorCode = function (CM_Exception_InvalidParam $ex, $errorOptions) use(&$exceptionCodeExecutionCounter) {
$exceptionCodeExecutionCounter++;
};
CMTest_TH::callProtectedMethod($response, '_runWithCatching', [function () {
throw new CM_Exception_InvalidParam();
}, $errorCode]);
$this->assertSame(2, $exceptionCodeExecutionCounter);
$this->assertCount(1, new CM_Paging_Log([CM_Log_Logger::INFO]));
// test public/non-public exceptions not marked for catching
$exceptionCodeExecutionCounter = 0;
// public exception, no public exception catching
CM_Config::get()->{$className}->exceptionsToCatch = [];
$errorCode = function (CM_Exception_Nonexistent $ex, $errorOptions) use(&$exceptionCodeExecutionCounter) {
$exceptionCodeExecutionCounter++;
$this->assertTrue($ex->isPublic());
};
try {
CMTest_TH::callProtectedMethod($response, '_runWithCatching', [function () {
throw new CM_Exception_Nonexistent('foo', null, null, ['messagePublic' => new CM_I18n_Phrase('bar')]);
}, $errorCode]);
$this->fail('Caught public exception with public exception catching disabled');
} catch (CM_Exception_Nonexistent $ex) {
$this->assertTrue($ex->isPublic());
$this->assertSame('foo', $ex->getMessage());
}
$this->assertSame(0, $exceptionCodeExecutionCounter);
// non-public exception, public exception catching
CM_Config::get()->{$className}->catchPublicExceptions = true;
try {
CMTest_TH::callProtectedMethod($response, '_runWithCatching', [function () {
throw new CM_Exception_Nonexistent('foo');
}, $errorCode]);
$this->fail('Caught non-public exception that was not configured to be caught');
} catch (CM_Exception_Nonexistent $ex) {
$this->assertFalse($ex->isPublic());
$this->assertSame('foo', $ex->getMessage());
}
$this->assertSame(0, $exceptionCodeExecutionCounter);
// public exception, public exception catching
try {
$returnValue = CMTest_TH::callProtectedMethod($response, '_runWithCatching', [function () {
throw new CM_Exception_Nonexistent('foo', null, null, ['messagePublic' => new CM_I18n_Phrase('bar')]);
}, $errorCode]);
$this->assertNull($returnValue);
} catch (CM_Exception_Nonexistent $ex) {
$this->fail('Caught non-public exception');
}
$this->assertSame(1, $exceptionCodeExecutionCounter);
// test child exception catching
$response = $this->mockClass('CM_Http_Response_Abstract')->newInstanceWithoutConstructor();
$className = get_class($response);
CM_Config::get()->{$className} = new stdClass();
CM_Config::get()->{$className}->exceptionsToCatch = ['CM_Exception' => []];
$exceptionCodeExecutionCounter = 0;
$errorCode = function (CM_Exception $ex, $errorOptions) use(&$exceptionCodeExecutionCounter) {
$exceptionCodeExecutionCounter++;
};
try {
$returnValue = CMTest_TH::callProtectedMethod($response, '_runWithCatching', [function () {
throw new CM_Exception_Invalid('foo');
}, $errorCode]);
$this->assertNull($returnValue);
} catch (CM_Exception_Nonexistent $ex) {
$this->fail("Didn't catch the child of an exception that was configured to be caught");
}
$this->assertSame(1, $exceptionCodeExecutionCounter);
}