Skip to content

Commit b2322d2

Browse files
committed
Fix encoder documentation
1 parent 2ac0aa1 commit b2322d2

File tree

6 files changed

+53
-1
lines changed

6 files changed

+53
-1
lines changed

BaseUri.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,8 @@ final protected static function formatPathWithEmptyBaseQuery(string $path): stri
527527
* Normalizes a URI for comparison; this URI string representation is not suitable for usage as per RFC guidelines.
528528
*
529529
* @deprecated since version 7.6.0
530+
*
531+
* @codeCoverageIgnore
530532
*/
531533
#[Deprecated(message:'no longer used by the isSameDocument method', since:'league/uri-interfaces:7.6.0')]
532534
final protected function normalize(Psr7UriInterface|UriInterface $uri): string
@@ -544,6 +546,8 @@ final protected function normalize(Psr7UriInterface|UriInterface $uri): string
544546
* Remove dot segments from the URI path as per RFC specification.
545547
*
546548
* @deprecated since version 7.6.0
549+
*
550+
* @codeCoverageIgnore
547551
*/
548552
#[Deprecated(message:'no longer used by the isSameDocument method', since:'league/uri-interfaces:7.6.0')]
549553
final protected function removeDotSegments(string $path): string
@@ -588,6 +592,8 @@ final protected function removeDotSegments(string $path): string
588592
* @return array{0:string, 1:string|null}
589593
*
590594
* @deprecated since version 7.6.0
595+
*
596+
* @codeCoverageIgnore
591597
*/
592598
#[Deprecated(message:'no longer used by the isSameDocument method', since:'league/uri-interfaces:7.6.0')]
593599
final protected function resolvePathAndQuery(Psr7UriInterface|UriInterface $uri): array

UriTemplate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function getDefaultVariables(): array
103103
public function withDefaultVariables(iterable $defaultVariables): self
104104
{
105105
$defaultVariables = $this->filterVariables($defaultVariables);
106-
if ($defaultVariables == $this->defaultVariables) {
106+
if ($this->defaultVariables->equals($defaultVariables)) {
107107
return $this;
108108
}
109109

UriTemplate/ExpressionTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use PHPUnit\Framework\TestCase;
2020

2121
#[CoversClass(Expression::class)]
22+
#[CoversClass(Operator::class)]
2223
final class ExpressionTest extends TestCase
2324
{
2425
#[DataProvider('providesValidNotation')]

UriTemplate/TemplateTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,10 @@ public function testExpandOrFailIfAtLeastOneVariableIsMissing(): void
180180

181181
Template::new('{var}{baz}')->expandOrFail(['var' => 'bar']);
182182
}
183+
184+
#[Test]
185+
public function it_can_expand_with_expand_or_fail_when_all_variables_are_present(): void
186+
{
187+
self::assertSame('barfoo', Template::new('{var}{baz}')->expandOrFail(['var' => 'bar', 'baz' => 'foo']));
188+
}
183189
}

UriTemplate/VariableBag.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ public function isNotEmpty(): bool
9797
return [] !== $this->variables;
9898
}
9999

100+
public function equals(mixed $value): bool
101+
{
102+
return $value instanceof self
103+
&& $this->variables === $value->variables;
104+
}
105+
100106
/**
101107
* Fetches the variable value if none found returns null.
102108
*

UriTemplate/VariableBagTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ArrayIterator;
1717
use PHPUnit\Framework\Attributes\CoversClass;
1818
use PHPUnit\Framework\Attributes\DataProvider;
19+
use PHPUnit\Framework\Attributes\Test;
1920
use PHPUnit\Framework\TestCase;
2021
use stdClass;
2122
use TypeError;
@@ -172,4 +173,36 @@ public function testItCanReplaceItsValueWithThatOfAnotherInstance(): void
172173
self::assertEquals($expected, $bag->replace($defaultBag));
173174
self::assertEquals($defaultBag, $defaultBag->replace($bag));
174175
}
176+
177+
#[Test]
178+
public function it_can_evaluate_if_the_bag_is_identical(): void
179+
{
180+
$bag = new VariableBag([
181+
'foo' => 'bar',
182+
'yolo' => 42,
183+
'list' => 'this is a list',
184+
]);
185+
186+
self::assertFalse($bag->equals(new ArrayIterator()));
187+
self::assertFalse($bag->equals(new stdClass()));
188+
self::assertFalse($bag->equals('bag'));
189+
self::assertFalse($bag->equals(new VariableBag()));
190+
self::assertTrue($bag->equals($bag));
191+
}
192+
193+
#[Test]
194+
public function it_can_filter_its_content(): void
195+
{
196+
$bag = new VariableBag([
197+
'foo' => 'bar',
198+
'yolo' => 42,
199+
'list' => 'this is a list',
200+
]);
201+
self::assertCount(3, $bag);
202+
203+
$newBag = $bag->filter(fn ($value, $key) => 'foo' === $key);
204+
205+
self::assertFalse($newBag->equals($bag));
206+
self::assertCount(1, $newBag);
207+
}
175208
}

0 commit comments

Comments
 (0)