@@ -1357,19 +1357,14 @@ public function testGetInstagramStoryInsights()
1357
1357
1358
1358
$ facebook = new Facebook ();
1359
1359
1360
- $ responseMock = m::mock ('\Facebook\FacebookResponse ' )
1361
- ->shouldReceive ('isError ' )
1362
- ->once ()
1363
- ->andReturn (false )
1364
- ->shouldReceive ('getDecodedBody ' )
1365
- ->once ()
1366
- ->andReturn ($ decodedInsightsResponseData )
1367
- ->getMock ();
1360
+ $ responseMock = m::mock ('\Facebook\FacebookResponse ' );
1361
+ $ responseMock ->shouldReceive ('isError ' )->once ()->andReturn (false );
1362
+ $ responseMock ->shouldReceive ('getDecodedBody ' )->once ()->andReturn ($ decodedInsightsResponseData );
1363
+
1368
1364
$ facebookMock = m::mock ('\Facebook\Facebook ' );
1369
- $ facebookMock
1370
- ->shouldReceive ('sendRequest ' )
1365
+ $ facebookMock ->shouldReceive ('sendRequest ' )
1371
1366
->once ()
1372
- ->with ('GET ' , " / $ { mediaId} /insights " , ["metric " => $ metrics ])
1367
+ ->with ('GET ' , ' / ' . $ mediaId . ' /insights ' , ["metric " => $ metrics ])
1373
1368
->andReturn ($ responseMock );
1374
1369
$ facebook ->setFacebookLibrary ($ facebookMock );
1375
1370
@@ -1400,7 +1395,7 @@ public function testGetInstagramStoryInsightsNullIfError()
1400
1395
$ facebookMock
1401
1396
->shouldReceive ('sendRequest ' )
1402
1397
->once ()
1403
- ->with ('GET ' , " / $ { mediaId} /insights " , ["metric " => $ metrics ])
1398
+ ->with ('GET ' , ' / ' . $ mediaId . ' /insights ' , ["metric " => $ metrics ])
1404
1399
->andReturn ($ responseMock );
1405
1400
$ facebook ->setFacebookLibrary ($ facebookMock );
1406
1401
@@ -1429,7 +1424,7 @@ public function testGetInstagramStoryNavigationInsightsNullIfError()
1429
1424
$ facebookMock
1430
1425
->shouldReceive ('sendRequest ' )
1431
1426
->once ()
1432
- ->with ('GET ' , " / $ { mediaId} /insights " , $ params )
1427
+ ->with ('GET ' , ' / ' . $ mediaId . ' /insights ' , $ params )
1433
1428
->andReturn ($ responseMock );
1434
1429
$ facebook ->setFacebookLibrary ($ facebookMock );
1435
1430
@@ -1493,7 +1488,7 @@ public function testGetInstagramStoryNavigationInsightsReturnsData()
1493
1488
$ facebookMock
1494
1489
->shouldReceive ('sendRequest ' )
1495
1490
->once ()
1496
- ->with ('GET ' , " / $ { mediaId} /insights " , $ params )
1491
+ ->with ('GET ' , ' / ' . $ mediaId . ' /insights ' , $ params )
1497
1492
->andReturn ($ responseMock );
1498
1493
$ facebook ->setFacebookLibrary ($ facebookMock );
1499
1494
@@ -1526,7 +1521,7 @@ public function testGetInstagramStoryNavigationInsightsEmptyResponse()
1526
1521
$ facebookMock
1527
1522
->shouldReceive ('sendRequest ' )
1528
1523
->once ()
1529
- ->with ('GET ' , " / $ { mediaId} /insights " , $ params )
1524
+ ->with ('GET ' , ' / ' . $ mediaId . ' /insights ' , $ params )
1530
1525
->andReturn ($ responseMock );
1531
1526
$ facebook ->setFacebookLibrary ($ facebookMock );
1532
1527
@@ -1664,4 +1659,54 @@ public function testGetTokenScopes()
1664
1659
1665
1660
$ this ->assertEquals (['email ' , 'public_profile ' ], $ response ['data ' ]['scopes ' ]);
1666
1661
}
1662
+
1663
+ public function testGetInstagramStoryInsightsWithMetricType ()
1664
+ {
1665
+ $ mediaId = "123456789 " ;
1666
+ $ decodedInsightsResponseData = [
1667
+ 'data ' => [
1668
+ [
1669
+ 'name ' => 'reach ' ,
1670
+ 'period ' => 'lifetime ' ,
1671
+ 'values ' => [
1672
+ [
1673
+ 'value ' => 123 ,
1674
+ ],
1675
+ ],
1676
+ ],
1677
+ [
1678
+ 'name ' => 'views ' ,
1679
+ 'period ' => 'lifetime ' ,
1680
+ 'values ' => [
1681
+ [
1682
+ 'value ' => 500 ,
1683
+ ],
1684
+ ],
1685
+ ],
1686
+ ]
1687
+ ];
1688
+
1689
+ $ metricsArray = ['reach ' , 'views ' ];
1690
+ $ metrics = join (", " , $ metricsArray );
1691
+
1692
+ $ facebook = new Facebook ();
1693
+
1694
+ $ responseMock = m::mock ('\Facebook\FacebookResponse ' );
1695
+ $ responseMock ->shouldReceive ('isError ' )->once ()->andReturn (false );
1696
+ $ responseMock ->shouldReceive ('getDecodedBody ' )->once ()->andReturn ($ decodedInsightsResponseData );
1697
+
1698
+ $ facebookMock = m::mock ('\Facebook\Facebook ' );
1699
+ $ facebookMock ->shouldReceive ('sendRequest ' )
1700
+ ->once ()
1701
+ ->with ('GET ' , '/ ' . $ mediaId . '/insights ' , ["metric " => $ metrics , "metric_type " => "total_values " ])
1702
+ ->andReturn ($ responseMock );
1703
+ $ facebook ->setFacebookLibrary ($ facebookMock );
1704
+
1705
+ $ response = $ facebook ->getInstagramStoryInsights ($ mediaId , $ metricsArray , "total_values " );
1706
+
1707
+ $ this ->assertEquals ($ response , [
1708
+ 'reach ' => 123 ,
1709
+ 'views ' => 500
1710
+ ]);
1711
+ }
1667
1712
}
0 commit comments