Skip to content

Commit

Permalink
Embrace strict(er) types, ensure that #13 is covered by Selector
Browse files Browse the repository at this point in the history
  • Loading branch information
stevegrunwell committed Dec 4, 2023
1 parent a6f07df commit cfea894
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct($selector)
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return $this->getValue();
}
Expand All @@ -48,7 +48,7 @@ public function __toString()
*
* @return string
*/
public function getValue()
public function getValue(): string
{
return $this->selector;
}
Expand All @@ -61,7 +61,7 @@ public function getValue()
*
* @return string The flattened attribute array.
*/
private function attributeArrayToString($attributes)
private function attributeArrayToString($attributes): string
{
if (empty($attributes)) {
throw new AttributeArrayException('Attributes array is empty.');
Expand Down
22 changes: 19 additions & 3 deletions tests/Unit/SelectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,29 @@ public function it_should_accept_string_selectors()
*
* @dataProvider provideAttributes
*/
public function it_should_automatically_convert_attribute_arrays_to_strings($attributes, $expected)
{
public function it_should_automatically_convert_attribute_arrays_to_strings(
array $attributes,
string $expected
) {
$selector = new Selector($attributes);

$this->assertSame($expected, $selector->getValue());
}

/**
* @test
*
* @ticket https://github.com/stevegrunwell/phpunit-markup-assertions/issues/13
*/
public function it_should_be_able_to_handle_spaces_in_attribute_values()
{
$selector = new Selector([
'data-attr' => 'foo bar baz',
]);

$this->assertSame('*[data-attr="foo bar baz"]', $selector->getValue());
}

/**
* @test
*/
Expand All @@ -58,7 +74,7 @@ public function it_should_be_able_to_be_cast_to_a_string()
/**
* Data provider for testFlattenAttributeArray().
*
* @return Iterable{array<string, scalar>, string} The attribute array and teh expected string.
* @return iterable{array<string, scalar>, string} The attribute array and the expected string.
*/
public function provideAttributes()
{
Expand Down

0 comments on commit cfea894

Please sign in to comment.