Skip to content

Commit

Permalink
test: test all camel case conversion
Browse files Browse the repository at this point in the history
fixes #448
  • Loading branch information
g105b committed Nov 30, 2023
1 parent 80043fd commit 32e2769
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion test/phpunit/DOMStringMapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testGetterSetter():void {
self::assertSame($keyValuePairs["example"], $sut->example);
}

public function testGetterCamelCaseConversion():void {
public function testGetter_fromCamelCase():void {
$keyValuePairs = [
"this-is-camel-case" => uniqid("example-"),
];
Expand All @@ -34,6 +34,44 @@ public function testGetterCamelCaseConversion():void {
self::assertSame($keyValuePairs["this-is-camel-case"], $sut->thisIsCamelCase);
}

public function testGetter_fromHyphenated():void {
$keyValuePairs = [
"this-is-camel-case" => uniqid("example-"),
];
$getter = function() use (&$keyValuePairs) {
return $keyValuePairs;
};
$setter = function(array $kvp) use (&$keyValuePairs) {
$keyValuePairs = $kvp;
};
$sut = new DOMStringMap($getter, $setter);

self::assertSame($keyValuePairs["this-is-camel-case"], $sut->get("this-is-camel-case"));
self::assertSame($keyValuePairs["this-is-camel-case"], $sut->get("thisIsCamelCase"));
self::assertArrayNotHasKey("thisIsCamelCase", $keyValuePairs);
}

public function testSetter_fromHyphenated():void {
$keyValuePairs = [
"this-is-camel-case" => uniqid("example-"),
];
$getter = function() use (&$keyValuePairs) {
return $keyValuePairs;
};
$setter = function(array $kvp) use (&$keyValuePairs) {
$keyValuePairs = $kvp;
};
$sut = new DOMStringMap($getter, $setter);

$sut->set("this-is-camel-case", "update1");
$sut->set("thisIsCamelCase", "update2");
$sut->set("other-key", "other-update");

self::assertCount(2, $keyValuePairs);
self::assertSame("update2", $sut->thisIsCamelCase);
self::assertSame("other-update", $sut->otherKey);
}

public function testSetterCamelCaseConversion():void {
$keyValuePairs = [];
$getter = function() use (&$keyValuePairs) {
Expand Down

0 comments on commit 32e2769

Please sign in to comment.