File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -14,8 +14,10 @@ class TestResource extends \PHPUnit_Framework_TestCase
14
14
*/
15
15
public static $ shopify ;
16
16
17
+ public static $ microtimeOfLastAPICall ;
18
+
17
19
/**
18
- * Initial setup for the tests to run
20
+ * @inheritDoc
19
21
*/
20
22
public static function setUpBeforeClass ()
21
23
{
@@ -28,8 +30,34 @@ public static function setUpBeforeClass()
28
30
self ::$ shopify = ShopifySDK::config ($ config );
29
31
}
30
32
33
+ /**
34
+ * @inheritDoc
35
+ */
31
36
public static function tearDownAfterClass ()
32
37
{
33
38
self ::$ shopify = null ;
34
39
}
40
+
41
+ /**
42
+ * @inheritDoc
43
+ */
44
+ public function setUp ()
45
+ {
46
+ if (static ::$ microtimeOfLastAPICall == null ) {
47
+ //Maintain 2 seconds per call
48
+ usleep (500000 );
49
+ } else {
50
+ $ now = microtime (true );
51
+ $ timeSinceLastCall = $ now - static ::$ microtimeOfLastAPICall ;
52
+ //Ensure 2 API calls per second
53
+ if ($ timeSinceLastCall < .5 ) {
54
+ $ timeToWait = .5 - $ timeSinceLastCall ;
55
+ //convert time to microseconds
56
+ $ microSecondsToWait = $ timeToWait * 1000000 ;
57
+ //Wait to maintain the API call difference of .5 seconds
58
+ usleep ($ microSecondsToWait );
59
+ }
60
+ }
61
+ static ::$ microtimeOfLastAPICall = microtime (true );
62
+ }
35
63
}
You can’t perform that action at this time.
0 commit comments