Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Compare strings directly #674

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ public function testInvalidValue(): void
$this->formatter->format($matcher);
}

#[TestWith([new Boolean(true), '"matching(boolean, true)"'])]
#[TestWith([new Boolean(false), '"matching(boolean, false)"'])]
#[TestWith([new Boolean(true), 'matching(boolean, true)'])]
#[TestWith([new Boolean(false), 'matching(boolean, false)'])]
public function testFormat(MatcherInterface $matcher, string $expression): void
{
$this->assertSame($expression, json_encode($this->formatter->format($matcher)));
$result = $this->formatter->format($matcher);
$this->assertIsString($result);
$this->assertSame($expression, $result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ public function testInvalidString(MatcherInterface $matcher, string $value): voi
$this->formatter->format($matcher);
}

#[TestWith([new ContentType('plain/text'), '"matching(contentType, \'plain\/text\', \'\')"'])]
#[TestWith([new ContentType('application/json', '{"key":"value"}'), '"matching(contentType, \'application\/json\', \'{\"key\":\"value\"}\')"'])]
#[TestWith([new ContentType('application/xml', '<?xml?><test/>'), '"matching(contentType, \'application\/xml\', \'<?xml?><test\/>\')"'])]
#[TestWith([new ContentType('plain/text'), 'matching(contentType, \'plain/text\', \'\')'])]
#[TestWith([new ContentType('application/json', '{"key":"value"}'), 'matching(contentType, \'application/json\', \'{"key":"value"}\')'])]
#[TestWith([new ContentType('application/xml', '<?xml?><test/>'), 'matching(contentType, \'application/xml\', \'<?xml?><test/>\')'])]
public function testFormat(MatcherInterface $matcher, string $expression): void
{
$this->assertSame($expression, json_encode($this->formatter->format($matcher)));
$result = $this->formatter->format($matcher);
$this->assertIsString($result);
$this->assertSame($expression, $result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ public function testInvalidString(MatcherInterface $matcher, string $value): voi
$this->formatter->format($matcher);
}

#[TestWith([new DateTime('yyyy-MM-dd HH:mm:ssZZZZZ', '2020-05-21 16:44:32+10:00'), '"matching(datetime, \'yyyy-MM-dd HH:mm:ssZZZZZ\', \'2020-05-21 16:44:32+10:00\')"'])]
#[TestWith([new Date('yyyy-MM-dd', '2012-04-12'), '"matching(date, \'yyyy-MM-dd\', \'2012-04-12\')"'])]
#[TestWith([new Time('HH:mm', '22:04'), '"matching(time, \'HH:mm\', \'22:04\')"'])]
#[TestWith([new DateTime('yyyy-MM-dd HH:mm:ssZZZZZ', '2020-05-21 16:44:32+10:00'), 'matching(datetime, \'yyyy-MM-dd HH:mm:ssZZZZZ\', \'2020-05-21 16:44:32+10:00\')'])]
#[TestWith([new Date('yyyy-MM-dd', '2012-04-12'), 'matching(date, \'yyyy-MM-dd\', \'2012-04-12\')'])]
#[TestWith([new Time('HH:mm', '22:04'), 'matching(time, \'HH:mm\', \'22:04\')'])]
public function testFormat(MatcherInterface $matcher, string $expression): void
{
$this->assertSame($expression, json_encode($this->formatter->format($matcher)));
$result = $this->formatter->format($matcher);
$this->assertIsString($result);
$this->assertSame($expression, $result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ public function testInvalidValue(): void
$this->formatter->format($matcher);
}

#[TestWith([new Decimal(-99), '"matching(decimal, -99)"'])] // Provider verification will fail on this case
#[TestWith([new Decimal(100), '"matching(decimal, 100)"'])] // Provider verification will fail on this case
#[TestWith([new Decimal(100.01), '"matching(decimal, 100.01)"'])]
#[TestWith([new Decimal(-100.003), '"matching(decimal, -100.003)"'])]
#[TestWith([new Decimal(-99), 'matching(decimal, -99)'])] // Provider verification will fail on this case
#[TestWith([new Decimal(100), 'matching(decimal, 100)'])] // Provider verification will fail on this case
#[TestWith([new Decimal(100.01), 'matching(decimal, 100.01)'])]
#[TestWith([new Decimal(-100.003), 'matching(decimal, -100.003)'])]
public function testFormat(MatcherInterface $matcher, string $expression): void
{
$this->assertSame($expression, json_encode($this->formatter->format($matcher)));
$result = $this->formatter->format($matcher);
$this->assertIsString($result);
$this->assertSame($expression, $result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ public function testInvalidRules(EachKey $matcher): void
$this->formatter->format($matcher);
}

#[TestWith([new EachKey(['value'], [new Integer(123)]), '"eachKey(matching(integer, 123))"'])]
#[TestWith([new EachKey(new stdClass(), [new Regex('\w+', 'example value')]), '"eachKey(matching(regex, \'\\\\w+\', \'example value\'))"'])]
#[TestWith([new EachKey(['value'], [new Integer(123)]), 'eachKey(matching(integer, 123))'])]
#[TestWith([new EachKey(new stdClass(), [new Regex('\w+', 'example value')]), 'eachKey(matching(regex, \'\w+\', \'example value\'))'])]
public function testFormat(MatcherInterface $matcher, string $expression): void
{
$this->assertSame($expression, json_encode($this->formatter->format($matcher)));
$result = $this->formatter->format($matcher);
$this->assertIsString($result);
$this->assertSame($expression, $result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ public function testInvalidRules(EachValue $matcher): void
$this->formatter->format($matcher);
}

#[TestWith([new EachValue(['value'], [new StringValue('example value')]), '"eachValue(matching(type, \'example value\'))"'])]
#[TestWith([new EachValue(new stdClass(), [new Regex('\w \d', 'a 1')]), '"eachValue(matching(regex, \'\\\\w \\\\d\', \'a 1\'))"'])]
#[TestWith([new EachValue(['value'], [new StringValue('example value')]), 'eachValue(matching(type, \'example value\'))'])]
#[TestWith([new EachValue(new stdClass(), [new Regex('\w \d', 'a 1')]), 'eachValue(matching(regex, \'\w \d\', \'a 1\'))'])]
public function testFormat(MatcherInterface $matcher, string $expression): void
{
$this->assertSame($expression, json_encode($this->formatter->format($matcher)));
$result = $this->formatter->format($matcher);
$this->assertIsString($result);
$this->assertSame($expression, $result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,18 @@ public function testInvalidString(MatcherInterface $matcher, string $value): voi
$this->formatter->format($matcher);
}

#[TestWith([new Equality('example value'), '"matching(equalTo, \'example value\')"'])]
#[TestWith([new Equality(100.09), '"matching(equalTo, 100.09)"'])]
#[TestWith([new Equality(-99.99), '"matching(equalTo, -99.99)"'])]
#[TestWith([new Equality(100), '"matching(equalTo, 100)"'])]
#[TestWith([new Equality(-99), '"matching(equalTo, -99)"'])]
#[TestWith([new Equality(true), '"matching(equalTo, true)"'])]
#[TestWith([new Equality(false), '"matching(equalTo, false)"'])]
#[TestWith([new Equality(null), '"matching(equalTo, null)"'])]
#[TestWith([new Equality('example value'), 'matching(equalTo, \'example value\')'])]
#[TestWith([new Equality(100.09), 'matching(equalTo, 100.09)'])]
#[TestWith([new Equality(-99.99), 'matching(equalTo, -99.99)'])]
#[TestWith([new Equality(100), 'matching(equalTo, 100)'])]
#[TestWith([new Equality(-99), 'matching(equalTo, -99)'])]
#[TestWith([new Equality(true), 'matching(equalTo, true)'])]
#[TestWith([new Equality(false), 'matching(equalTo, false)'])]
#[TestWith([new Equality(null), 'matching(equalTo, null)'])]
public function testFormat(MatcherInterface $matcher, string $expression): void
{
$this->assertSame($expression, json_encode($this->formatter->format($matcher)));
$result = $this->formatter->format($matcher);
$this->assertIsString($result);
$this->assertSame($expression, $result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ public function testInvalidString(MatcherInterface $matcher, string $value): voi
$this->formatter->format($matcher);
}

#[TestWith([new Includes('example value'), '"matching(include, \'example value\')"'])]
#[TestWith([new Includes('example value'), 'matching(include, \'example value\')'])]
public function testFormat(MatcherInterface $matcher, string $expression): void
{
$this->assertSame($expression, json_encode($this->formatter->format($matcher)));
$result = $this->formatter->format($matcher);
$this->assertIsString($result);
$this->assertSame($expression, $result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ public function testInvalidValue(): void
$this->formatter->format($matcher);
}

#[TestWith([new Integer(-99), '"matching(integer, -99)"'])]
#[TestWith([new Integer(100), '"matching(integer, 100)"'])]
#[TestWith([new Integer(-99), 'matching(integer, -99)'])]
#[TestWith([new Integer(100), 'matching(integer, 100)'])]
public function testFormat(MatcherInterface $matcher, string $expression): void
{
$this->assertSame($expression, json_encode($this->formatter->format($matcher)));
$result = $this->formatter->format($matcher);
$this->assertIsString($result);
$this->assertSame($expression, $result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ public function testInvalidMatchers(MatchAll $matcher): void
$this->formatter->format($matcher);
}

#[TestWith([new MatchAll(['abc' => 1, 'def' => 234], [new MinType(null, 2, false)]), '"atLeast(2)"'])]
#[TestWith([new MatchAll(['abc' => 1, 'def' => 234], [new MinType(null, 1, false), new MaxType(null, 2, false), new EachKey(["doesn't matter"], [new Regex('\w+', 'abc')]), new EachValue(["doesn't matter"], [new Type(100)])]), '"atLeast(1), atMost(2), eachKey(matching(regex, \'\\\\w+\', \'abc\')), eachValue(matching(type, 100))"'])]
#[TestWith([new MatchAll(['abc' => 1, 'def' => 234], [new MinType(null, 2, false)]), 'atLeast(2)'])]
#[TestWith([new MatchAll(['abc' => 1, 'def' => 234], [new MinType(null, 1, false), new MaxType(null, 2, false), new EachKey(["doesn't matter"], [new Regex('\w+', 'abc')]), new EachValue(["doesn't matter"], [new Type(100)])]), 'atLeast(1), atMost(2), eachKey(matching(regex, \'\w+\', \'abc\')), eachValue(matching(type, 100))'])]
public function testFormat(MatcherInterface $matcher, string $expression): void
{
$this->assertSame($expression, json_encode($this->formatter->format($matcher)));
$result = $this->formatter->format($matcher);
$this->assertIsString($result);
$this->assertSame($expression, $result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ public function testInvalidString(MatcherInterface $matcher, string $value): voi
$this->formatter->format($matcher);
}

#[TestWith([new MatchingField('product'), '"matching($\'product\')"'])]
#[TestWith([new MatchingField('product'), 'matching($\'product\')'])]
public function testFormat(MatcherInterface $matcher, string $expression): void
{
$this->assertSame($expression, json_encode($this->formatter->format($matcher)));
$result = $this->formatter->format($matcher);
$this->assertIsString($result);
$this->assertSame($expression, $result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ public function testNotSupportedMatcher(): void
$this->formatter->format($matcher);
}

#[TestWith([new MaxType(null, 2, false), '"atMost(2)"'])]
#[TestWith([new MaxType('example value', 2, false), '"atMost(2)"'])]
#[TestWith([new MaxType(null, 2), '"atMost(2), eachValue(matching(type, null)"'])]
#[TestWith([new MaxType('example value', 2), '"atMost(2), eachValue(matching(type, \'example value\')"'])]
#[TestWith([new MaxType(null, 2, false), 'atMost(2)'])]
#[TestWith([new MaxType('example value', 2, false), 'atMost(2)'])]
#[TestWith([new MaxType(null, 2), 'atMost(2), eachValue(matching(type, null)'])]
#[TestWith([new MaxType('example value', 2), 'atMost(2), eachValue(matching(type, \'example value\')'])]
public function testFormat(MatcherInterface $matcher, string $expression): void
{
$this->assertSame($expression, json_encode($this->formatter->format($matcher)));
$result = $this->formatter->format($matcher);
$this->assertIsString($result);
$this->assertSame($expression, $result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ public function testNotSupportedMatcher(): void
$this->formatter->format($matcher);
}

#[TestWith([new MinMaxType(null, 2, 3), '"atLeast(2), atMost(3), eachValue(matching(type, null)"'])]
#[TestWith([new MinMaxType('example value', 2, 3), '"atLeast(2), atMost(3), eachValue(matching(type, \'example value\')"'])]
#[TestWith([new MinMaxType(null, 2, 3), 'atLeast(2), atMost(3), eachValue(matching(type, null)'])]
#[TestWith([new MinMaxType('example value', 2, 3), 'atLeast(2), atMost(3), eachValue(matching(type, \'example value\')'])]
public function testFormat(MatcherInterface $matcher, string $expression): void
{
$this->assertSame($expression, json_encode($this->formatter->format($matcher)));
$result = $this->formatter->format($matcher);
$this->assertIsString($result);
$this->assertSame($expression, $result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ public function testNotSupportedMatcher(): void
$this->formatter->format($matcher);
}

#[TestWith([new MinType(null, 1, false), '"atLeast(1)"'])]
#[TestWith([new MinType('example value', 1, false), '"atLeast(1)"'])]
#[TestWith([new MinType(null, 1), '"atLeast(1), eachValue(matching(type, null)"'])]
#[TestWith([new MinType('example value', 1), '"atLeast(1), eachValue(matching(type, \'example value\')"'])]
#[TestWith([new MinType(null, 1, false), 'atLeast(1)'])]
#[TestWith([new MinType('example value', 1, false), 'atLeast(1)'])]
#[TestWith([new MinType(null, 1), 'atLeast(1), eachValue(matching(type, null)'])]
#[TestWith([new MinType('example value', 1), 'atLeast(1), eachValue(matching(type, \'example value\')'])]
public function testFormat(MatcherInterface $matcher, string $expression): void
{
$this->assertSame($expression, json_encode($this->formatter->format($matcher)));
$result = $this->formatter->format($matcher);
$this->assertIsString($result);
$this->assertSame($expression, $result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ public function testInvalidString(MatcherInterface $matcher, string $value): voi
$this->formatter->format($matcher);
}

#[TestWith([new NotEmpty('example value'), '"notEmpty(\'example value\')"'])]
#[TestWith([new NotEmpty(100.09), '"notEmpty(100.09)"'])]
#[TestWith([new NotEmpty(100), '"notEmpty(100)"'])]
#[TestWith([new NotEmpty(true), '"notEmpty(true)"'])]
#[TestWith([new NotEmpty(false), '"notEmpty(false)"'])]
#[TestWith([new NotEmpty('example value'), 'notEmpty(\'example value\')'])]
#[TestWith([new NotEmpty(100.09), 'notEmpty(100.09)'])]
#[TestWith([new NotEmpty(100), 'notEmpty(100)'])]
#[TestWith([new NotEmpty(true), 'notEmpty(true)'])]
#[TestWith([new NotEmpty(false), 'notEmpty(false)'])]
public function testFormat(MatcherInterface $matcher, string $expression): void
{
$this->assertSame($expression, json_encode($this->formatter->format($matcher)));
$result = $this->formatter->format($matcher);
$this->assertIsString($result);
$this->assertSame($expression, $result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ protected function setUp(): void
$this->formatter = new NullValueFormatter();
}

#[TestWith([new NullValue(), '"matching(type, null)"'])]
#[TestWith([new NullValue(), 'matching(type, null)'])]
public function testFormat(MatcherInterface $matcher, string $expression): void
{
$this->assertSame($expression, json_encode($this->formatter->format($matcher)));
$result = $this->formatter->format($matcher);
$this->assertIsString($result);
$this->assertSame($expression, $result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ public function testInvalidValue(): void
$this->formatter->format($matcher);
}

#[TestWith([new Number(-99), '"matching(number, -99)"'])]
#[TestWith([new Number(100), '"matching(number, 100)"'])]
#[TestWith([new Number(100.01), '"matching(number, 100.01)"'])]
#[TestWith([new Number(-100.003), '"matching(number, -100.003)"'])]
#[TestWith([new Number(-99), 'matching(number, -99)'])]
#[TestWith([new Number(100), 'matching(number, 100)'])]
#[TestWith([new Number(100.01), 'matching(number, 100.01)'])]
#[TestWith([new Number(-100.003), 'matching(number, -100.003)'])]
public function testFormat(MatcherInterface $matcher, string $expression): void
{
$this->assertSame($expression, json_encode($this->formatter->format($matcher)));
$result = $this->formatter->format($matcher);
$this->assertIsString($result);
$this->assertSame($expression, $result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ public function testInvalidString(MatcherInterface $matcher, string $value): voi
$this->formatter->format($matcher);
}

#[TestWith([new Regex('\\w{3}\\d+', 'abc123'), '"matching(regex, \'\\\\w{3}\\\\d+\', \'abc123\')"'])]
#[TestWith([new Regex('\w{3}\d+', 'abc123'), 'matching(regex, \'\w{3}\d+\', \'abc123\')'])]
public function testFormat(MatcherInterface $matcher, string $expression): void
{
$this->assertSame($expression, json_encode($this->formatter->format($matcher)));
$result = $this->formatter->format($matcher);
$this->assertIsString($result);
$this->assertSame($expression, $result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ public function testInvalidString(MatcherInterface $matcher, string $value): voi
$this->formatter->format($matcher);
}

#[TestWith([new Semver('1.0.0'), '"matching(semver, \'1.0.0\')"'])]
#[TestWith([new Semver('1.0.0'), 'matching(semver, \'1.0.0\')'])]
public function testFormat(MatcherInterface $matcher, string $expression): void
{
$this->assertSame($expression, json_encode($this->formatter->format($matcher)));
$result = $this->formatter->format($matcher);
$this->assertIsString($result);
$this->assertSame($expression, $result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ public function testInvalidString(MatcherInterface $matcher, string $value): voi
$this->formatter->format($matcher);
}

#[TestWith([new StringValue('value'), '"matching(type, \'value\')"'])]
#[TestWith([new StringValue('value'), 'matching(type, \'value\')'])]
public function testFormat(MatcherInterface $matcher, string $expression): void
{
$this->assertSame($expression, json_encode($this->formatter->format($matcher)));
$result = $this->formatter->format($matcher);
$this->assertIsString($result);
$this->assertSame($expression, $result);
}
}
Loading