3
3
namespace DayRev \Smmry \Tests \Unit ;
4
4
5
5
use DayRev \Smmry \SDK ;
6
+ use ReflectionMethod ;
7
+ use stdClass ;
6
8
7
9
class SDKTest extends \PHPUnit_Framework_TestCase
8
10
{
@@ -21,4 +23,36 @@ public function testContainsDynamicProperties()
21
23
$ this ->assertObjectHasAttribute ('summary_length ' , $ this ->sdk );
22
24
$ this ->assertAttributeEquals (5 , 'summary_length ' , $ this ->sdk );
23
25
}
26
+
27
+ public function testCleanSummary ()
28
+ {
29
+ $ summary = new stdClass ();
30
+ $ summary ->sm_api_title = ' Greeting ' ;
31
+ $ summary ->sm_api_content = ' Hello, how are you? ' ;
32
+ $ summary ->sm_api_img_url = ' http://smmry.com/sm_images/sm_logo.png ' ;
33
+
34
+ $ summary = $ this ->invokeProtectedSdkMethod ('cleanSummary ' , [$ summary ]);
35
+
36
+ $ this ->assertEquals ('Greeting ' , $ summary ->sm_api_title );
37
+ $ this ->assertEquals ('Hello, how are you? ' , $ summary ->sm_api_content );
38
+ $ this ->assertEquals (' http://smmry.com/sm_images/sm_logo.png ' , $ summary ->sm_api_img_url );
39
+ }
40
+
41
+ public function testBuildUrl ()
42
+ {
43
+ $ url = $ this ->invokeProtectedSdkMethod ('buildUrl ' , [['SM_QUOTE_AVOID ' => 1 ]]);
44
+
45
+ $ this ->assertEquals (
46
+ 'http://api.smmry.com?SM_API_KEY=D74KLJ345UH9SHDF1&SM_LENGTH=5&SM_QUOTE_AVOID=1 ' ,
47
+ $ url
48
+ );
49
+ }
50
+
51
+ protected function invokeProtectedSdkMethod (string $ method , array $ args = [])
52
+ {
53
+ $ reflection = new ReflectionMethod (get_class ($ this ->sdk ), $ method );
54
+ $ reflection ->setAccessible (true );
55
+
56
+ return $ reflection ->invokeArgs ($ this ->sdk , $ args );
57
+ }
24
58
}
0 commit comments