-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#16 added tests; moved worker call to separate file for testing
- Loading branch information
1 parent
2d0d277
commit f7be805
Showing
5 changed files
with
108 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Exception; | ||
|
||
require_once "ShowPulseWorker.php"; | ||
|
||
$worker = new ShowPulseWorker(); | ||
while (true) { | ||
try { | ||
$worker->getWebsiteApiKey(); | ||
$worker->getFppStatus(); | ||
$worker->postShowStatus(); | ||
$worker->getNextRequest(); | ||
$sleepTime = $worker->calculateSleepTime(); | ||
sleep($sleepTime); | ||
$worker->resetAttemptCount(); | ||
} catch (Exception $e) { | ||
$worker->logError($e->getMessage()); | ||
$sleepTime = $worker->exponentialBackoffSleep(); | ||
$worker->increaseAttemptCount(); | ||
sleep($sleepTime); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace App\Test; | ||
|
||
use App\ShowPulseWorker; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @covers ShowPulseWorker | ||
*/ | ||
final class ShowPulseWorkerTest extends TestCase | ||
{ | ||
public function testResetAttemptCount() | ||
{ | ||
$worker = new ShowPulseWorker(); | ||
$worker->resetAttemptCount(); | ||
|
||
$this->assertEquals(0, $worker->getAttemptCount()); | ||
} | ||
|
||
public function testIncreaseAttemptCountTwoTimes() | ||
{ | ||
$worker = new ShowPulseWorker(); | ||
$worker->increaseAttemptCount(); | ||
$worker->increaseAttemptCount(); | ||
|
||
$this->assertEquals(2, $worker->getAttemptCount()); | ||
} | ||
|
||
public function testIncreaseAttemptCountSixTimes() | ||
{ | ||
$worker = new ShowPulseWorker(); | ||
$worker->increaseAttemptCount(); | ||
$worker->increaseAttemptCount(); | ||
$worker->increaseAttemptCount(); | ||
$worker->increaseAttemptCount(); | ||
$worker->increaseAttemptCount(); | ||
$worker->increaseAttemptCount(); | ||
|
||
$this->assertEquals(5, $worker->getAttemptCount()); | ||
} | ||
|
||
public function testSleepShortValue() | ||
{ | ||
$worker = new ShowPulseWorker(); | ||
|
||
$this->assertEquals(5, $worker->sleepShortValue()); | ||
} | ||
|
||
public function testSleepLongValue() | ||
{ | ||
$worker = new ShowPulseWorker(); | ||
|
||
$this->assertEquals(30, $worker->sleepLongValue()); | ||
} | ||
|
||
public function testCalculateSleepTime() | ||
{ | ||
$worker = new ShowPulseWorker(); | ||
|
||
$sleepTime = $worker->calculateSleepTime(); | ||
|
||
$this->assertEquals(5, $sleepTime); | ||
} | ||
} |