mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2025-12-21 21:33:08 +01:00
Fix some tests
This commit is contained in:
@@ -23,7 +23,7 @@ class OoklaTester implements SpeedtestProvider
|
|||||||
try {
|
try {
|
||||||
$output = json_decode($output, true, 512, JSON_THROW_ON_ERROR);
|
$output = json_decode($output, true, 512, JSON_THROW_ON_ERROR);
|
||||||
|
|
||||||
if (!$this->isOutputIsComplete($output)) {
|
if (!$this->isOutputComplete($output)) {
|
||||||
$test = false;
|
$test = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ class OoklaTester implements SpeedtestProvider
|
|||||||
'scheduled' => $scheduled,
|
'scheduled' => $scheduled,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
throw new SpeedtestFailureException($output);
|
throw new SpeedtestFailureException((string)$output);
|
||||||
}
|
}
|
||||||
|
|
||||||
Cache::flush();
|
Cache::flush();
|
||||||
@@ -90,7 +90,7 @@ class OoklaTester implements SpeedtestProvider
|
|||||||
* @param array $output
|
* @param array $output
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
private static function isOutputIsComplete($output)
|
public static function isOutputComplete($output)
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Array of indexes that must exist in $output
|
* Array of indexes that must exist in $output
|
||||||
|
|||||||
1
database/.gitignore
vendored
1
database/.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
*.sqlite
|
*.sqlite
|
||||||
*.sqlite-journal
|
*.sqlite-journal
|
||||||
*.bak
|
*.bak
|
||||||
|
*.db_test*
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
<server name="BCRYPT_ROUNDS" value="4"/>
|
<server name="BCRYPT_ROUNDS" value="4"/>
|
||||||
<server name="CACHE_DRIVER" value="array"/>
|
<server name="CACHE_DRIVER" value="array"/>
|
||||||
<server name="DB_CONNECTION" value="sqlite"/>
|
<server name="DB_CONNECTION" value="sqlite"/>
|
||||||
<server name="DB_DATABASE" value=":memory:"/>
|
<!-- <server name="DB_DATABASE" value=":memory:"/> -->
|
||||||
<server name="MAIL_MAILER" value="array"/>
|
<server name="MAIL_MAILER" value="array"/>
|
||||||
<server name="QUEUE_CONNECTION" value="sync"/>
|
<server name="QUEUE_CONNECTION" value="sync"/>
|
||||||
<server name="SESSION_DRIVER" value="array"/>
|
<server name="SESSION_DRIVER" value="array"/>
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ class APISpeedtestTest extends TestCase
|
|||||||
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
$response->assertJsonStructure([
|
$response->assertJsonStructure([
|
||||||
'method',
|
|
||||||
'data' => [
|
'data' => [
|
||||||
'id',
|
'id',
|
||||||
'ping',
|
'ping',
|
||||||
|
|||||||
@@ -2,11 +2,18 @@
|
|||||||
|
|
||||||
namespace Tests\Unit\Helpers\SpeedtestHelper;
|
namespace Tests\Unit\Helpers\SpeedtestHelper;
|
||||||
|
|
||||||
use App\Helpers\SpeedtestHelper;
|
use App\Utils\OoklaTester;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class CheckOutputTest extends TestCase
|
class CheckOutputTest extends TestCase
|
||||||
{
|
{
|
||||||
|
private OoklaTester $speedtestProvider;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->speedtestProvider = new OoklaTester();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A basic unit test example.
|
* A basic unit test example.
|
||||||
*
|
*
|
||||||
@@ -16,9 +23,9 @@ class CheckOutputTest extends TestCase
|
|||||||
{
|
{
|
||||||
$expected = [
|
$expected = [
|
||||||
'type' => 'result',
|
'type' => 'result',
|
||||||
'download' => [ 'bandwidth' => '*' ],
|
'download' => ['bandwidth' => '*'],
|
||||||
'upload' => [ 'bandwidth' => '*' ],
|
'upload' => ['bandwidth' => '*'],
|
||||||
'ping' => [ 'latency' => '*' ],
|
'ping' => ['latency' => '*'],
|
||||||
'server' => [
|
'server' => [
|
||||||
'id' => '*',
|
'id' => '*',
|
||||||
'name' => '*',
|
'name' => '*',
|
||||||
@@ -30,7 +37,7 @@ class CheckOutputTest extends TestCase
|
|||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->assertTrue(SpeedtestHelper::checkOutputIsComplete($expected));
|
$this->assertTrue($this->speedtestProvider->isOutputComplete($expected));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,7 +49,7 @@ class CheckOutputTest extends TestCase
|
|||||||
{
|
{
|
||||||
$expected = [
|
$expected = [
|
||||||
'type' => 'result',
|
'type' => 'result',
|
||||||
'download' => [ 'bandwidth' => '*' ],
|
'download' => ['bandwidth' => '*'],
|
||||||
'server' => [
|
'server' => [
|
||||||
'id' => '*',
|
'id' => '*',
|
||||||
'name' => '*',
|
'name' => '*',
|
||||||
@@ -54,6 +61,6 @@ class CheckOutputTest extends TestCase
|
|||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->assertFalse(SpeedtestHelper::checkOutputIsComplete($expected));
|
$this->assertFalse($this->speedtestProvider->isOutputComplete($expected));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace Tests\Unit\Helpers\SpeedtestHelper;
|
namespace Tests\Unit\Helpers\SpeedtestHelper;
|
||||||
|
|
||||||
use App\Helpers\SpeedtestHelper;
|
use App\Helpers\SpeedtestHelper;
|
||||||
|
use App\Utils\OoklaTester;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use JsonException;
|
use JsonException;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
@@ -13,11 +14,15 @@ class SpeedtestTest extends TestCase
|
|||||||
|
|
||||||
private $output;
|
private $output;
|
||||||
|
|
||||||
public function setUp() : void
|
private OoklaTester $speedtestProvider;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->output = SpeedtestHelper::output();
|
$this->speedtestProvider = new OoklaTester();
|
||||||
|
|
||||||
|
$this->output = $this->speedtestProvider->output();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,7 +44,7 @@ class SpeedtestTest extends TestCase
|
|||||||
{
|
{
|
||||||
$output = json_decode($this->output, true);
|
$output = json_decode($this->output, true);
|
||||||
|
|
||||||
$test = SpeedtestHelper::runSpeedtest($this->output);
|
$test = $this->speedtestProvider->run($this->output);
|
||||||
|
|
||||||
$this->assertEquals($output['ping']['latency'], $test->ping);
|
$this->assertEquals($output['ping']['latency'], $test->ping);
|
||||||
$this->assertEquals(SpeedtestHelper::convert($output['download']['bandwidth']), $test->download);
|
$this->assertEquals(SpeedtestHelper::convert($output['download']['bandwidth']), $test->download);
|
||||||
@@ -55,7 +60,7 @@ class SpeedtestTest extends TestCase
|
|||||||
{
|
{
|
||||||
$json = '{hi: hi}';
|
$json = '{hi: hi}';
|
||||||
|
|
||||||
$o = SpeedtestHelper::runSpeedtest($json);
|
$o = $this->speedtestProvider->run($json);
|
||||||
|
|
||||||
$this->assertFalse($o);
|
$this->assertFalse($o);
|
||||||
}
|
}
|
||||||
@@ -69,7 +74,7 @@ class SpeedtestTest extends TestCase
|
|||||||
{
|
{
|
||||||
$json = '{"hi": "hi"}';
|
$json = '{"hi": "hi"}';
|
||||||
|
|
||||||
$o = SpeedtestHelper::runSpeedtest($json);
|
$o = $this->speedtestProvider->run($json);
|
||||||
|
|
||||||
$this->assertFalse($o);
|
$this->assertFalse($o);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user