<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
  <channel>
    <title><![CDATA[Content with Style - Comments on Unit testing web service based models in Zend Framework]]></title>
    <link>http://www.contentwithstyle.co.uk/feeds/rss/comments/192</link>
    <description><![CDATA[]]></description>
    <pubDate>Tue, 07 Sep 2010 17:06:18 -0400</pubDate>
    <generator>Zend_Feed</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <item>
      <title><![CDATA[Content with Style - Comment #1 on Unit testing web service based models in Zend Framework]]></title>
      <link>http://www.contentwithstyle.co.uk/content/unit-testing-web-service-based-models-in-zend-framework/#comment-5973</link>
      <guid>http://www.contentwithstyle.co.uk/content/unit-testing-web-service-based-models-in-zend-framework/#comment-5973</guid>
      <description><![CDATA[<p>Hello,</p>

<p>You have a typo in the first code example [...]</p>]]></description>
      <content:encoded><![CDATA[<p>Hello,</p>

<p>You have a typo in the first code example [...]</p>]]></content:encoded>
      <pubDate>Wed, 29 Apr 2009 16:43:59 -0400</pubDate>
    </item>
    <item>
      <title><![CDATA[Content with Style - Comment #2 on Unit testing web service based models in Zend Framework]]></title>
      <link>http://www.contentwithstyle.co.uk/content/unit-testing-web-service-based-models-in-zend-framework/#comment-5974</link>
      <guid>http://www.contentwithstyle.co.uk/content/unit-testing-web-service-based-models-in-zend-framework/#comment-5974</guid>
      <description><![CDATA[Fixed, thanks for spotting it.]]></description>
      <content:encoded><![CDATA[Fixed, thanks for spotting it.]]></content:encoded>
      <pubDate>Wed, 29 Apr 2009 16:44:27 -0400</pubDate>
    </item>
    <item>
      <title><![CDATA[Content with Style - Comment #3 on Unit testing web service based models in Zend Framework]]></title>
      <link>http://www.contentwithstyle.co.uk/content/unit-testing-web-service-based-models-in-zend-framework/#comment-6601</link>
      <guid>http://www.contentwithstyle.co.uk/content/unit-testing-web-service-based-models-in-zend-framework/#comment-6601</guid>
      <description><![CDATA[Hello,
<p>
I am trying to do the same thing as above but using Zend_Service_Twitter
</p>

<p>
I have this:
</p>

<pre><code>
$mockReturn = array();
$mockReturn['request'] = '/account/verify_credentials.xml';
$mockReturn['error'] = 'Could not authenticate you.';

$stub = $this-&gt;getMock('Zend_Service_Twitter', array('verifyCredentials'),array(),'',FALSE);

 $stub-&gt;expects($this-&gt;once())
              -&gt;method('verifyCredentials')
              -&gt;will($this-&gt;returnValue($mockReturn));

$model = new Twitter_Model_Twitter(array('username'=&gt;'test','password'=&gt;'passwd'));
$model-&gt;setOptions(array('twitter'=&gt;$stub));

$posts = $model-&gt;verifyCredentials();
$this-&gt;assertEquals($posts, $mockReturn);
</code></pre>

<p>
I am confused because it is trying to access the twitter.com API. I know this because when I turned off my internet connection, I got this:
</p>

<pre><code>
1) testVerifyCredentials(Model_TwitterTest)
Zend_Http_Client_Adapter_Exception: Unable to Connect to tcp://twitter.com:80. Error #60: Operation timed out
</code></pre>

<p>
FYI: when it connects successfully to the twitter API i get this:
</p>

<pre><code>
1) testVerifyCredentials(Model_TwitterTest)
Failed asserting that two objects are equal.
--- Expected
+++ Actual
@@ -1,9 +1,5 @@
-Zend_Rest_Client_Result Object
+Array
 (
-    [_sxml:protected] =&gt; SimpleXMLElement Object
-        (
-            [request] =&gt; /statuses/friends.xml
-            [error] =&gt; This method requires authentication.
-        )
-
+    [request] =&gt; /account/verify_credentials.xml
+    [error] =&gt; Could not authenticate you.
 )

/htdocs/twitter/tests/application/models/TwitterTest.php:57
</code></pre>

<p>
How do I properly test Zend_Service_Twitter? 
When my Twitter_Model_Twitter looks like this:
</p>
]]></description>
      <content:encoded><![CDATA[Hello,
<p>
I am trying to do the same thing as above but using Zend_Service_Twitter
</p>

<p>
I have this:
</p>

<pre><code>
$mockReturn = array();
$mockReturn['request'] = '/account/verify_credentials.xml';
$mockReturn['error'] = 'Could not authenticate you.';

$stub = $this-&gt;getMock('Zend_Service_Twitter', array('verifyCredentials'),array(),'',FALSE);

 $stub-&gt;expects($this-&gt;once())
              -&gt;method('verifyCredentials')
              -&gt;will($this-&gt;returnValue($mockReturn));

$model = new Twitter_Model_Twitter(array('username'=&gt;'test','password'=&gt;'passwd'));
$model-&gt;setOptions(array('twitter'=&gt;$stub));

$posts = $model-&gt;verifyCredentials();
$this-&gt;assertEquals($posts, $mockReturn);
</code></pre>

<p>
I am confused because it is trying to access the twitter.com API. I know this because when I turned off my internet connection, I got this:
</p>

<pre><code>
1) testVerifyCredentials(Model_TwitterTest)
Zend_Http_Client_Adapter_Exception: Unable to Connect to tcp://twitter.com:80. Error #60: Operation timed out
</code></pre>

<p>
FYI: when it connects successfully to the twitter API i get this:
</p>

<pre><code>
1) testVerifyCredentials(Model_TwitterTest)
Failed asserting that two objects are equal.
--- Expected
+++ Actual
@@ -1,9 +1,5 @@
-Zend_Rest_Client_Result Object
+Array
 (
-    [_sxml:protected] =&gt; SimpleXMLElement Object
-        (
-            [request] =&gt; /statuses/friends.xml
-            [error] =&gt; This method requires authentication.
-        )
-
+    [request] =&gt; /account/verify_credentials.xml
+    [error] =&gt; Could not authenticate you.
 )

/htdocs/twitter/tests/application/models/TwitterTest.php:57
</code></pre>

<p>
How do I properly test Zend_Service_Twitter? 
When my Twitter_Model_Twitter looks like this:
</p>
]]></content:encoded>
      <pubDate>Mon, 10 Aug 2009 06:25:36 -0400</pubDate>
    </item>
    <item>
      <title><![CDATA[Content with Style - Comment #4 on Unit testing web service based models in Zend Framework]]></title>
      <link>http://www.contentwithstyle.co.uk/content/unit-testing-web-service-based-models-in-zend-framework/#comment-6603</link>
      <guid>http://www.contentwithstyle.co.uk/content/unit-testing-web-service-based-models-in-zend-framework/#comment-6603</guid>
      <description><![CDATA[<p>Wenbert, it looks to me like the twitter object doesn't swap properly in your model. If I was you I'd var_dump the model after I injected the mock object, to verify what's going on, and take it from there.</p>

<p>Also I'd have a close look at what exactly you are doing in $model->setOptions. Refer to the code above, there it's called $model->setProperty. Does this successfully alter the property? Again a var_dump before and after the replacement will probably show this.</p>

<p>If this part works, you'll probably have to check whether you overwrite the 'twitter' property later on.</p>

<p>Finally I'd recommend you an HTTP tracker like HTTPScoop to see what requests your machine does to the outside. It helps to have a close eye on the HTTP traffic when working with web services.</p>

<p>Good luck!</p>]]></description>
      <content:encoded><![CDATA[<p>Wenbert, it looks to me like the twitter object doesn't swap properly in your model. If I was you I'd var_dump the model after I injected the mock object, to verify what's going on, and take it from there.</p>

<p>Also I'd have a close look at what exactly you are doing in $model->setOptions. Refer to the code above, there it's called $model->setProperty. Does this successfully alter the property? Again a var_dump before and after the replacement will probably show this.</p>

<p>If this part works, you'll probably have to check whether you overwrite the 'twitter' property later on.</p>

<p>Finally I'd recommend you an HTTP tracker like HTTPScoop to see what requests your machine does to the outside. It helps to have a close eye on the HTTP traffic when working with web services.</p>

<p>Good luck!</p>]]></content:encoded>
      <pubDate>Mon, 10 Aug 2009 06:43:20 -0400</pubDate>
    </item>
    <item>
      <title><![CDATA[Content with Style - Comment #5 on Unit testing web service based models in Zend Framework]]></title>
      <link>http://www.contentwithstyle.co.uk/content/unit-testing-web-service-based-models-in-zend-framework/#comment-6973</link>
      <guid>http://www.contentwithstyle.co.uk/content/unit-testing-web-service-based-models-in-zend-framework/#comment-6973</guid>
      <description><![CDATA[Some nice examples of mocking techniques for web services. Thanks.]]></description>
      <content:encoded><![CDATA[Some nice examples of mocking techniques for web services. Thanks.]]></content:encoded>
      <pubDate>Thu, 24 Sep 2009 13:34:30 -0400</pubDate>
    </item>
  </channel>
</rss>
