Beispiel #1
0
 /**
  * Creates and instance of the mock object.
  *
  * @param   PHPUnit_Framework_TestCase  $test  A test object.
  *
  * @return  PHPUnit_Framework_MockObject_MockObject
  */
 public static function create($test)
 {
     // Collect all the relevant methods in JDatabase.
     $methods = array('getIssueId', 'setIssueId', 'getIssue', 'getIssueProject', 'getIssues');
     // Create the mock.
     $mockObject = $test->getMock('MonitorModelIssue', $methods, array(), '', false);
     self::createSampleData();
     $setterCallback = function ($id) {
         self::$issueId = $id;
     };
     $mockObject->expects($test->any())->method('setIssueId')->will($test->returnCallback($setterCallback));
     $mockObject->expects($test->any())->method('getIssueId')->will($test->returnValue(self::$issueId));
     $mockObject->expects($test->any())->method('getIssue')->will($test->returnValue(self::$data[self::$issueId]));
     $mockObject->expects($test->any())->method('getIssueProject')->will($test->returnValue(1));
     $mockObject->expects($test->any())->method('getIssues')->will($test->returnValue(self::$data));
     return $mockObject;
 }
 /**
  * Test of the build function.
  *
  * @param   array   $queryExpected  The expected parsed query..
  * @param   string  $url            URL to be parsed.
  * @param   array   $exceptions     Array of exceptional menu items, where the URL is different.
  *
  * @dataProvider buildProvider
  * @return null
  */
 public function testParse($queryExpected, $url, $exceptions)
 {
     $modelProject = MonitorTestMockModelProject::create($this);
     $modelIssue = MonitorTestMockModelIssue::create($this);
     MonitorTestMockMenu::createMenuSampleData();
     for ($i = 0; $i < MonitorTestMockMenu::getItemCount(); $i++) {
         MonitorTestMockMenu::setActiveIndex($i);
         $menu = MonitorTestMockMenu::create($this);
         $router = new MonitorRouter($this->getMockCmsApp(), $menu, $modelProject, $modelIssue);
         $description = "Active Item: ({$i}) " . $menu->getActive()->link . "\n";
         // TODO: Test query rest
         if (isset($exceptions[$i])) {
             $segments = explode('/', $exceptions[$i]);
             $description .= "URL: " . $exceptions[$i];
         } else {
             $segments = explode('/', $url);
             $description .= "URL: " . $url;
         }
         $query = $router->parse($segments);
         MonitorRouter::convertTaskToView($query);
         MonitorRouter::convertTaskToView($queryExpected);
         $this->assertEquals($queryExpected, $query, $description);
     }
 }