Skip to content

Commit

Permalink
update kirby dependency to 4.1.x adjust tests, remove __invoke() ma…
Browse files Browse the repository at this point in the history
…gic method
  • Loading branch information
fabianmichael committed Mar 17, 2024
1 parent eefdfb9 commit 1b8bbd4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 46 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"phpunit/phpunit": "^9",
"phpmd/phpmd" : "@stable",
"vimeo/psalm": "^5.1",
"getkirby/cms": "^4.0.0",
"getkirby/cms": "^4.1.0",
"squizlabs/php_codesniffer": "^3.9"
},
"require": {
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,6 @@ public function __call(string $name, array $arguments): self
return $this->set($name, ...$arguments);
}

public function __invoke(...$data): static
{
return $this->merge(...$data);
}

public function toHtml(): string|null
{
return Html::attr(
Expand Down
70 changes: 31 additions & 39 deletions tests/AttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function testConstructorArray(): void
'bar' => 'foo'
]);

$this->assertSame((string)$attr, 'bar="foo" foo="bar"');
$this->assertSame((string) $attr, 'bar="foo" foo="bar"');
}

public function testConstrucorNamedArguments(): void
Expand All @@ -26,7 +26,7 @@ public function testConstrucorNamedArguments(): void
bar: 'foo',
);

$this->assertSame((string)$attr, 'bar="foo" foo="bar"');
$this->assertSame((string) $attr, 'bar="foo" foo="bar"');
}

public function testConversionToLowerCase(): void
Expand All @@ -35,17 +35,17 @@ public function testConversionToLowerCase(): void
fooBar: 'baz',
);

$this->assertSame((string)$attr, 'foobar="baz"');
$this->assertSame((string) $attr, 'foobar="baz"');
}

public function testToHtml(): void
{
$attr = new Attributes([
'standalone',
'fooBar' => 'baz',
'standalone'
]);

$this->assertSame($attr->toHtml(), 'foobar="baz" standalone');
$this->assertSame($attr->toHtml(), 'standalone foobar="baz"');
}

public function testEmptyInputArray(): void
Expand All @@ -54,27 +54,27 @@ public function testEmptyInputArray(): void

$this->assertSame($attr->toHtml(), null);
$this->assertSame($attr->toXml(), null);
$this->assertSame((string)$attr, '');
$this->assertSame((string) $attr, '');
}

public function testEmptyAttributes(): void
{
$attr = new Attributes(['foo' => '']);
$this->assertSame((string)$attr, 'foo=""');
$this->assertSame((string)$attr->toXml(), 'foo=""');
$this->assertSame((string) $attr, 'foo=""');
$this->assertSame((string) $attr->toXml(), 'foo=""');

$attr = new Attributes(['foo']);
$this->assertSame((string)$attr, 'foo');
$this->assertSame((string)$attr->toXml(), 'foo="foo"');
$this->assertSame((string) $attr, 'foo');
$this->assertSame((string) $attr->toXml(), 'foo="foo"');

$attr = new Attributes(['foo' => null, 'bar' => false]);
$this->assertSame((string)$attr, '');
$this->assertSame((string) $attr, '');
}

public function testSingleSpaceAttribute(): void
{
// should trigger e deprecated error
@(string)(new Attributes(['foo' => ' ']));
@(string) (new Attributes(['foo' => ' ']));
$this->assertTrue(error_get_last() !== null);
}

Expand All @@ -85,35 +85,35 @@ public function testToXml(): void
'standalone'
]);

$this->assertSame($attr->toXml(), 'fooBar="baz" standalone="standalone"');
$this->assertSame($attr->toXml(), 'standalone="standalone" fooBar="baz"');
}

public function testAfter(): void
{
$attr = (new Attributes(foo: 'bar'))->after(' ');

$this->assertSame((string)$attr, 'foo="bar" ');
$this->assertSame((string) $attr, 'foo="bar" ');
}

public function testBefore(): void
{
$attr = (new Attributes(foo: 'bar'))->before(' ');

$this->assertSame((string)$attr, ' foo="bar"');
$this->assertSame((string) $attr, ' foo="bar"');
}

public function testCreateClassValue(): void
{
$value = $this->_callProtectedStaticMethod('createClassValue', 'foo bar');

$this->assertSame((string)$value, 'foo bar');
$this->assertSame((string) $value, 'foo bar');
}

public function testNullClassValue(): void
{
$attributes = new Attributes(class: null);
$this->assertSame($attributes->get('class')->value(), null);
$this->assertSame((string)$attributes, '');
$this->assertSame((string) $attributes, '');
}

public function testCreateClassValueWhiteSurplusWhiteSpace(): void
Expand All @@ -123,14 +123,14 @@ public function testCreateClassValueWhiteSurplusWhiteSpace(): void
qux
');

$this->assertSame((string)$value, 'foo bar baz qux');
$this->assertSame((string) $value, 'foo bar baz qux');
}

public function testNormalizeClassValueFromNumericArray(): void
{
$value = $this->_callProtectedStaticMethod('normalizeClassValue', ['foo', 'bar']);

$this->assertSame((string)$value, 'foo bar');
$this->assertSame((string) $value, 'foo bar');
}

public function testNormalizeClassValueFromConditionalArray(): void
Expand All @@ -141,7 +141,7 @@ public function testNormalizeClassValueFromConditionalArray(): void
'baz'
]);

$this->assertSame((string)$value, 'foo baz');
$this->assertSame((string) $value, 'foo baz');
}

public function testAttributesWithClassesArray(): void
Expand All @@ -155,17 +155,15 @@ public function testAttributesWithClassesArray(): void
]
]);

echo $attr;

$this->assertSame((string)$attr, 'class="foo bar" foo="bar"');
$this->assertSame((string) $attr, 'class="foo bar" foo="bar"');
}

public function testMerge(): void
{
$attr = new Attributes(foo: 'bar');
$attr = $attr->merge(bar: 'foo');

$this->assertSame((string)$attr, 'bar="foo" foo="bar"');
$this->assertSame((string) $attr, 'bar="foo" foo="bar"');
}

public function testMergeClassAttribute(): void
Expand All @@ -174,22 +172,22 @@ public function testMergeClassAttribute(): void
$attr = $attr->merge(['class' => 'bar']);
$attr = $attr->class('baz');

$this->assertSame((string)$attr, 'class="foo bar baz"');
$this->assertSame((string) $attr, 'class="foo bar baz"');
}

public function testRepeatedSetClassAttribute(): void
{
$attr = new Attributes(['class' => 'foo']);
$attr = $attr->class('bar');

$this->assertSame((string)$attr, 'class="foo bar"');
$this->assertSame((string) $attr, 'class="foo bar"');
}

public function testCreateStyleValue(): void
{
$value = $this->_callProtectedStaticMethod('createStyleValue', 'foo: bar; bar: foo;');

$this->assertSame((string)$value, 'foo: bar; bar: foo;');
$this->assertSame((string) $value, 'foo: bar; bar: foo;');
}

public function testNullStyleValue(): void
Expand All @@ -205,7 +203,7 @@ public function testNormalizeStyleValue(): void
'bar: foo',
]);

$this->assertSame((string)$value, 'foo: bar; bar: foo');
$this->assertSame((string) $value, 'foo: bar; bar: foo');
}

public function testMergeStyleAttribute(): void
Expand All @@ -214,7 +212,7 @@ public function testMergeStyleAttribute(): void
$attr = $attr->merge(['style' => 'bar: foo']);
$attr = $attr->style('baz: qux');

$this->assertSame((string)$attr, 'style="foo: bar; bar: foo; baz: qux"');
$this->assertSame((string) $attr, 'style="foo: bar; bar: foo; baz: qux"');
}

public function testGet(): void
Expand All @@ -233,7 +231,7 @@ public function testSet(): void
$attr = $attr->baz('qux');
$attr = $attr->merge(['qux' => 'bar']);

$this->assertSame((string)$attr, 'baz="qux" foo="bar" qux="bar"');
$this->assertSame((string) $attr, 'baz="qux" foo="bar" qux="bar"');
}

public function testAppend(): void
Expand Down Expand Up @@ -263,16 +261,10 @@ public function testProtect(): void
$this->assertSame($attr->get('foo')->value(), 'bar');
}

public function testInvoke(): void
{
$attr = (new Attributes())(foo: 'bar')(baz: 'qux');
$this->assertSame((string)$attr, 'baz="qux" foo="bar"');
}

public function testOffsetGet(): void
{
$attr = new Attributes(foo: 'bar');
$this->assertSame((string)$attr['foo'], 'bar');
$this->assertSame((string) $attr['foo'], 'bar');
}

public function testOffsetGetNonExisting(): void
Expand All @@ -285,7 +277,7 @@ public function testOffsetSet(): void
{
$attr = new Attributes();
$attr['foo'] = 'bar';
$this->assertSame((string)$attr, 'foo="bar"');
$this->assertSame((string) $attr, 'foo="bar"');
}


Expand All @@ -306,7 +298,7 @@ public function testOffsetUnset(): void
{
$attr = new Attributes(foo: 'bar');
unset($attr['foo']);
$this->assertSame((string)$attr, '');
$this->assertSame((string) $attr, '');
}


Expand Down

0 comments on commit 1b8bbd4

Please sign in to comment.