Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F4793982
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
19 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/omnitools/tests/Collections/WeightedListTest.php b/omnitools/tests/Collections/WeightedListTest.php
index f600887..dc91459 100644
--- a/omnitools/tests/Collections/WeightedListTest.php
+++ b/omnitools/tests/Collections/WeightedListTest.php
@@ -1,87 +1,84 @@
<?php
declare(strict_types=1);
namespace Keruald\OmniTools\Tests\Collections;
use Keruald\OmniTools\Collections\WeightedValue;
use Keruald\OmniTools\Collections\WeightedList;
use PHPUnit\Framework\TestCase;
class WeightedListTest extends TestCase {
- /**
- * @var WeightedList
- */
- private $list;
+ private WeightedList $list;
///
/// Fixtures
///
protected function setUp () : void {
$this->list = new WeightedList;
$this->list->add("LOW", 0.1);
$this->list->add("HIGH", 4);
$this->list->add("AVERAGE");
}
///
/// Tests
///
public function testAdd () : void {
$count = count($this->list);
$this->list->add("ANOTHER");
$this->assertEquals($count + 1, count($this->list));
}
public function testAddWeightedValue () : void {
$count = count($this->list);
$this->list->addWeightedValue(new WeightedValue("ANOTHER"));
$this->assertEquals($count + 1, count($this->list));
}
public function testClear () : void {
$this->list->clear();
$this->assertEquals(0, count($this->list));
}
public function testGetHeaviest () : void {
$this->assertEquals(4, $this->list->getHeaviest()->getWeight());
}
public function testToSortedArray () : void {
$array = $this->list->toSortedArray();
$this->assertEquals(3, count($array));
$this->assertEquals(["HIGH", "AVERAGE", "LOW"], $array);
}
public function testToSortedArrayWithDuplicateValues () : void {
$this->list->add("AVERAGE");
$array = $this->list->toSortedArray();
$this->assertEquals(4, count($array));
$this->assertEquals(["HIGH", "AVERAGE", "AVERAGE", "LOW"], $array);
}
public function testGetIterator () : void {
$count = 0;
foreach ($this->list as $item) {
$this->assertInstanceOf(WeightedValue::class, $item);
$count++;
}
$this->assertEquals(3, $count);
}
public function testCount() : void {
$this->assertEquals(3, $this->list->count());
}
}
diff --git a/omnitools/tests/Collections/WeightedValueTest.php b/omnitools/tests/Collections/WeightedValueTest.php
index 264ebab..3f684b9 100644
--- a/omnitools/tests/Collections/WeightedValueTest.php
+++ b/omnitools/tests/Collections/WeightedValueTest.php
@@ -1,100 +1,94 @@
<?php
declare(strict_types=1);
namespace Keruald\OmniTools\Tests\Collections;
use Keruald\OmniTools\Collections\WeightedValue;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class WeightedValueTest extends TestCase {
- /**
- * @var WeightedValue
- */
- private $lowValue;
-
- /**
- * @var WeightedValue
- */
- private $highValue;
+ private WeightedValue $lowValue;
+
+ private WeightedValue $highValue;
///
/// Fixtures
///
protected function setUp () : void {
$this->lowValue = new WeightedValue("LOW", 0.1);
$this->highValue = new WeightedValue("HIGH");
}
///
/// Tests
///
public function testGetWeight () : void {
$this->assertSame(0.1, $this->lowValue->getWeight());
$this->assertSame(
WeightedValue::DEFAULT_WEIGHT,
$this->highValue->getWeight()
);
}
public function testSetWeight () : void {
$this->lowValue->setWeight(0.2);
$this->assertSame(0.2, $this->lowValue->getWeight());
}
public function testGetValue () : void {
$this->assertEquals("LOW", $this->lowValue->getValue());
$this->assertEquals("HIGH", $this->highValue->getValue());
}
public function testSetValue () : void {
$this->lowValue->setValue("FOO");
$this->assertEquals("FOO", $this->lowValue->getValue());
}
public function testCompareTo () : void {
$this->assertEquals(
0,
$this->lowValue->compareTo($this->lowValue)
);
$this->assertEquals(
-1,
$this->lowValue->compareTo($this->highValue)
);
$this->assertEquals(
1,
$this->highValue->compareTo($this->lowValue)
);
}
public function testCompareToWithApplesAndPears () : void {
$this->expectException("TypeError");
$this->highValue->compareTo(new \stdClass);
}
#[DataProvider('provideExpressionsToParse')]
public function testParse ($expression, $expectedValue, $expectedWeight) : void {
$value = WeightedValue::Parse($expression);
$this->assertEquals($expectedValue, $value->getValue());
$this->assertEquals($expectedWeight, $value->getWeight());
}
///
/// Data providers
///
public static function provideExpressionsToParse () : iterable {
yield ["", "", 1.0];
yield ["de", "de", 1.0];
yield ["de;q=1.0", "de", 1.0];
yield ["de;q=0.7", "de", 0.7];
yield [";;q=0.7", ";", 0.7];
}
}
diff --git a/omnitools/tests/DateTime/DateStampTest.php b/omnitools/tests/DateTime/DateStampTest.php
index 3636e87..273ef4a 100644
--- a/omnitools/tests/DateTime/DateStampTest.php
+++ b/omnitools/tests/DateTime/DateStampTest.php
@@ -1,90 +1,87 @@
<?php
declare(strict_types=1);
namespace Keruald\OmniTools\Tests\DateTime;
use Keruald\OmniTools\DateTime\DateStamp;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use DateTime;
class DateStampTest extends TestCase {
///
/// Private members
///
- /**
- * @var DateStamp
- */
- private $dateStamp;
+ private DateStamp $dateStamp;
///
/// Fixtures
///
protected function setUp () : void {
$this->dateStamp = new DateStamp(2010, 11, 25); // 25 November 2010
}
///
/// Tests
///
public function testToUnixTime () : void {
$this->assertEquals(1290643200, $this->dateStamp->toUnixTime());
}
public function testToDateTime () : void {
$expectedDateTime = new DateTime("2010-11-25");
$this->assertEquals($expectedDateTime, $this->dateStamp->toDateTime());
}
public function testToShortString () : void {
$this->assertEquals("20101125", $this->dateStamp->toShortString());
}
public function testToString () : void {
$this->assertEquals("2010-11-25", (string)$this->dateStamp);
}
public function testFromUnixTime () : void {
$this->assertEquals(
$this->dateStamp,
DateStamp::fromUnixTime(1290643200)
);
}
public function testParse () : void {
$this->assertEquals(
$this->dateStamp,
DateStamp::parse("2010-11-25")
);
$this->assertEquals(
$this->dateStamp,
DateStamp::parse("20101125")
);
}
#[DataProvider('provideInvalidDateStamps')]
public function testParseWithInvalidFormat ($dateStamp) : void {
$this->expectException("InvalidArgumentException");
DateStamp::parse($dateStamp);
}
///
/// Data provider
///
public static function provideInvalidDateStamps () : iterable {
yield ["10-11-25"];
yield ["2010-41-25"];
yield ["2010-11-99"];
yield ["20104125"];
yield ["20101199"];
}
}
diff --git a/omnitools/tests/HTTP/Requests/AcceptedLanguagesTest.php b/omnitools/tests/HTTP/Requests/AcceptedLanguagesTest.php
index d210050..cc5ceec 100644
--- a/omnitools/tests/HTTP/Requests/AcceptedLanguagesTest.php
+++ b/omnitools/tests/HTTP/Requests/AcceptedLanguagesTest.php
@@ -1,47 +1,44 @@
<?php
declare(strict_types=1);
namespace Keruald\OmniTools\Tests\HTTP\Requests;
use Keruald\OmniTools\HTTP\Requests\AcceptedLanguages;
use PHPUnit\Framework\TestCase;
class AcceptedLanguagesTest extends TestCase {
- /**
- * @var AcceptedLanguages
- */
- private $languages;
+ private AcceptedLanguages $languages;
protected function setUp () : void {
$this->languages = new AcceptedLanguages("en-US,en;q=0.9,fr;q=0.8");
}
public function testExtractFromHeaders () : void {
$this->assertEquals("", AcceptedLanguages::extractFromHeaders());
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = "de";
$this->assertEquals("de", AcceptedLanguages::extractFromHeaders());
}
public function testFromServer () : void {
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = "de";
$languages = AcceptedLanguages::fromServer();
$this->assertEquals(["de"], $languages->getLanguageCodes());
}
public function testGetLanguageCodes () : void {
$this->assertEquals(
["en-US", "en", "fr"],
$this->languages->getLanguageCodes()
);
}
public function testGetLanguageCodesWithBlankInformation () : void {
$languages = new AcceptedLanguages;
$this->assertEquals([], $languages->getLanguageCodes());
}
}
diff --git a/omnitools/tests/Network/IPv4RangeTest.php b/omnitools/tests/Network/IPv4RangeTest.php
index ee36916..e00e910 100644
--- a/omnitools/tests/Network/IPv4RangeTest.php
+++ b/omnitools/tests/Network/IPv4RangeTest.php
@@ -1,47 +1,44 @@
<?php
namespace Keruald\OmniTools\Tests\Network;
use Keruald\OmniTools\Network\IPRange;
use PHPUnit\Framework\TestCase;
class IPv4RangeTest extends TestCase {
- /**
- * @var IPRange
- */
- protected $range;
+ protected IPRange $range;
///
/// Fixtures
///
protected function setUp () : void {
$this->range = IPRange::from("216.66.0.0/18");
}
///
/// Tests
///
public function testGetBase () : void {
$this->assertEquals("216.66.0.0", $this->range->getBase());
}
public function testGetNetworkBits () : void {
$this->assertEquals(18, $this->range->getNetworkBits());
}
public function testCount () : void {
$this->assertEquals(14, $this->range->count()); // 14 + 18 = 32 bits
}
public function testGetFirst () : void {
$this->assertEquals("216.66.0.0", $this->range->getFirst());
}
public function testGetLast () : void {
$this->assertEquals("216.66.63.255", $this->range->getLast());
}
}
diff --git a/omnitools/tests/Network/IPv6RangeTest.php b/omnitools/tests/Network/IPv6RangeTest.php
index 86655c8..479ba74 100644
--- a/omnitools/tests/Network/IPv6RangeTest.php
+++ b/omnitools/tests/Network/IPv6RangeTest.php
@@ -1,55 +1,52 @@
<?php
namespace Keruald\OmniTools\Tests\Network;
use Keruald\OmniTools\Network\IPRange;
use PHPUnit\Framework\TestCase;
class IPv6RangeTest extends TestCase {
- /**
- * @var IPRange
- */
- protected $range;
+ protected IPRange $range;
///
/// Fixtures
///
protected function setUp () : void {
$this->range = IPRange::from("2001:400::/23");
}
///
/// Tests
///
public function testGetBase () : void {
$this->assertEquals("2001:400::", $this->range->getBase());
}
public function testGetNetworkBits () : void {
$this->assertEquals(23, $this->range->getNetworkBits());
}
public function testCount () : void {
$this->assertEquals(105, $this->range->count()); // 23 + 105 = 128 bits
}
public function testGetFirst () : void {
$this->assertEquals("2001:400::", $this->range->getFirst());
}
public function testGetLast () : void {
$this->assertEquals("2001:5ff:ffff:ffff:ffff:ffff:ffff:ffff", $this->range->getLast());
}
public function testContains () : void {
$this->assertTrue($this->range->contains("2001:431::af"));
}
public function testContainsWorksWithIPv4MappedIPv6Address () : void {
$this->assertTrue(IPRange::from("::ffff:0.0.0.0/96")->contains("1.2.3.4"));
}
}
diff --git a/omnitools/tests/Reflection/CodeFileTest.php b/omnitools/tests/Reflection/CodeFileTest.php
index e941b87..172ada5 100644
--- a/omnitools/tests/Reflection/CodeFileTest.php
+++ b/omnitools/tests/Reflection/CodeFileTest.php
@@ -1,94 +1,88 @@
<?php
declare(strict_types=1);
namespace Keruald\OmniTools\Tests\Reflection;
use Keruald\OmniTools\OS\CurrentOS;
use Keruald\OmniTools\OS\CurrentProcess;
use Keruald\OmniTools\Reflection\CodeFile;
use Keruald\OmniTools\Tests\WithData;
use PHPUnit\Framework\TestCase;
use Acme\MockLib\Bar; // a mock class in a mock namespace to test include
class CodeFileTest extends TestCase {
use WithData;
- /**
- * @var CodeFile
- */
- private $validCodeFile;
-
- /**
- * @var CodeFile
- */
- private $notExistingCodeFile;
+ private CodeFile $validCodeFile;
+
+ private CodeFile $notExistingCodeFile;
public function setUp () : void {
$file = $this->getDataPath("MockLib/Bar.php");
$this->validCodeFile = CodeFile::from($file);
$this->notExistingCodeFile = CodeFile::from("/notexisting");
}
public function testCanInclude () : void {
$this->assertTrue($this->validCodeFile->canBeIncluded());
$this->assertFalse($this->notExistingCodeFile->canBeIncluded());
}
public function testCanBeIncludedWhenFileModeForbidsReading () : void {
if (CurrentOS::isPureWindows()) {
$this->markTestSkipped("This test is intended for UNIX systems.");
}
if (CurrentProcess::isPrivileged()) {
$this->markTestSkipped(
"This test requires non-root access to run properly."
);
}
$file = $this->getNonReadableFile();
$this->assertFalse(CodeFile::From($file)->canBeIncluded());
unlink($file);
}
public function testTryInclude () : void {
$this->assertTrue($this->validCodeFile->tryInclude());
$this->assertTrue(class_exists(Bar::class));
$this->assertFalse($this->notExistingCodeFile->tryInclude());
}
public function testIsReadable () : void {
$this->assertTrue($this->validCodeFile->isReadable());
}
public function testIsReadableWhenFileModeForbidsReading () : void {
if (CurrentOS::isPureWindows()) {
$this->markTestSkipped("This test is intended for UNIX systems.");
}
if (CurrentProcess::isPrivileged()) {
$this->markTestSkipped(
"This test requires non-root access to run properly."
);
}
$file = $this->getNonReadableFile();
$this->assertFalse(CodeFile::From($file)->isReadable());
unlink($file);
}
private function getNonReadableFile () : string {
$file = tempnam(sys_get_temp_dir(), "testCodeFile");
chmod($file, 0);
return $file;
}
}
diff --git a/omnitools/tests/Strings/Multibyte/OmniStringTest.php b/omnitools/tests/Strings/Multibyte/OmniStringTest.php
index 993fa89..06fadf1 100644
--- a/omnitools/tests/Strings/Multibyte/OmniStringTest.php
+++ b/omnitools/tests/Strings/Multibyte/OmniStringTest.php
@@ -1,119 +1,116 @@
<?php
declare(strict_types=1);
namespace Keruald\OmniTools\Tests\Strings\Multibyte;
use Keruald\OmniTools\Strings\Multibyte\OmniString;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class OmniStringTest extends TestCase {
- /**
- * @var OmniString
- */
- private $string;
+ private OmniString $string;
protected function setUp () : void {
$this->string = new OmniString("foo");
}
public function testToString () : void {
$this->assertEquals("foo", (string)$this->string);
$this->assertEquals("foo", $this->string->__toString());
}
public function testPad () : void {
$paddedString = $this->string->pad(9, '-=-', STR_PAD_BOTH);
$this->assertEquals("-=-foo-=-", $paddedString);
}
public function testStartsWith () : void {
$this->assertTrue($this->string->startsWith("fo"));
$this->assertTrue($this->string->startsWith(""));
$this->assertTrue($this->string->startsWith("foo"));
$this->assertFalse($this->string->startsWith("Fo"));
$this->assertFalse($this->string->startsWith("bar"));
}
public function testEndsWith () : void {
$this->assertTrue($this->string->endsWith("oo"));
$this->assertTrue($this->string->endsWith(""));
$this->assertTrue($this->string->endsWith("foo"));
$this->assertFalse($this->string->endsWith("oO"));
$this->assertFalse($this->string->endsWith("bar"));
}
public function testLen () : void {
$this->assertEquals(3, $this->string->len());
}
#[DataProvider('provideCharactersArrays')]
public function testGetChars (string $string, array $expectedCharacters) : void {
$actualCharacters = (new OmniString($string))->getChars();
$this->assertEquals($expectedCharacters, $actualCharacters);
}
#[DataProvider('provideCharactersBigrams')]
public function testBigrams (string $string, array $expectedBigrams) : void {
$actualBigrams = (new OmniString($string))->getBigrams();
$this->assertEquals($expectedBigrams, $actualBigrams);
}
#[DataProvider('provideExplosions')]
public function testExplode (string $delimiter, string $imploded, array $exploded) : void {
$actual = (new OmniString($imploded))
->explode($delimiter)
->toArray();
$this->assertEquals($exploded, $actual);
}
public function testExplodeWithEmptyOmniArray () : void {
$array = (new OmniString("foo"))
->explode("", -1);
$this->assertEquals(0, count($array->toArray()));
}
///
/// Data providers
///
public static function provideCharactersArrays () : iterable {
yield ["foo", ['f', 'o', 'o']];
yield [
'àèòàFOOàèòà',
['à', 'è', 'ò', 'à', 'F', 'O', 'O', 'à', 'è', 'ò', 'à']
];
yield ["🇩🇪", ["🇩", "🇪"]];
yield ["", []];
}
public static function provideCharactersBigrams () : iterable {
yield ["foo", ['fo', 'oo']];
yield ["night", ['ni', 'ig', 'gh', 'ht']];
yield ["🇩🇪", ["🇩🇪"]];
yield ["", []];
}
public static function provideExplosions () : iterable {
yield ["/", "a/b/c", ['a', 'b', 'c']];
yield ["/", "abc", ['abc']];
yield ["/", "/b/c", ['', 'b', 'c']];
yield ["/", "a/b/", ['a', 'b', '']];
yield ["", "a/b/c", ['a/b/c']];
yield ["x", "a/b/c", ['a/b/c']];
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Fri, Feb 28, 22:57 (23 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2448034
Default Alt Text
(19 KB)
Attached To
Mode
rKERUALD Keruald libraries development repository
Attached
Detach File
Event Timeline
Log In to Comment