66
77class ApiTest extends \PHPUnit_Framework_TestCase
88{
9+ private $ className = 'Swader\Diffbot\Abstracts\Api ' ;
10+ private $ testUrl = 'http://diffbot.com ' ;
11+
912 /**
1013 * @return \PHPUnit_Framework_MockObject_MockObject
1114 */
1215 private function buildMock ()
1316 {
14- return $ this ->getMockForAbstractClass (' Swader\Diffbot\Abstracts\Api ' );
17+ return $ this ->getMockForAbstractClass ($ this -> className , [ $ this -> testUrl ] );
1518 }
1619
1720 public function testSetTimeout ()
@@ -61,4 +64,56 @@ public function testSetTimeout()
6164 $ this ->fail ('Failed, assumed invalid parameter was valid. ' );
6265 }
6366 }
67+
68+ public function testConstructor ()
69+ {
70+ $ validUrls = [
71+ 'http://google.com ' ,
72+ 'http://gigaom.com/cloud/silicon-valley-royalty-pony-up-2m-to-scale-diffbots-visual-learning-robot/ ' ,
73+ <<<'TAG'
74+ http://techcrunch.com/2012/05/31/diffbot-raises-2-million-seed-round-for-web-content-extraction-technology/
75+ TAG
76+ ,
77+ 'http://www.theverge.com/2012/5/31/3054444/diffbot-raises-2-million-apps-open-web ' ,
78+ 'http://venturebeat.com/2012/08/16/diffbot-api-links ' ,
79+ 'http://www.wired.co.uk/news/archive/2012-06/01/diffbot ' ,
80+ 'http://www.amazon.com/Oh-The-Places-Youll-Go/dp/0679805273/ ' ,
81+ 'http://us.levi.com/product/index.jsp?productId=2076855 ' ,
82+ <<<'TAG'
83+ http://www.petsmart.com/dog/grooming-supplies/grreat-choice-soft-slicker-dog-brush-zid36-12094/cat-36-catid-100016
84+ TAG
85+ ,
86+ 'http://instagram.com/p/t879OvgvqS/ ' ,
87+ 'http://smittenkitchen.com/blog/2012/01/buckwheat-baby-with-salted-caramel-syrup/ ' ,
88+ 'https://twitter.com/NASA/status/525397368116895744 ' ,
89+ 'www.example.com ' ,
90+ 'example.com '
91+ ];
92+
93+ $ invalidUrls = [
94+ false ,
95+ null ,
96+ 12345 ,
97+ 'abc ' ,
98+ '35tugz---sdf----?//*****/*//* '
99+ ];
100+
101+ foreach ($ validUrls as $ i => $ url ) {
102+ try {
103+ $ this ->getMockForAbstractClass ($ this ->className , [$ url ]);
104+ } catch (\InvalidArgumentException $ e ) {
105+ $ this ->fail ('Failed with supposedly valid URL: ' . $ url . ' at index ' . $ i );
106+ }
107+ }
108+
109+ foreach ($ invalidUrls as $ i => $ url ) {
110+ try {
111+ $ this ->getMockForAbstractClass ($ this ->className , [$ url ]);
112+ } catch (\InvalidArgumentException $ e ) {
113+ continue ;
114+ }
115+ $ this ->fail ('Did not fail with invalid URL at index ' . $ i );
116+ }
117+
118+ }
64119}
0 commit comments