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
1414 */
1515 public static $ shopify ;
1616
17+ public static $ microtimeOfLastAPICall ;
18+
1719 /**
18- * Initial setup for the tests to run
20+ * @inheritDoc
1921 */
2022 public static function setUpBeforeClass ()
2123 {
@@ -28,8 +30,34 @@ public static function setUpBeforeClass()
2830 self ::$ shopify = ShopifySDK::config ($ config );
2931 }
3032
33+ /**
34+ * @inheritDoc
35+ */
3136 public static function tearDownAfterClass ()
3237 {
3338 self ::$ shopify = null ;
3439 }
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+ }
3563}
You can’t perform that action at this time.
0 commit comments