/** * @dataProvider provideTimestamps */ public function test_GetTimestamp_ReturnsFormattedValue($timestamp, $expectedTimestamp) { $microtime = new PHPUnit_Extensions_MockFunction('microtime', $this->_fsm); $microtime->expects($this->once())->will($this->returnValue($timestamp)); $timestamp = $this->_fsm->getTimestamp(); $this->assertSame($expectedTimestamp, $timestamp); }
/** * @test */ public function output_parameter_is_passed_to_method() { $output_file = "/tmp/output.log"; $output = "This is testing."; $MockFunction = new \PHPUnit_Extensions_MockFunction('file_put_contents', $this); $MockFunction->expects($this->once())->with($this->equalTo($output_file), $this->equalTo($output), FILE_APPEND)->will($this->returnValue(true)); $Logger = new \Logger($output_file); $Logger->output($output); }
/** * Testing newly created function. */ public function testMockNewFunction() { $this->test_function_name = 'new_random_function_' . uniqid(); $this->object = new PHPUnit_Extensions_MockFunction($this->test_function_name, $this->test_scope_object); // Return normally, only checks the call. $this->object->expects($this->any())->will($this->returnValue('OK')); $this->assertSame('OK', $this->test_scope_object->callFunction($this->test_function_name, array())); $this->object->restore(); }
/** * Test simple function return faking without consraints. */ public function testMockWithReturn() { $this->object = new PHPUnit_Extensions_MockStaticMethod('TestStatic::test', $this->test_scope_object); // CHanging return value. $this->object->expects($this->atLeastOnce())->will($this->returnValue('DEF')); $this->assertSame('DEF', $this->test_scope_object->callStatic()); // From this scope the original method is called. $this->assertSame('ABC', TestStatic::test()); $this->object->restore(); // We are back in 1985. $this->assertSame('ABC', $this->test_scope_object->callStatic()); }
function setUp() { parent::setUp(); $get_option = new PHPUnit_Extensions_MockFunction('get_option'); $get_option->expects($this->any())->will($this->returnCallback(array($this, 'callback'))); $update_option = new PHPUnit_Extensions_MockFunction('update_option'); $this->setupInit(); $this->_sut = new org_tubepress_impl_options_WordPressStorageManager(); $ioc = org_tubepress_impl_ioc_IocContainer::getInstance(); $validator = $ioc->get(org_tubepress_api_options_OptionValidator::_); $validator->shouldReceive('isValid')->andReturn(true); $this->_sut->init(); }
function testInitAction() { $iocContainer = org_tubepress_impl_ioc_IocContainer::getInstance(); $ms = $iocContainer->get(org_tubepress_api_message_MessageService::_); $widgetOps = array('classname' => 'widget_tubepress', 'description' => '<<Displays YouTube or Vimeo videos with TubePress>>'); $ms->shouldReceive('_')->atLeast(1)->andReturnUsing(function ($key) { return "<<{$key}>>"; }); $wp_register_sidebar_widget = new PHPUnit_Extensions_MockFunction('wp_register_sidebar_widget'); $wp_register_sidebar_widget->expects($this->once())->with('tubepress', 'TubePress', array('org_tubepress_impl_env_wordpress_Widget', 'printWidget'), $widgetOps); $wp_register_widget_control = new PHPUnit_Extensions_MockFunction('wp_register_widget_control'); $wp_register_widget_control->expects($this->once())->with('tubepress', 'TubePress', array('org_tubepress_impl_env_wordpress_Widget', 'printControlPanel')); org_tubepress_impl_env_wordpress_Widget::initAction(); }
public function test() { ${org_tubepress_impl_env_wordpress_Widget::WIDGET_SUBMIT_TAG} = '<<widget-submit-tag>>'; ${org_tubepress_impl_env_wordpress_Widget::WIDGET_CONTROL_TITLE} = '<<widget-control-title>>'; ${org_tubepress_impl_env_wordpress_Widget::WIDGET_TITLE} = '<<widget-title>>'; ${org_tubepress_impl_env_wordpress_Widget::WIDGET_SHORTCODE} = '<<widget-shortcode>>'; ${org_tubepress_impl_env_wordpress_Widget::WIDGET_SUBMIT_TAG} = '<<widget-submit-tag>>'; ${org_tubepress_impl_env_wordpress_Widget::WIDGET_CONTROL_SHORTCODE} = '<<widget-control-shortcode>>'; $nonceMock = new PHPUnit_Extensions_MockFunction('wp_nonce_field'); $nonceMock->expects($this->once())->will($this->returnCallback(array($this, 'doNonce'))); ob_start(); include BASE . '/sys/ui/templates/wordpress/widget_controls.tpl.php'; $result = ob_get_contents(); ob_end_clean(); $this->assertEquals($this->_expected(), $result); }
function testInitAction() { $ioc = org_tubepress_impl_ioc_IocContainer::getInstance(); $fs = $ioc->get(org_tubepress_api_filesystem_Explorer::_); $fs->shouldReceive('getTubePressInstallationDirectoryBaseName')->once()->andReturn('base_name'); $plugins_url = new PHPUnit_Extensions_MockFunction('plugins_url'); $plugins_url->expects($this->exactly(2))->will($this->_getPluginsUrlReturnMap()); $is_admin = new PHPUnit_Extensions_MockFunction('is_admin'); $is_admin->expects($this->once())->will($this->returnValue(false)); $wp_register_script = new PHPUnit_Extensions_MockFunction('wp_register_script'); $wp_register_script->expects($this->once())->with('tubepress', 'foobar'); $wp_register_style = new PHPUnit_Extensions_MockFunction('wp_register_style'); $wp_register_style->expects($this->once())->with('tubepress', 'fooey'); $wp_enqueue_script = new PHPUnit_Extensions_MockFunction('wp_enqueue_script'); $wp_enqueue_script->expects($this->exactly(2))->will($this->_getEnqueueScriptReturnMap()); $wp_enqueue_style = new PHPUnit_Extensions_MockFunction('wp_enqueue_style'); $wp_enqueue_style->expects($this->once())->with('tubepress'); org_tubepress_impl_env_wordpress_Main::initAction(); }
public function test() { $filter = \Mockery::mock(org_tubepress_spi_options_ui_Field::__); $filter->shouldReceive('getTitle')->once()->andReturn('filter-title'); $filter->shouldReceive('getHtml')->once()->andReturn('filter-html'); ${org_tubepress_impl_options_ui_AbstractFormHandler::TEMPLATE_VAR_TITLE} = '<<template-var-title>>'; ${org_tubepress_impl_options_ui_AbstractFormHandler::TEMPLATE_VAR_FILTER} = $filter; ${org_tubepress_impl_options_ui_AbstractFormHandler::TEMPLATE_VAR_INTRO} = '<<template-var-intro>>'; ${org_tubepress_impl_options_ui_AbstractFormHandler::TEMPLATE_VAR_SAVE_ID} = '<<template-var-saveid>>'; ${org_tubepress_impl_options_ui_AbstractFormHandler::TEMPLATE_VAR_SAVE_TEXT} = '<<template-var-savetext>>'; ${org_tubepress_impl_options_ui_AbstractFormHandler::TEMPLATE_VAR_TABS} = '<<template-var-tabs>>'; $nonceMock = new PHPUnit_Extensions_MockFunction('wp_nonce_field'); $nonceMock->expects($this->once())->will($this->returnCallback(array($this, 'doNonce'))); ob_start(); include BASE . '/sys/ui/templates/wordpress/options_page.tpl.php'; $result = ob_get_contents(); ob_end_clean(); $this->assertEquals($this->_removeTabs($this->_removeNewLines($this->_expected())), $this->_removeTabs($this->_removeNewLines($result))); }
function testWordPress() { $ioc = org_tubepress_impl_ioc_IocContainer::getInstance(); $ed = $ioc->get(org_tubepress_api_environment_Detector::_); $ed->shouldReceive('isWordPress')->once()->andReturn(true); $fse = $ioc->get(org_tubepress_api_filesystem_Explorer::_); $fse->shouldReceive('getTubePressInstallationDirectoryBaseName')->once()->andReturn('path'); $get_option = new PHPUnit_Extensions_MockFunction('site_url'); $get_option->expects($this->once())->will($this->returnValue('valueofsiteurl')); $loadPluginTextDomain = new PHPUnit_Extensions_MockFunction('load_plugin_textdomain'); $loadPluginTextDomain->expects($this->once())->with('tubepress', false, 'path/sys/i18n'); $add_filter = new PHPUnit_Extensions_MockFunction('add_filter'); $add_filter->expects($this->once())->with('the_content', array('org_tubepress_impl_env_wordpress_Main', 'contentFilter')); $add_action = new PHPUnit_Extensions_MockFunction('add_action'); $add_action->expects($this->exactly(5))->will($this->_getAddActionReturnMap()); $this->_sut->on_boot(); global $tubepress_base_url; $this->assertEquals('valueofsiteurl/wp-content/plugins/path', $tubepress_base_url); }
/** * Clean-up function. * * Removes mocked method and restores the original was there is any. * Also removes the reference to the object from self::$instances. */ public function restore() { if ($this->active) { list($class, $method) = $this->getClassAndMethod(); runkit_method_remove($class, $method); runkit_method_rename($class, $this->restore_name, $method); $this->active = false; } parent::restore(); }
/** * @test * @expectedException RuntimeException * @expectedExceptionMessage Failed to get mock object */ public function get_mock_with_unknown_function() { $mockDate = new PHPUnit_Extensions_MockFunction('date', $this); PHPUnit_Extensions_MockFunction::getMock('time'); }
/** * @expectedException RuntimeException * @expectedExceptionMessage Failed to get mock object */ public function testGetMockWithUnknownFunction() { $mockDate = new PHPUnit_Extensions_MockFunction('date', $this); PHPUnit_Extensions_MockFunction::getMock('time'); }
/** test array optional parameter */ public function testReturnAsArray() { $handler = new Postmen('', 'region', array('array' => true)); $curl_response = $this->headers . '{"meta":{"code":200,"message":"OK"},"data":{"key1":"value1", "key2":"value2"}}'; $mock_curl = new PHPUnit_Extensions_MockFunction('curl_exec', $handler); $mock_curl->expects($this->at(0))->will($this->returnValue($curl_response)); $mock_curl_length = new PHPUnit_Extensions_MockFunction('curl_getinfo', $handler); $mock_curl_length->expects($this->atLeastOnce())->will($this->returnValue($this->headers_length)); $result = $handler->get('labels', ''); $this->assertEquals(isset($result['key1']), true); $this->assertEquals(isset($result['key2']), true); $this->assertEquals($result['key1'], 'value1'); $this->assertEquals($result['key2'], 'value2'); }
private function _setupWorkingNonce() { $adminCheck = new PHPUnit_Extensions_MockFunction('check_admin_referer'); $adminCheck->expects($this->once())->with('tubepress-save', 'tubepress-nonce')->will($this->returnValue(true)); }
function setUp() { $this->_sut = new org_tubepress_impl_message_WordPressMessageService(); $__ = new PHPUnit_Extensions_MockFunction('__'); $__->expects($this->any())->will($this->returnCallback(array($this, 'echoCallback'))); }