1
0
mirror of https://github.com/Kovah/LinkAce.git synced 2025-03-15 04:09:39 +01:00

Add a new test for the update check ()

This commit is contained in:
Kovah 2020-03-04 15:02:15 +01:00
parent 54226a5eca
commit efd6dbd720
No known key found for this signature in database
GPG Key ID: AAAA031BA9830D7B

@ -0,0 +1,72 @@
<?php
namespace Tests\Unit\Helper;
use App\Helper\UpdateHelper;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
/**
* Class UpdateCheckTest
*
* @package Tests\Unit\Helper
*/
class UpdateCheckTest extends TestCase
{
/**
* Test the checkForUpdates() helper function with a new update available.
* Must return the given version string.
*
* @return void
*/
public function testSuccessfulCheck(): void
{
Http::fake([
'github.com/*' => Http::response(
[['tag_name' => 'v100.0.0']],
200
),
]);
$result = UpdateHelper::checkForUpdates();
$this->assertEquals('v100.0.0', $result);
}
/**
* Test the checkForUpdates() helper function with no update available.
* Must return true.
*
* @return void
*/
public function testSuccessfulCheckWithoutVersion(): void
{
Http::fake([
'github.com/*' => Http::response(
[['tag_name' => 'v0.0.0']],
200
),
]);
$result = UpdateHelper::checkForUpdates();
$this->assertTrue($result);
}
/**
* Test the checkForUpdates() helper function, but trigger a network / http error.
* Must return false.
*
* @return void
*/
public function testValidWaybackLink(): void
{
Http::fake([
'github.com/*' => Http::response([], 404),
]);
$result = UpdateHelper::checkForUpdates();
$this->assertFalse($result);
}
}