/**
  * 
  * @param  I18n\Testcase  $testcase
  * @param  array          $translations
  */
 public function __construct(I18n\Testcase $testcase, $translations, $method_name = 'load_translations')
 {
     $this->translations = $translations;
     $this->load_file_counter = 0;
     $this->object = $testcase->getMock($testcase->class_name(), array($method_name));
     $this->object->expects($testcase->any())->method($method_name)->will($testcase->returnCallback(array($this, 'callback_load_translations')));
 }
 /**
  * Tests the findOneByProviderAndLongUrl method
  */
 public function testFindOneByProviderAndLongUrl()
 {
     $provider = $this->getMock('Mremi\\UrlShortener\\Provider\\UrlShortenerProviderInterface');
     $provider->expects($this->once())->method('getName')->will($this->returnValue('google'));
     $provider->expects($this->once())->method('shorten');
     $this->chainProvider->expects($this->once())->method('getProvider')->with($this->equalTo('google'))->will($this->returnValue($provider));
     $link = $this->manager->findOneByProviderAndLongUrl('google', 'http://www.google.com/');
     $this->assertInstanceOf('Mremi\\UrlShortener\\Model\\Link', $link);
     $this->assertEquals('http://www.google.com/', $link->getLongUrl());
 }
Example #3
0
    /**
     *
     */
    public function testStatsThrowsExceptionIfApiResponseHasInvalidStatusCode()
    {
        $this->setExpectedException('Sonrisa\\Service\\ShortLink\\Exceptions\\InvalidApiResponseException');
        $apiRawResponse = <<<JSON
{
 "kind": "urlshortener#url",
 "id": "http://goo.gl/fbsS",
 "longUrl": "http://www.google.com/",
 "status": "KO",
 "created": "2009-12-13T07:22:55.000+00:00",
 "analytics": {
  "allTime": {
   "shortUrlClicks": "3227",
   "longUrlClicks": "9358",
   "referrers": [ { "count": "2160", "id": "Unknown/empty" }  ],
   "countries": [ { "count": "1022", "id": "US" }  ],
   "browsers": [ { "count": "1025", "id": "Firefox" }  ],
   "platforms": [ { "count": "2278", "id": "Windows" }  ]
  }
 }
}
JSON;
        $this->provider = $this->getBaseMockResponse();
        $this->provider->expects($this->once())->method('request')->will($this->returnValue($apiRawResponse));
        $this->provider->stats("http://goo.gl/fbsS");
    }
Example #4
0
 /**
  * Sets up the mocks.
  *
  * @return void
  */
 private function _setUpMocks()
 {
     $this->_dataFolderMock = new PHPUnit_Extensions_MockStaticMethod('Advancedform\\Data::folder', $this);
     $this->_dataFolderMock->expects($this->any())->will($this->returnValue($this->_rootFolder));
     $this->_dbMock = new PHPUnit_Extensions_MockStaticMethod('Advancedform\\Data::readDB', $this);
     $this->_dbMock->expects($this->any())->will($this->returnValue(array('test' => array('fields' => array(array('field' => 'foo', 'type' => 'text'), array('field' => 'bar', 'type' => 'text'))))));
     $this->_eMock = new PHPUnit_Extensions_MockFunction('e', $this);
 }
 /**
  * Test if proper file is extrected from XML file.
  * 
  * SimpleXMLObject is generated by MockObject.
  * 
  * @return void
  */
 public function testGetFilesWithErrors()
 {
     $this->_mockXMLHandler->expects($this->once())->method('loadXML')->with($this->equalTo(self::$_cbXMLFile))->will($this->returnValue(simplexml_load_file(self::$_cbXMLFile)));
     $this->_mockXMLHandler->expects($this->atLeastOnce())->method('countItems')->will($this->returnValue(rand(1, 100)));
     $files = $this->_cbErrorHandler->getFilesWithErrors(self::$_cbXMLFile);
     $this->assertTrue(5 === count($files[0]));
     $this->assertEquals($this->_fileName, $files[0]['complete']);
 }
 /**
  * Mocks the client
  *
  * @param object $response      A mocked response
  * @param string $requestMethod A request method (get|post)
  */
 private function mockClient($response, $requestMethod)
 {
     $request = $this->getMock('Guzzle\\Http\\Message\\RequestInterface');
     $request->expects($this->once())->method('send')->will($this->returnValue($response));
     $client = $this->getMock('Guzzle\\Http\\ClientInterface');
     $client->expects($this->once())->method($requestMethod)->will($this->returnValue($request));
     $this->provider->expects($this->once())->method('createClient')->will($this->returnValue($client));
 }
 /**
  * Test if saving an XML file works properly.
  * Checks are done for content and file exists.
  *
  * @return void
  *
  * @group XMLHandler
  */
 public function testSaveXML()
 {
     $tmpXML = simplexml_load_string('<?xml version="1.0" encoding="utf-8"?><codebrowser></codebrowser>');
     $this->assertFileNotExists(self::$_cbTestXML);
     $this->_mockFDHandler->expects($this->once())->method('createFile')->with($this->equalTo(self::$_cbTestXML))->will($this->returnValue(file_put_contents(self::$_cbTestXML, $tmpXML->asXML())));
     $this->_cbXMLHandler->saveXML(self::$_cbTestXML, $tmpXML);
     $this->assertFileExists(self::$_cbTestXML);
     $this->assertXmlFileEqualsXmlFile(self::$_cbTestXML, PHPCB_TEST_DIR . '/basic.xml');
 }
 /**
  * Test if proper content is generated.
  * It is expeceted that source code from file is present and error Highlighting
  * is resolved the right way.
  *
  * @return void
  */
 public function testGetHighlightedSource()
 {
     $mockErrors = unserialize(file_get_contents(self::$_serializedErrors));
     $this->_mockFDHandler->expects($this->once())->method('loadFile')->with($this->equalTo(PHPCB_TEST_DIR . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'MyJSGenerator.php'))->will($this->returnValue(trim(file_get_contents(PHPCB_TEST_DIR . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'JSTestGenerator.php'))));
     $content = $this->_cbJSGenerator->getHighlightedSource('MyJSGenerator.php', $mockErrors['b0456446720360d02791c1a3d143f703'], PHPCB_TEST_DIR . DIRECTORY_SEPARATOR . 'src');
     $this->assertNotNull($content);
     $this->assertContains('<li id="line-249" class="white"><a name="line-249"></a><code><span class="comment">', $content);
     $this->assertContains('<li id="line-250-254" class="moreErrors" ><ul><li id="line-250" class="transparent"><a name="line-250"></a><code><span class="comment">    </span><span class="keyword">private function </span><span class="default">getFoldersFilesTree </span><span class="keyword">(</span><span class="default">$files</span><span class="keyword">)</span></code></li>', $content);
     $this->assertContains('<li id="line-251" class="transparent"><a name="line-251"></a><code><span class="keyword">', $content);
     $this->assertTrue((int) substr_count($content, '<ul>', 0) == (int) substr_count($content, '</ul>', 0));
     $this->assertTrue((int) substr_count($content, '<li ', 0) == (int) substr_count($content, '</li>', 0));
 }
Example #9
0
 /**
  * Assigns mock callbacks to methods.
  *
  * @param   object  $mockObject  The mock object that the callbacks are being assigned to.
  * @param   array   $array       An array of methods names to mock with callbacks.
  *                               This method assumes that the mock callback is named {mock}{method name}.
  *
  * @return  void
  *
  * @since   11.3
  */
 public function assignMockCallbacks($mockObject, $array)
 {
     foreach ($array as $index => $method) {
         if (is_array($method)) {
             $methodName = $index;
             $callback = $method;
         } else {
             $methodName = $method;
             $callback = array(get_called_class(), 'mock' . $method);
         }
         $mockObject->expects($this->any())->method($methodName)->will($this->returnCallback($callback));
     }
 }
Example #10
0
    /**
     *
     */
    public function testExpandThrowsExceptionInvalidURL404()
    {
        $this->setExpectedException('Sonrisa\\Service\\ShortLink\\Exceptions\\InvalidApiResponseException');
        $apiRawResponse = <<<JSON
{
  "data": {
    "expand": [
      {
        "global_hash": "900913",
        "long_url": "http://google.com/",
        "short_url": "http://bit.ly/ze6poY",
        "user_hash": "ze6poY"
      }
    ]
  },
  "status_code": 200,
  "status_txt": "OK"
}
JSON;
        $this->provider = $this->getBaseMockResponse();
        $this->provider->expects($this->any())->method('request')->will($this->returnValue($apiRawResponse));
        $this->provider->expand('http://www.google.com/i-dont-happen-to-exist.html');
    }
 /**
  * Mock methods recursively
  *
  * @param object $object
  * @param array $methods
  * @param mixed $lastReturnValue
  */
 protected function mockMethods($object, $methods, $lastReturnValue)
 {
     if ($methods) {
         foreach ($methods as $key => $method) {
             $mock = $object->expects($this->any())->method($method);
             if ($key >= count($methods) - 1) {
                 $mock->will($this->returnValue($lastReturnValue));
             } else {
                 $mock->will($this->returnValue($object));
             }
         }
     }
 }
Example #12
0
 /**
  * Assigns mock values to methods.
  *
  * @param   object  $mockObject  The mock object.
  * @param   array   $array       An associative array of methods to mock with return values:<br />
  * string (method name) => mixed (return value)
  *
  * @return  void
  *
  * @since   12.1
  */
 public function assignMockReturns($mockObject, $array)
 {
     foreach ($array as $method => $return) {
         $mockObject->expects($this->any())->method($method)->will($this->returnValue($return));
     }
 }
 /**
  * stub the specified methods on the mock to expect a
  * string argument and return itself
  * @param  array  $methods
  * @param  object $stub
  * @return object
  */
 protected function stubAcceptStrReturnSelf(array $methods, $stub)
 {
     foreach ($methods as $method) {
         $stub->expects($this->any())->method($method)->with($this->isType('string'))->will($this->returnSelf());
     }
     return $stub;
 }
 /**
  * Test if tree.html file is generated properly and if expected content
  * is written to this file. Files and folders are created by callback method
  * with original values.
  * Errors are read in by data provider
  * 
  * @dataProvider providedErrors
  */
 public function testGenerateViewTree($errors)
 {
     $this->_mockFDHandler->expects($this->once())->method('createFile')->will($this->returnCallback(array($this, 'callbackMockMethod')));
     $this->_mockJSGenerator->expects($this->once())->method('getJSTree')->with($this->equalTo($errors))->will($this->returnValue('<script type="text/javascript">Javascript Dummy</script>'));
     $this->_cbHTMLGenerator->setOutputDir(PHPCB_TEST_OUTPUT);
     $this->_cbHTMLGenerator->setTemplateDir(PHPCB_ROOT_DIR . 'templates');
     $this->_cbHTMLGenerator->generateViewTree($errors);
     $this->assertFileExists(PHPCB_TEST_OUTPUT . '/tree.html');
     $content = file_get_contents(PHPCB_TEST_OUTPUT . '/tree.html');
     $this->assertContains('<script type="text/javascript">Javascript Dummy</script></div>', $content);
     $this->assertTrue(0 == substr_count($content, '<a href=', 0));
 }
 /**
  * @param object $entity
  * @param string $code
  * @param array  $attributeCodes
  *
  * @return \Doctrine\Common\Collections\ArrayCollection
  */
 protected function addAttributeCollection($entity, $code, array $attributeCodes)
 {
     $test = $this;
     $collection = $this->getMock('Doctrine\\Common\\Collections\\ArrayCollection');
     $collection->expects($this->once())->method('toArray')->will($this->returnValue(array_map(function ($code) use($test) {
         return $test->addAttribute($code);
     }, $attributeCodes)));
     $entity->expects($this->any())->method('getCode')->will($this->returnValue($code));
     $entity->expects($this->once())->method('getAttributes')->will($this->returnValue($collection));
     return $collection;
 }
Example #16
0
 protected function setUp()
 {
     //Mock the Client's notify method, no args, skip __construct
     $this->object = $this->getMock('Airbrake\\Client', array('notify'), array(), '', false);
     $this->object->expects($this->once())->method('notify')->will($this->returnValue(true));
 }
 /**
  * Mocks Object->getResourceFromId
  *
  * Needs to pass a mock of a File or Folder
  *
  * @param object $mockedObject
  * @param int $fileId
  * @param File|Folder $answer
  */
 protected function mockGetResourceFromId($mockedObject, $fileId, $answer)
 {
     $mockedObject->expects($this->once())->method('getResourceFromId')->with($this->equalTo($fileId))->willReturn($answer);
 }