Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Unit/UtilsTest.php
<?php | <?php | ||||
namespace Tests\Unit; | namespace Tests\Unit; | ||||
use App\Utils; | use App\Utils; | ||||
use Tests\TestCase; | use Tests\TestCase; | ||||
class UtilsTest extends TestCase | class UtilsTest extends TestCase | ||||
{ | { | ||||
/** | /** | ||||
* Test for Utils::powerSet() | * Test for Utils::powerSet() | ||||
* | |||||
* @return void | |||||
*/ | */ | ||||
public function testPowerSet() | public function testPowerSet(): void | ||||
{ | { | ||||
$set = []; | $set = []; | ||||
$result = \App\Utils::powerSet($set); | $result = \App\Utils::powerSet($set); | ||||
$this->assertIsArray($result); | $this->assertIsArray($result); | ||||
$this->assertCount(0, $result); | $this->assertCount(0, $result); | ||||
Show All 26 Lines | public function testPowerSet(): void | ||||
$this->assertTrue(in_array(["a3"], $result)); | $this->assertTrue(in_array(["a3"], $result)); | ||||
$this->assertTrue(in_array(["a1", "a2"], $result)); | $this->assertTrue(in_array(["a1", "a2"], $result)); | ||||
$this->assertTrue(in_array(["a1", "a3"], $result)); | $this->assertTrue(in_array(["a1", "a3"], $result)); | ||||
$this->assertTrue(in_array(["a2", "a3"], $result)); | $this->assertTrue(in_array(["a2", "a3"], $result)); | ||||
$this->assertTrue(in_array(["a1", "a2", "a3"], $result)); | $this->assertTrue(in_array(["a1", "a2", "a3"], $result)); | ||||
} | } | ||||
/** | /** | ||||
* Test for Utils::serviceUrl() | |||||
*/ | |||||
public function testServiceUrl(): void | |||||
{ | |||||
$public_href = 'https://public.url/cockpit'; | |||||
$local_href = 'https://local.url/cockpit'; | |||||
\config([ | |||||
'app.url' => $local_href, | |||||
'app.public_url' => '', | |||||
]); | |||||
$this->assertSame($local_href, Utils::serviceUrl('')); | |||||
$this->assertSame($local_href . '/unknown', Utils::serviceUrl('unknown')); | |||||
$this->assertSame($local_href . '/unknown', Utils::serviceUrl('/unknown')); | |||||
\config([ | |||||
'app.url' => $local_href, | |||||
'app.public_url' => $public_href, | |||||
]); | |||||
$this->assertSame($public_href, Utils::serviceUrl('')); | |||||
$this->assertSame($public_href . '/unknown', Utils::serviceUrl('unknown')); | |||||
$this->assertSame($public_href . '/unknown', Utils::serviceUrl('/unknown')); | |||||
} | |||||
/** | |||||
* Test for Utils::uuidInt() | * Test for Utils::uuidInt() | ||||
* | |||||
* @return void | |||||
*/ | */ | ||||
public function testUuidInt() | public function testUuidInt(): void | ||||
{ | { | ||||
$result = Utils::uuidInt(); | $result = Utils::uuidInt(); | ||||
$this->assertTrue(is_int($result)); | $this->assertTrue(is_int($result)); | ||||
$this->assertTrue($result > 0); | $this->assertTrue($result > 0); | ||||
} | } | ||||
/** | /** | ||||
* Test for Utils::uuidStr() | * Test for Utils::uuidStr() | ||||
* | |||||
* @return void | |||||
*/ | */ | ||||
public function testUuidStr() | public function testUuidStr(): void | ||||
{ | { | ||||
$result = Utils::uuidStr(); | $result = Utils::uuidStr(); | ||||
$this->assertTrue(is_string($result)); | $this->assertTrue(is_string($result)); | ||||
$this->assertTrue(strlen($result) === 36); | $this->assertTrue(strlen($result) === 36); | ||||
$this->assertTrue(preg_match('/[^a-f0-9-]/i', $result) === 0); | $this->assertTrue(preg_match('/[^a-f0-9-]/i', $result) === 0); | ||||
} | } | ||||
} | } |