/** * @expectedException CM_Exception * @expectedExceptionMessage Path is out of filesystem directory */ public function testGetRelativePathOutOfFilesystem() { $adapter = $this->getMockBuilder('CM_File_Filesystem_Adapter')->setConstructorArgs(array('/base/base2'))->getMockForAbstractClass(); /** @var CM_File_Filesystem_Adapter $adapter */ $method = CMTest_TH::getProtectedMethod('CM_File_Filesystem_Adapter', '_getRelativePath'); $method->invoke($adapter, '/base/base2/../foo'); }
public function testGetCollectionName() { CM_Config::get()->CM_Model_Abstract = new stdClass(); CM_Config::get()->CM_Model_Abstract->types = [1 => 'CMTest_ModelMock_3', 2 => 'CMTest_ModelMock_4']; $adapter = new CM_Model_StorageAdapter_MongoDb(); $method = CMTest_TH::getProtectedMethod('CM_Model_StorageAdapter_MongoDb', '_getCollectionName'); $this->assertSame('cmtest_modelmock_3', $method->invoke($adapter, 1)); $this->assertSame('custom_table', $method->invoke($adapter, 2)); }
public function testGetTableName() { CM_Config::get()->CM_Model_Abstract = new stdClass(); CM_Config::get()->CM_Model_Abstract->types = array(1 => 'CMTest_ModelMock_1', 2 => 'CMTest_ModelMock_2'); $adapter = new CM_Model_StorageAdapter_Database(); $method = CMTest_TH::getProtectedMethod('CM_Model_StorageAdapter_Database', '_getTableName'); $this->assertSame('cmtest_modelmock_1', $method->invoke($adapter, 1)); $this->assertSame('custom_table', $method->invoke($adapter, 2)); }
public function testGetCacheKey() { CM_Config::get()->CM_Model_Abstract = new stdClass(); CM_Config::get()->CM_Model_Abstract->types = array(1 => 'CMTest_ModelMock_1', 2 => 'CMTest_ModelMock_2'); $adapter = new CM_Model_StorageAdapter_Cache(); $method = CMTest_TH::getProtectedMethod('CM_Model_StorageAdapter_Cache', '_getCacheKey'); $this->assertSame('CM_Model_StorageAdapter_Cache_type:1_id:a:1:{s:2:"id";i:2;}', $method->invoke($adapter, 1, array('id' => 2))); $this->assertSame('CM_Model_StorageAdapter_Cache_type:2_id:a:1:{s:2:"id";i:3;}', $method->invoke($adapter, 2, array('id' => 3))); }
public function testExtractTraceRow() { $trace = array(array('file' => 'test.php', 'line' => 18, 'function' => 'foo', 'args' => array()), array('file' => 'test.php', 'line' => 26, 'function' => 'bar', 'class' => 'Foo', 'type' => '->', 'args' => array()), array('file' => 'test.php(28) : eval()\'d code', 'line' => 1, 'function' => '{closure}', 'args' => array()), array('file' => 'test.php', 'line' => 28, 'function' => 'eval')); $expected = array(array('code' => 'foo()', 'file' => 'test.php', 'line' => 18), array('code' => 'Foo->bar()', 'file' => 'test.php', 'line' => 26), array('code' => '{closure}()', 'file' => 'test.php(28) : eval()\'d code', 'line' => 1), array('code' => 'eval', 'file' => 'test.php', 'line' => 28)); $exception = $this->getMockBuilder('Exception')->setMethods(array('getTrace'))->getMockForAbstractClass(); $exception->expects($this->any())->method('getTrace')->will($this->returnValue($trace)); $method = CMTest_TH::getProtectedMethod('CM_ExceptionHandling_SerializableException', '_extractTraceRow'); foreach ($trace as $key => $traceRow) { $this->assertSame($expected[$key], $method->invoke(null, $traceRow)); } }
public function testIsInt() { $schema = new CM_Model_Schema_Definition(array()); $_isInt = CMTest_TH::getProtectedMethod('CM_Model_Schema_Definition', '_isInt'); $this->assertTrue($_isInt->invoke($schema, 1)); $this->assertTrue($_isInt->invoke($schema, '1')); $this->assertFalse($_isInt->invoke($schema, 1.2)); $this->assertFalse($_isInt->invoke($schema, '1.0')); $this->assertFalse($_isInt->invoke($schema, '4E2')); $this->assertFalse($_isInt->invoke($schema, 400.0)); }
public function testGetPackageFromComposerPackageMissingExtra() { $composerPackage = $this->getMockBuilder('\\Composer\\Package\\CompletePackage')->setMethods(array('getName', 'getPrettyName', 'getExtra'))->disableOriginalConstructor()->getMock(); $composerPackage->expects($this->any())->method('getName')->will($this->returnValue('foo')); $composerPackage->expects($this->any())->method('getPrettyName')->will($this->returnValue('foo')); $composerPackage->expects($this->any())->method('getExtra')->will($this->returnValue(array())); /** @var \Composer\Package\CompletePackage $composerPackage */ $installation = $this->getMockBuilder('CM_App_Installation')->disableOriginalConstructor()->setMethods(array('_getComposerVendorDir'))->getMock(); $installation->expects($this->any())->method('_getComposerVendorDir')->will($this->returnValue('vendor/')); $method = CMTest_TH::getProtectedMethod('CM_App_Installation', '_getPackageFromComposerPackage'); /** @var CM_App_Package $package */ $package = $method->invoke($installation, $composerPackage); $this->assertSame(array(), $package->getModules()); }
public function testCleanUp() { $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(); $this->assertSame(0, $paging->getCount()); CMTest_TH::getProtectedMethod($paging, '_add')->invoke($paging, 'foo'); $paging->_change(); $this->assertSame(1, $paging->getCount()); $age = 7 * 86400; CMTest_TH::timeForward($age); $paging->cleanUp(); $this->assertSame(0, $paging->getCount()); }
public function testLogExceptionFileLog() { $errorLog = CM_Bootloader::getInstance()->getDirTmp() . uniqid(); $log = $this->getMockBuilder('CM_Paging_Log_Error')->setMethods(array('add'))->disableOriginalConstructor()->getMock(); $log->expects($this->any())->method('add')->will($this->throwException(new Exception('foo'))); $exception = $this->getMockBuilder('CM_Exception')->setMethods(array('getLog', 'getMetaInfo'))->getMock(); $exception->expects($this->any())->method('getLog')->will($this->returnValue($log)); $exception->expects($this->any())->method('getMetaInfo')->will($this->returnValue(array())); $method = CMTest_TH::getProtectedMethod('CM_ExceptionHandling_Handler_Abstract', 'logException'); $exceptionHandler = $this->getMockBuilder('CM_ExceptionHandling_Handler_Abstract')->setMethods(array('_getLogFile'))->getMockForAbstractClass(); $exceptionHandler->expects($this->any())->method('_getLogFile')->will($this->returnValue(new CM_File($errorLog))); $this->assertFileNotExists($errorLog); $method->invoke($exceptionHandler, $exception); $logContents = file_get_contents($errorLog); $this->assertNotEmpty($logContents); $this->assertContains('### Cannot log error: ', $logContents); $this->assertContains('### Original Exception: ', $logContents); }
public function testDeleteOnUnsubscribeInvalid() { $streamSubscribe = $this->getMockBuilder('CM_Model_Stream_Subscribe')->setMethods(array('getStreamChannel', 'getId'))->getMock(); $streamChannel = $this->getMockBuilder('CM_Model_StreamChannel_Media')->setMethods(array('isValid', 'onUnsubscribe'))->getMock(); $streamSubscribe->expects($this->any())->method('getStreamChannel')->will($this->returnValue($streamChannel)); $streamChannel->expects($this->any())->method('isValid')->will($this->returnValue(false)); $streamChannel->expects($this->never())->method('onUnsubscribe'); /** @var CM_Model_StreamChannel_Media $streamChannel */ /** @var CM_Model_Stream_Subscribe $streamSubscribe */ $onDelete = CMTest_TH::getProtectedMethod('CM_Model_Stream_Subscribe', '_onDelete'); $onDelete->invoke($streamSubscribe); }
public function testSetData() { $data = array('bar' => '23', 'foo' => 'bar'); $dataNew = array('baar' => '23', 'fooo' => 'bar'); $model = $this->getMockBuilder('CM_Model_Abstract')->setConstructorArgs(array())->getMockForAbstractClass(); /** @var CM_Model_Abstract $model */ $getData = CMTest_TH::getProtectedMethod('CM_Model_Abstract', '_getData'); $setData = CMTest_TH::getProtectedMethod('CM_Model_Abstract', '_setData'); $this->assertSame(array(), $getData->invoke($model)); $setData->invoke($model, $data); $this->assertSame($data, $getData->invoke($model)); $setData->invoke($model, $dataNew); $this->assertSame($dataNew, $getData->invoke($model)); }
/** * @param DateTime $start * @param DateTimeZone $timeZone * @throws CM_Exception_Invalid */ private function _testIntervalModeDST(DateTime $start, DateTimeZone $timeZone) { $currently = clone $start; $managerMock = $this->mockClass('CM_Clockwork_Manager'); $managerMock->mockMethod('_getCurrentDateTimeUTC')->set(function () use(&$currently) { return clone $currently; }); $storageClass = $this->mockClass('CM_Clockwork_Storage_Abstract'); $storageClass->mockMethod('getLastRuntime')->set(function () use(&$lastRuntime) { if ($lastRuntime instanceof DateTime) { return clone $lastRuntime; } return $lastRuntime; }); /** @var CM_Clockwork_Storage_FileSystem $storage */ $storage = $storageClass->newInstanceWithoutConstructor(); /** @var CM_Clockwork_Manager $manager */ $manager = $managerMock->newInstance(); $manager->setStorage($storage); $manager->setTimeZone($timeZone); $_shouldRun = CMTest_TH::getProtectedMethod('CM_Clockwork_Manager', '_shouldRun'); $event = new CM_Clockwork_Event('event', '20 minutes'); $lastRuntime = null; $this->assertFalse($_shouldRun->invoke($manager, $event)); $currently->modify('19 minutes 59 seconds'); $this->assertFalse($_shouldRun->invoke($manager, $event)); $currently->modify('1 second'); $this->assertTrue($_shouldRun->invoke($manager, $event)); $lastRuntime = clone $currently; $currently->modify('19 minutes 59 seconds'); $this->assertFalse($_shouldRun->invoke($manager, $event)); $currently->modify('1 second'); $this->assertTrue($_shouldRun->invoke($manager, $event)); $lastRuntime = clone $currently; $currently->modify('19 minutes 59 seconds'); $this->assertFalse($_shouldRun->invoke($manager, $event)); $currently->modify('1 second'); $this->assertTrue($_shouldRun->invoke($manager, $event)); if ($timeZone->getOffset($start) === $timeZone->getOffset($currently)) { throw new CM_Exception_Invalid("Test did not go through a daylight saving time switch"); } }
public function testDeleteOnUnpublishInvalid() { $streamPublish = $this->getMockBuilder('CM_Model_Stream_Publish')->setMethods(array('getStreamChannel', 'getId'))->getMock(); $streamChannel = $this->getMockBuilder('CM_Model_StreamChannel_Video')->setMethods(array('isValid', 'onUnpublish'))->getMock(); $streamPublish->expects($this->any())->method('getStreamChannel')->will($this->returnValue($streamChannel)); $streamChannel->expects($this->any())->method('isValid')->will($this->returnValue(false)); $streamChannel->expects($this->never())->method('onUnpublish'); /** @var CM_Model_StreamChannel_Video $streamChannel */ /** @var CM_Model_Stream_Publish $streamPublish */ $onDelete = CMTest_TH::getProtectedMethod('CM_Model_Stream_Publish', '_onDelete'); $onDelete->invoke($streamPublish); }
public function testNotify() { $actor = CMTest_TH::createUser(); $action = $this->getMockBuilder('CM_Action_Abstract')->setMethods(array('_notifyFoo', '_track'))->setConstructorArgs(array('foo', $actor))->getMockForAbstractClass(); $action->expects($this->once())->method('_notifyFoo')->with('bar'); $method = CMTest_TH::getProtectedMethod('CM_Action_Abstract', '_notify'); $method->invoke($action, 'bar'); }