/** * Creates an instance of the mock JMenu object. * * @param FOFTestCase $test A test object. * * @return \PHPUnit_Framework_MockObject_MockObject * * @since 3.4 */ public static function create(FOFTestCase $test, $setDefault = true, $setActive = false) { // Collect all the relevant methods in JMenu (work in progress). $methods = array('getItem', 'setDefault', 'getDefault', 'setActive', 'getActive', 'getItems', 'getParams', 'getMenu', 'authorise', 'load'); // Create the mock. $mockObject = $test->getMock('\\JMenu', $methods, array(), '', false); self::createMenuSampleData(); $mockObject->expects($test->any())->method('getItem')->will($test->returnValueMap(self::prepareGetItemData())); $mockObject->expects($test->any())->method('getMenu')->will($test->returnValue(self::$data)); if ($setDefault) { $mockObject->expects($test->any())->method('getDefault')->will($test->returnValueMap(self::prepareDefaultData())); } if ($setActive) { $mockObject->expects($test->any())->method('getActive')->will($test->returnValue(self::$data[$setActive])); } return $mockObject; }
/** * Adds mock objects for some methods. * * @param FOFTestCase $test A test object. * @param \PHPUnit_Framework_MockObject_MockObject $mockObject The mock object. * @param array $options A set of options to configure the mock. * * @return \PHPUnit_Framework_MockObject_MockObject The object with the behaviours added * * @since 3.4 */ public static function addBehaviours($test, $mockObject, $options) { // Mock calls to JApplicationWeb::getDocument(). $mockObject->expects($test->any())->method('getDocument')->willReturn(MockDocument::create($test)); // Mock calls to JApplicationWeb::getLanguage(). $mockObject->expects($test->any())->method('getLanguage')->willReturn(MockLanguage::create($test)); // Mock a call to JApplicationWeb::getSession(). if (isset($options['session'])) { $mockObject->expects($test->any())->method('getSession')->willReturn($options['session']); } else { $mockObject->expects($test->any())->method('getSession')->willReturn(MockSession::create($test)); } $test->assignMockCallbacks($mockObject, array('appendBody' => array(is_callable(array($test, 'mockAppendBody')) ? $test : get_called_class(), 'mockAppendBody'), 'getBody' => array(is_callable(array($test, 'mockGetBody')) ? $test : get_called_class(), 'mockGetBody'), 'prependBody' => array(is_callable(array($test, 'mockPrependBody')) ? $test : get_called_class(), 'mockPrependBody'), 'setBody' => array(is_callable(array($test, 'mockSetBody')) ? $test : get_called_class(), 'mockSetBody'), 'getHeaders' => array(is_callable(array($test, 'mockGetHeaders')) ? $test : get_called_class(), 'mockGetHeaders'), 'setHeader' => array(is_callable(array($test, 'mockSetHeader')) ? $test : get_called_class(), 'mockSetHeader'), 'clearHeaders' => array(is_callable(array($test, 'mockClearHeaders')) ? $test : get_called_class(), 'mockClearHeaders'), 'allowCache' => array(is_callable(array($test, 'mockAllowCache')) ? $test : get_called_class(), 'mockAllowCache'))); // Reset the body storage. static::$body = array(); // Reset the headers storage. static::$headers = array(); // Reset the cache storage. static::$cachable = false; return parent::addBehaviours($test, $mockObject, $options); }
/** * Adds mock objects for some methods. * * @param FOFTestCase $test A test object. * @param \PHPUnit_Framework_MockObject_MockObject $mockObject The mock object. * @param array $options A set of options to configure the mock. * * @return \PHPUnit_Framework_MockObject_MockObject The object with the behaviours added * * @since 3.4 */ public static function addBehaviours($test, $mockObject, $options) { // Mock calls to JApplicationCms::getMenu(); $mockObject->expects($test->any())->method('getMenu')->will($test->returnValue(MockMenu::create($test))); return parent::addBehaviours($test, $mockObject, $options); }