generate() public static method

Clones a class' interface and creates a mock version that can have return values and expectations set.
public static generate ( string $class, string $mock_class = false, array $methods = false )
$class string Class to clone.
$mock_class string New class name. Default is the old name with "Mock" prepended.
$methods array Additional methods to add beyond those in the cloned class. Use this to emulate the dynamic addition of methods in the cloned class or when the class hasn't been written yet.sta
 /**
  * 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'));
 }
 /**
  * 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 __construct()
 {
     parent::__construct();
     Mock::generate('MAX_Dal_Entities');
     Mock::generate('OA_Dal_Maintenance_Priority');
     Mock::generate('OA_DB_Table_Priority');
 }
Exemplo n.º 4
0
 /**
  * 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();
 }
 /**
  * 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());
 }
Exemplo n.º 6
0
 function setUp()
 {
     global $DB;
     Mock::generate(get_class($DB), 'mockDB');
     $this->realDB = $DB;
     $DB = new mockDB();
 }
 /**
  * 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'));
 }
 /**
  * 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');
 }
Exemplo n.º 9
0
 public function __construct()
 {
     parent::__construct();
     // Make sure the moded db class is available
     Mock::generate('MY_DB');
     Template::$ignore_session = true;
 }
Exemplo n.º 10
0
 /**
  * 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'));
 }
Exemplo n.º 11
0
 /**
  * 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);
 }
Exemplo n.º 12
0
 public function setUp()
 {
     Mock::generate('\\Pheanstalk\\Socket\\StreamFunctions', 'MockStreamFunctions');
     $instance = new MockStreamFunctions();
     $instance->setReturnValue('fsockopen', true);
     \Pheanstalk\Socket\StreamFunctions::setInstance($instance);
     $this->_streamFunctions = $instance;
 }
Exemplo n.º 13
0
 /**
  * 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();
 }
Exemplo n.º 14
0
 public function __construct()
 {
     parent::__construct();
     Mock::generate('AkActiveRecord');
     Mock::generate('AkActionController');
     Mock::generate('AkRequest');
     $this->testing_url_path = AK_ASSET_URL_PREFIX;
 }
function generate_mock_once($name)
{
    $mock_name = $name . 'Mock';
    if (class_exists($mock_name, false)) {
        return false;
    }
    Mock::generate($name, $mock_name);
}
Exemplo n.º 16
0
 /**
  * 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'));
 }
Exemplo n.º 17
0
 public function __construct()
 {
     parent::__construct();
     // Make sure the moded db class is available
     Mock::generate('MY_DB');
     $this->ci->load->model('roles/role_model');
     Mock::generate('Role_model');
     Template::$ignore_session = true;
 }
Exemplo n.º 18
0
/**
 * mock('SomeClass');
 *
 * is exactly the same as
 *
 * <code>
 * Mock::generate('SomeClass');
 * $mock = new MockSomeClass();
 * </code>
 *
 * @param type $classname
 *
 * @return a simpletest mock
 */
function mock($classname)
{
    $mockclassname = "Mock{$classname}";
    if (strpos($classname, '\\') !== false) {
        $mockclassname = "Mock" . str_replace('\\', '_', $classname);
    }
    Mock::generate($classname, $mockclassname);
    return new $mockclassname();
}
Exemplo n.º 19
0
 function startTest()
 {
     Mock::generate('Controller');
     Mock::generate('SeoHoneypotVisit');
     $this->BlackList = new BlackListComponent();
     $this->BlackList->Controller = new MockController();
     $this->BlackList->SeoBlacklist = new TestBlacklist();
     $this->BlackList->SeoHoneypotVisit = new TestHoneyPotVisit();
 }
Exemplo n.º 20
0
 public function setUp()
 {
     $this->installAndIncludeModels(array('Hybrid'=>'id,name'));
     Mock::generate('AkDbAdapter');
     $Db = new MockAkDbAdapter();
     $Db->setReturnValue('select',array());
     $this->Db =& $Db;
     $this->Hybrid->setConnection($Db);
 }
Exemplo n.º 21
0
 public function setUp()
 {
     Mock::generate('AppController', 'TestController');
     Mock::generate('SessionComponent', 'MockSession');
     $this->Controller = new TestController();
     $this->StateMachine = new YantraComponent();
     $this->StateMachine->Session = new MockSession();
     $this->states = array('signing in' => array('sign_in', 'new_user'), 'billing' => 'billing', 'paying' => 'payment', 'reviewing' => 'summary', 'processing' => 'fulfill');
     $this->transitions = array('sign in' => array('signing in' => 'billing', 'paying' => 'billing', 'reviewing' => 'billing'), 'bill & ship' => array('billing' => 'paying'), 'pay' => array('billing' => 'paying'), 'review' => array('paying' => 'reviewing'), 'process' => array('reviewing' => 'processing'));
 }
Exemplo n.º 22
0
 public function testExpose()
 {
     Mock::generate('MyClass', 'MyMock');
     $m = new MyMock();
     Ernie::expose('test', $m);
     $m->expectCallCount('a', 1);
     $m->expectCallCount('b', 1);
     Ernie::dispatch('test', 'a', array());
     Ernie::dispatch('test', 'b', array());
 }
 /**
  * TODO: upgrade simpletest
  */
 function _REPAIR_ME_testGetPlugins()
 {
     Mock::generate('MAX_Plugin');
     $mockPlugins = new MockMAX_Plugin($this);
     $mockPlugins->setReturnValue('getPluginsFromFolder', true);
     $recursive = true;
     $mockPlugins->expectOnce('getPluginsFromFolder', array(MAX_PATH . '/plugins/moduleName/packageName', $recursive));
     $ret = $mockPlugins->getPlugins('moduleName', 'packageName', $recursive);
     $mockPlugins->tally();
 }
 /**
  * The constructor method.
  */
 function Test_OA_Maintenance_Priority_AdServer_Task_GetRequiredAdImpressionsLifetime()
 {
     $this->UnitTestCase();
     Mock::generate('MAX_Dal_Entities');
     Mock::generate('OA_Dal_Maintenance_Priority');
     Mock::generate('OA_DB_Table_Priority');
     // Install the openXDeliveryLog plugin
     TestEnv::uninstallPluginPackage('openXDeliveryLimitations', false);
     TestEnv::installPluginPackage('openXDeliveryLimitations', false);
 }
Exemplo n.º 25
0
Arquivo: unit.php Projeto: ssrsfs/blg
 public function setUp()
 {
     // Mock source for news articles
     Mock::generate('Dbi_Source');
     $model = new Model_News_Article();
     $mock = new MockDbi_Source();
     $mock->returns('select', new Dbi_Recordset_Array($model, array(array('newsid' => 1, 'title' => 'Article One', 'article' => '<p>Body 1</p>', 'summary' => 'Summary 1'), array('newsid' => 2, 'title' => 'Article Two', 'article' => '<p>Body 2</p>', 'summary' => 'Summary 2'))));
     $this->_oldSource = Dbi_Source::GetModelSource($model);
     Dbi_Source::SetModelSource($model, $mock);
 }
 /**
  * Create global mocked $Settings object.
  */
 function setUp()
 {
     parent::setUp();
     Mock::generate('GeneralSettings');
     $this->old_Settings_EvoFilemanUnitTestCase =& $GLOBALS['Settings'];
     $GLOBALS['Settings'] = new MockGeneralSettings();
     $GLOBALS['Settings']->setReturnValue('get', 1, array('fm_enable_roots_user'));
     $GLOBALS['Settings']->setReturnValue('get', '775', array('fm_default_chmod_dir'));
     $GLOBALS['Settings']->setReturnValue('get', '664', array('fm_default_chmod_file'));
 }
Exemplo n.º 27
0
 function testExtensionOfCommonSplClasses()
 {
     if (!function_exists('spl_classes')) {
         return;
     }
     Mock::generate('IteratorImplementation');
     $this->assertIsA(new IteratorImplementation(), 'IteratorImplementation');
     Mock::generate('IteratorAggregateImplementation');
     $this->assertIsA(new IteratorAggregateImplementation(), 'IteratorAggregateImplementation');
 }
Exemplo n.º 28
0
 public function setUp()
 {
     $this->_config = Configure::read('Cache.disable');
     Configure::write('Cache.disable', false);
     Mock::generate('AppController', 'TestController');
     Mock::generate('SessionComponent', 'MockSession');
     $this->Controller = new TestController();
     $this->Acl = new AuthorityComponent();
     $this->Acl->Session = new MockSession();
     $this->_writeTestConfiguration('test_authority');
 }
Exemplo n.º 29
0
 /**
  * Constructor.
  *
  * @access  public
  * @return  void
  */
 public function setUp()
 {
     parent::setUp();
     // Generate the mock model.
     Mock::generate('Crumbly_model', get_class($this) . '_mock_model');
     $this->_model = $this->_get_mock('model');
     $this->EE->crumbly_model = $this->_model;
     $this->_site_id = 10;
     $this->EE->crumbly_model->setReturnValue('get_site_id', $this->_site_id);
     $this->_subject = new Crumbly();
 }
Exemplo n.º 30
0
 public function testFaqItemName()
 {
     Mock::generate('DbService');
     $dbService = new MockDbService();
     $faqService = new FaqService();
     $faqService->dbService = $dbService;
     $faq = new Faq();
     $params = array('title' => 'My FAQ entry & _+');
     $dbService->setReturnValue('saveObject', $faq);
     $result = $faqService->saveFaq($faq, $params);
     $this->assertEqual('my-faq-entry-and', $faq->faqurl);
 }