public function test_calling_method_with_no_parameters() { $mock = new Mock('Test'); $mock->expects('method')->returns("returned data"); $this->assertEquals("returned data", $mock->method()); $this->assertTrue(Mock::verifyAll()); }
/** * Tests disableAll(). * * @test */ public function testDisableAll() { $mock2 = new Mock(__NAMESPACE__, "min", "max"); $mock2->enable(); Mock::disableAll(); $this->assertNotEquals(1234, time()); $this->assertEquals(1, min([1, 2])); }
function checkNotInstanceof() { $a = new Mock(); $info = array('test'); for ($i = 0; $i < LOOP; $i++) { if (!$a instanceof Mock) { $a->doIt($info); } } }
static function getPluginPackageManager($mock) { if ($mock) { Mock::generatePartial('OX_PluginManager', $mockPkgMgrClass = 'MOX_PluginManager' . rand(), array('_auditInit', '_auditSetKeys', '_auditStart', '_auditUpdate', '_auditSetID', '_checkDatabaseEnvironment', '_registerSchema', '_registerPreferences', '_registerPluginVersion', '_unregisterSchema', '_unregisterPreferences', '_unregisterPluginVersion', '_runExtensionTasks')); $oPkgMgr = new $mockPkgMgrClass(); // install tasks $oPkgMgr->setReturnValue('_auditInit', true); $oPkgMgr->setReturnValue('_auditSetKeys', true); $oPkgMgr->setReturnValue('_auditStart', true); $oPkgMgr->setReturnValue('_auditUpdate', true); $oPkgMgr->setReturnValue('_checkDatabaseEnvironment', true); //$oPkgMgr->setReturnValue('_runScript', true); //$oPkgMgr->setReturnValue('_checkDependenciesForInstallOrEnable', true); //$oPkgMgr->setReturnValue('_checkFiles', true); //$oPkgMgr->setReturnValue('_checkMenus', true); $oPkgMgr->setReturnValue('_registerSchema', true); $oPkgMgr->setReturnValue('_registerPreferences', true); //$oPkgMgr->setReturnValue('_registerSettings', true); $oPkgMgr->setReturnValue('_registerPluginVersion', true); // uninstall tasks //$oPkgMgr->setReturnValue('_checkDependenciesForUninstallOrDisable', true); $oPkgMgr->setReturnValue('_unregisterPluginVersion', true); $oPkgMgr->setReturnValue('_unregisterPreferences', true); //$oPkgMgr->setReturnValue('_unregisterSettings', true); $oPkgMgr->setReturnValue('_unregisterSchema', true); //$oPkgMgr->setReturnValue('_removeFiles', true); } else { $oPkgMgr = new OX_PluginManager(); } $oPkgMgr->init(); return $oPkgMgr; }
/** * Constructor. * * @access public * @return void */ public function setUp() { parent::setUp(); Mock::generate('Crumbly_model', get_class($this) . '_mock_model'); $this->_model = $this->_get_mock('model'); $this->_subject = new Crumbly_upd(); }
function setUp() { global $DB; Mock::generate(get_class($DB), 'mockDB'); $this->realDB = $DB; $DB = new mockDB(); }
function testdllValidation() { Mock::generatePartial('OA_Dll_User', 'PartialMockOA_Dll_User', array('raiseError')); $dllUserMock = new PartialMockOA_Dll_User(); $dllUserMock->setReturnValue('raiseError', true); $dllUserMock->expectCallCount('raiseError', 2); $oUserInfo = new OA_Dll_UserInfo(); // Test with nothing set $this->assertFalse($this->oPlugin->dllValidation($dllUserMock, $oUserInfo)); // Test with username set $oUserInfo->username = '******'; $this->assertFalse($this->oPlugin->dllValidation($dllUserMock, $oUserInfo)); // Test with username and password set $oUserInfo->password = '******'; $this->assertTrue($this->oPlugin->dllValidation($dllUserMock, $oUserInfo)); $this->assertEqual($oUserInfo->password, md5('pwd')); // Test edit $oUserInfo = new OA_Dll_UserInfo(); $oUserInfo->userId = 1; $this->assertTrue($this->oPlugin->dllValidation($dllUserMock, $oUserInfo)); $this->assertNull($oUserInfo->password); // Test edit with new password $oUserInfo->password = '******'; $this->assertTrue($this->oPlugin->dllValidation($dllUserMock, $oUserInfo)); $this->assertEqual($oUserInfo->password, md5('pwd')); $dllUserMock->tally(); }
public function __construct() { parent::__construct(); // Make sure the moded db class is available Mock::generate('MY_DB'); Template::$ignore_session = true; }
/** * The constructor method. */ function Test_OA_Maintenance_Priority_AdServer_Task_ECPMforRemnant() { $this->UnitTestCase(); Mock::generate('OA_Dal_Maintenance_Priority', $this->mockDal = 'MockOA_Dal_Maintenance_Priority' . rand()); Mock::generate('MAX_Dal_Admin_Data_intermediate_ad', $this->mockDalIntermediateAd = 'MAX_Dal_Admin_Data_intermediate_ad' . rand()); Mock::generatePartial('OA_Maintenance_Priority_AdServer_Task_ECPMforRemnant', 'PartialMock_OA_Maintenance_Priority_AdServer_Task_ECPMforRemnant', array('_getDal', '_factoryDal', 'getTodaysRemainingOperationIntervals', 'calculateCampaignEcpm')); }
/** * Test dependencies. */ function test_dependencies_api() { global $app_version; Mock::generatePartial('Plugin', 'PluginTestVersion', array('GetDependencies')); // Only major version given (not fulfilled) $test_Plugin = new PluginTestVersion(); $test_Plugin->setReturnValue('GetDependencies', array('requires' => array('app_min' => '1000'))); $dep_msgs = $this->Plugins->validate_dependencies($test_Plugin, 'enable'); $this->assertEqual(array_keys($dep_msgs), array('error')); $this->assertEqual(count($dep_msgs['error']), 1); // Current version given (fulfilled) $test_Plugin = new PluginTestVersion(); $test_Plugin->setReturnValue('GetDependencies', array('requires' => array('app_min' => $app_version))); $dep_msgs = $this->Plugins->validate_dependencies($test_Plugin, 'enable'); $this->assertEqual(array_keys($dep_msgs), array()); // Only major version given (fulfilled) $test_Plugin = new PluginTestVersion(); $test_Plugin->setReturnValue('GetDependencies', array('requires' => array('app_min' => '0'))); $dep_msgs = $this->Plugins->validate_dependencies($test_Plugin, 'enable'); $this->assertEqual(array_keys($dep_msgs), array()); // Obsolete "api_min" (fulfilled) $test_Plugin = new PluginTestVersion(); $test_Plugin->setReturnValue('GetDependencies', array('requires' => array('api_min' => array(1, 1)))); $dep_msgs = $this->Plugins->validate_dependencies($test_Plugin, 'enable'); $this->assertEqual(array_keys($dep_msgs), array()); }
/** * The constructor method. */ function __construct() { parent::__construct(); Mock::generatePartial('OA_Dll_Agency', 'PartialMockOA_Dll_Agency_AdvertiserTest', array('checkPermissions')); parent::__construct(); Mock::generatePartial('OA_Dll_Advertiser', 'PartialMockOA_Dll_Advertiser_AdvertiserTest', array('checkPermissions', 'getDefaultAgencyId')); }
function testDuplicate() { $GLOBALS['strCopyOf'] = 'Copy of '; $filename = 'test.gif'; $doBanners = OA_Dal::factoryDO('banners'); $doBanners->filename = $filename; $doBanners->storagetype = 'sql'; $doBanners->acls_updated = '2007-04-03 19:28:06'; $id1 = DataGenerator::generateOne($doBanners, true); $doBanners = OA_Dal::staticGetDO('banners', $id1); Mock::generatePartial('DataObjects_Banners', $mockBanners = 'DataObjects_Banners' . rand(), array('_imageDuplicate')); $doMockBanners = new $mockBanners($this); $doMockBanners->init(); $doMockBanners->setFrom($doBanners); $doMockBanners->bannerid = $doBanners->bannerid; // setFrom() doesn't copy primary key $doMockBanners->setReturnValue('_imageDuplicate', $filename); // make sure image was duplicated as well $doMockBanners->expectOnce('_imageDuplicate'); $id2 = $doMockBanners->duplicate(); // duplicate $doMockBanners->tally(); $this->assertNotEmpty($id2); $this->assertNotEqual($id1, $id2); $doBanners1 = OA_Dal::staticGetDO('banners', $id1); $doBanners2 = OA_Dal::staticGetDO('banners', $id2); // assert they are equal (but without comparing primary key) $this->assertNotEqualDataObjects($this->stripKeys($doBanners1), $this->stripKeys($doBanners2)); // Test that the only difference is their description $doBanners1->description = $doBanners2->description = null; $this->assertEqualDataObjects($this->stripKeys($doBanners1), $this->stripKeys($doBanners2)); }
/** * The constructor method. */ function __construct() { parent::__construct(); Mock::generate('OA_Dal_Maintenance_Priority', $this->mockDal = 'MockOA_Dal_Maintenance_Priority' . rand()); Mock::generatePartial('OA_Maintenance_Priority_AdServer_Task_PriorityCompensation', 'PartialMock_OA_Maintenance_Priority_AdServer_Task_PriorityCompensation', array('_getDal', '_getOperationIntUtils', '_getMaxEntityAdObject')); Mock::generatePartial('OA_Maintenance_Priority_Ad', 'PartialOA_Maintenance_Priority_Ad', array()); }
/** * The constructor method. */ function Test_OA_Maintenance_Priority_AdServer_Task_AllocateZoneImpressions() { $this->UnitTestCase(); Mock::generate('MAX_Dal_Entities'); Mock::generate('OA_Dal_Maintenance_Priority'); Mock::generate('OA_DB_Table_Priority'); }
/** * The class constructor method. */ function __construct() { parent::__construct(); Mock::generate('MAX_Dal_Entities'); Mock::generate('OA_Dal_Maintenance_Priority'); Mock::generatePartial('OX_Maintenance_Priority_Campaign', 'MockPartialOX_Maintenance_Priority_Campaign', array('_abort')); }
/** * The constructor method. */ function OA_Dll_AdvertiserTest() { $this->UnitTestCase(); Mock::generatePartial('OA_Dll_Agency', 'PartialMockOA_Dll_Agency_AdvertiserTest', array('checkPermissions')); $this->UnitTestCase(); Mock::generatePartial('OA_Dll_Advertiser', 'PartialMockOA_Dll_Advertiser_AdvertiserTest', array('checkPermissions', 'getDefaultAgencyId')); }
/** * The constructor method. */ function __construct() { parent::__construct(); Mock::generate('MAX_Dal_Entities'); Mock::generate('OA_Dal_Maintenance_Priority'); Mock::generate('OA_DB_Table_Priority'); }
function testExecute() { Mock::generatePartial('OA_UpgradeLogger', $mockLogger = 'OA_UpgradeLogger' . rand(), array('logOnly', 'logError', 'log')); $oLogger = new $mockLogger($this); $oLogger->setReturnValue('logOnly', true); $oLogger->setReturnValue('logError', true); $oLogger->setReturnValue('log', true); Mock::generatePartial('OA_Upgrade', $mockUpgrade = 'OA_Upgrade' . rand(), array('addPostUpgradeTask')); $mockUpgrade = new $mockUpgrade($this); $mockUpgrade->setReturnValue('addPostUpgradeTask', true); $mockUpgrade->oLogger = $oLogger; $mockUpgrade->oDBUpgrader = new OA_DB_Upgrade($oLogger); $mockUpgrade->oDBUpgrader->oTable =& $this->oaTable; // Run the upgrade $postscript = new OA_UpgradePostscript_2_7_30_beta_rc5(); $ret = $postscript->execute(array(&$mockUpgrade)); $this->assertTrue($ret); // Get the preference that we have inserted $doPreferences = OA_Dal::factoryDO('preferences'); $doPreferences->preference_name = 'campaign_ecpm_enabled'; $doPreferences->account_type = 'MANAGER'; $doPreferences->find(); $numberPreferences = $doPreferences->getRowCount(); $this->assertEqual(1, $numberPreferences); }
/** * The class constructor method. */ function Test_OX_Maintenance_Priority_Campaign() { $this->UnitTestCase(); Mock::generate('MAX_Dal_Entities'); Mock::generate('OA_Dal_Maintenance_Priority'); Mock::generatePartial('OX_Maintenance_Priority_Campaign', 'MockPartialOX_Maintenance_Priority_Campaign', array('_abort')); }
/** * Want to make sure that our schema * */ function testFindSchemaReturnsTheExpectedResult() { $expected = "CREATE TABLE IF NOT EXISTS `betting_index`.`event`"; $this->_callDynamicDBStub(); $actual = $this->_dynamicDBStub->findSchema('event'); $this->assertContains($expected, $actual); }
function testgetTasksUrls() { // Mock install status to mark update process Mock::generatePartial('OX_Admin_UI_Install_InstallStatus', 'OX_Admin_UI_Install_InstallStatusMock', array('isUpgrade')); $oInstallStatus = new OX_Admin_UI_Install_InstallStatusMock($this); $oInstallStatus->setReturnValue('isUpgrade', true); $oStorage = OX_Admin_UI_Install_InstallUtils::getSessionStorage(); @($oStatus = $oStorage->set('installStatus', $oInstallStatus)); include MAX_PATH . '/etc/default_plugins.php'; // set default plugins as installed except last one foreach ($aDefaultPlugins as $idx => $aPlugin) { $GLOBALS['_MAX']['CONF']['plugins'][$aPlugin['name']] = true; $lastPlugin = $aPlugin['name']; $lastPluginData = $aPlugin; } unset($GLOBALS['_MAX']['CONF']['plugins'][$lastPlugin]); $baseInstallUrl = 'my base url'; $GLOBALS['strPluginTaskChecking'] = 'Checking'; $GLOBALS['strPluginTaskInstalling'] = 'Installing'; $aExpected = array(); foreach ($GLOBALS['_MAX']['CONF']['plugins'] as $pluginName => $pluginEnabled) { $aExpected[] = array('id' => 'plugin:' . $pluginName, 'name' => $GLOBALS['strPluginTaskChecking'] . ': <br/> ' . $this->_correctPluginName($pluginName), 'url' => $baseInstallUrl . 'install-plugin.php?status=1&plugin=' . $pluginName); } $aExpected[] = array('id' => 'plugin:' . $lastPlugin, 'name' => $GLOBALS['strPluginTaskInstalling'] . ': <br/> ' . $this->_correctPluginName($lastPlugin), 'url' => $baseInstallUrl . 'install-plugin.php?status=0&plugin=' . $lastPlugin . (empty($lastPluginData['disabled']) ? '' : '&disabled=1')); $result = OX_Upgrade_InstallPlugin_Controller::getTasksUrls($baseInstallUrl); $this->assertEqual($result, $aExpected); $oStatus = $oStorage->set('installStatus', null); }
function test_executeTasksTablesAlter() { $this->assertTrue($this->initDatabase(325, array('campaigns')) . 'failed to created version 325 of campaigns table'); $tblCampaigns = $this->oDbh->quoteIdentifier($this->prefix . 'campaigns', true); // Insert some data to test the upgrade from... we know the schema being used so we can directly insert $this->oDbh->exec("INSERT INTO {$tblCampaigns} VALUES (1,'campaign one', 1, 100, 10, 1, '2000-01-01', '2000-01-01', 't', 'h', 1, 1, 'f', 'f')"); $this->oDbh->exec("INSERT INTO {$tblCampaigns} VALUES (2,'campaign two', 1, 100, 10, 1, '2000-01-01', '2000-01-01', 't', 'm', 1, 1, 'f', 'f')"); $this->oDbh->exec("INSERT INTO {$tblCampaigns} VALUES (3,'campaign three', 1, -1, -1, -1, '2000-01-01', '2000-01-01', 't', 'l', 1, 1, 'f', 'f')"); $this->oDbh->exec("INSERT INTO {$tblCampaigns} VALUES (4,'campaign four', 1, 100, 10, 1, '2000-01-01', '2000-01-01', 't', 'h', 1, 1, 'f', 'f')"); $this->oDbh->exec("INSERT INTO {$tblCampaigns} VALUES (5,'campaign five', 1, 100, 10, 1, '2000-01-01', '2000-01-01', 't', 'm', 1, 1, 'f', 'f')"); $this->oDbh->exec("INSERT INTO {$tblCampaigns} VALUES (6,'campaign six', 1, -1, -1, -1, '2000-01-01', '2000-01-01', 't', 'l', 1, 1, 'f', 'f')"); Mock::generatePartial('OA_DB_UpgradeAuditor', $mockAuditor = 'OA_DB_UpgradeAuditor' . rand(), array('logAuditAction', 'setKeyParams')); $oLogger = new OA_UpgradeLogger(); $oLogger->setLogFile('DB_Upgrade.test.log'); $oDB_Upgrade = new OA_DB_Upgrade($oLogger); $oDB_Upgrade->oAuditor = new $mockAuditor($this); $oDB_Upgrade->oAuditor->setReturnValue('logAuditAction', true); $oDB_Upgrade->oAuditor->setReturnValue('setKeyParams', true); $oDB_Upgrade->init('constructive', 'tables_core', 326); $aDef325 = $this->oaTable->aDefinition; $oDB_Upgrade->aDBTables = $oDB_Upgrade->_listTables(); $this->assertTrue($oDB_Upgrade->_verifyTasksTablesAlter(), 'failed _verifyTasksTablesAlter: change field'); $this->assertTrue($oDB_Upgrade->_executeTasksTablesAlter(), 'failed _executeTasksTablesAlter: change field'); $aDefDB = $oDB_Upgrade->oSchema->getDefinitionFromDatabase(array($this->prefix . 'campaigns')); $aDiff = $oDB_Upgrade->oSchema->compareDefinitions($this->aDefNew, $aDefDb); $this->assertEqual(count($aDiff), 0, 'comparison failed'); $aResults = $this->oDbh->queryAll("SELECT * FROM " . $tblCampaigns); $this->assertIsa($aResults, 'array'); $expected = array(1 => '5', 2 => '3', 3 => '0', 4 => '5', 5 => '3', 6 => '0'); foreach ($aResults as $idx => $aRow) { $this->assertEqual($aRow['priority'], $expected[$aRow['campaignid']], ' unexpected campaign priority value detected after upgrade'); } }
/** * Constructor. * * @access public * @return void */ public function setUp() { parent::setUp(); Mock::generate('Omnilog_model', get_class($this) . '_mock_model'); $this->EE->omnilog_model = $this->_get_mock('model'); $this->_model = $this->EE->omnilog_model; $this->_subject = new Omnilog_mcp(); }
public function setUp() { Mock::generate('\\Pheanstalk\\Socket\\StreamFunctions', 'MockStreamFunctions'); $instance = new MockStreamFunctions(); $instance->setReturnValue('fsockopen', true); \Pheanstalk\Socket\StreamFunctions::setInstance($instance); $this->_streamFunctions = $instance; }
public function __construct() { parent::__construct(); Mock::generate('AkActiveRecord'); Mock::generate('AkActionController'); Mock::generate('AkRequest'); $this->testing_url_path = AK_ASSET_URL_PREFIX; }
/** * The constructor method. */ function Test_OA_DB_Table() { $this->UnitTestCase(); // Mock the OA_DB class Mock::generate('OA_DB'); // Partially mock the OA_DB_Table class Mock::generatePartial('OA_DB_Table', 'PartialMockOA_DB_Table', array('_getDbConnection')); }
/** * Constructor. * * @access public * @return void */ public function setUp() { parent::setUp(); Mock::generate('Omnilog_model', get_class($this) . '_mock_model'); $this->EE->omnilog_model = $this->_get_mock('model'); $this->_model = $this->EE->omnilog_model; $this->_log_entry_props = array('addon_name' => 'Example Add-on', 'date' => time() - 100, 'message' => 'Example log entry.', 'extended_data' => 'Example OmniLog extended data.', 'notify_admin' => FALSE, 'type' => Omnilog_entry::NOTICE); }
/** * The constructor method. */ function __construct() { parent::__construct(); // Mock the OA_DB class Mock::generate('OA_DB'); // Partially mock the OA_DB_Table class Mock::generatePartial('OA_DB_Table', 'PartialMockOA_DB_Table', array('_getDbConnection')); }
function generate_mock_once($name) { $mock_name = $name . 'Mock'; if (class_exists($mock_name, false)) { return false; } Mock::generate($name, $mock_name); }
/** * This function sets up a TestHttpSocket instance we are going to use for testing * */ function setUp() { if (!class_exists('TestHttpSocket')) { Mock::generatePartial('HttpSocket', 'TestHttpSocket', array('read', 'write', 'connect')); Mock::generatePartial('HttpSocket', 'TestHttpSocketRequests', array('read', 'write', 'connect', 'request')); } $this->Socket =& new TestHttpSocket(); $this->RequestSocket =& new TestHttpSocketRequests(); }