mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2025-12-25 06:49:15 +01:00
Added some tests
This commit is contained in:
80
tests/Feature/APISpeedtestTest.php
Normal file
80
tests/Feature/APISpeedtestTest.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Speedtest;
|
||||
use Faker\Factory;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class APISpeedtestTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* Gets latest speedtest values
|
||||
*
|
||||
* @test
|
||||
* @return void
|
||||
*/
|
||||
public function getLatestSpeedtest()
|
||||
{
|
||||
$faker = Factory::create();
|
||||
|
||||
$ping = [];
|
||||
$dl = [];
|
||||
$ul = [];
|
||||
|
||||
for($i = 0; $i < 3; $i++) {
|
||||
$pingVal = $faker->randomFloat();
|
||||
array_push($ping,$pingVal);
|
||||
$dlVal = $faker->randomFloat();
|
||||
array_push($dl,$dlVal);
|
||||
$ulVal = $faker->randomFloat();
|
||||
array_push($ul,$ulVal);
|
||||
|
||||
Speedtest::create([
|
||||
'ping' => $pingVal,
|
||||
'download' => $dlVal,
|
||||
'upload' => $ulVal,
|
||||
]);
|
||||
}
|
||||
|
||||
$avgVals = Speedtest::select(DB::raw('AVG(ping) as ping, AVG(download) as download, AVG(upload) as upload'))->get()[0];
|
||||
$maxVals = Speedtest::select(DB::raw('MAX(ping) as ping, MAX(download) as download, MAX(upload) as upload'))->get()[0];
|
||||
|
||||
$pingAvg = $avgVals['ping'];
|
||||
$dlAvg = $avgVals['download'];
|
||||
$ulAvg = $avgVals['upload'];
|
||||
$pingMax = $maxVals['ping'];
|
||||
$dlMax = $maxVals['download'];
|
||||
$ulMax = $maxVals['upload'];
|
||||
|
||||
$response = $this->get('/api/speedtest/latest');
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonStructure([
|
||||
'method',
|
||||
'data' => [
|
||||
'id',
|
||||
'ping',
|
||||
'download',
|
||||
'upload',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
],
|
||||
'average' => [
|
||||
'ping',
|
||||
'download',
|
||||
'upload',
|
||||
],
|
||||
'max' => [
|
||||
'ping',
|
||||
'download',
|
||||
'upload',
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -3,16 +3,17 @@
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ExampleTest extends TestCase
|
||||
class BackupTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic test example.
|
||||
* A basic feature test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBasicTest()
|
||||
public function testExample()
|
||||
{
|
||||
$response = $this->get('/');
|
||||
|
||||
28
tests/Feature/SpeedtestTest.php
Normal file
28
tests/Feature/SpeedtestTest.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Helpers\SpeedtestHelper;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SpeedtestTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* Runs a speedtest
|
||||
*
|
||||
* @test
|
||||
* @return void
|
||||
*/
|
||||
public function runSpeedtest()
|
||||
{
|
||||
$data = SpeedtestHelper::runSpeedtest();
|
||||
|
||||
$this->assertArrayHasKey('ping', $data);
|
||||
$this->assertArrayHasKey('download', $data);
|
||||
$this->assertArrayHasKey('upload', $data);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ExampleTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBasicTest()
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user