Skip to content

Commit f237a20

Browse files
committed
Updated tests
1 parent d1b63c3 commit f237a20

19 files changed

+327
-362
lines changed

test/FeedbackTest.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ public function testFeedbackForEmptyPassword(): void
2323
{
2424
$feedback = $this->feedback->getFeedback(0, []);
2525

26-
$this->assertSame('', $feedback['warning'], "default warning");
26+
$this->assertSame('', $feedback['warning'], 'default warning');
2727
$this->assertContains(
2828
'Use a few words, avoid common phrases',
2929
$feedback['suggestions'],
30-
"default suggestion #1"
30+
'default suggestion #1'
3131
);
3232
$this->assertContains(
3333
'No need for symbols, digits, or uppercase letters',
3434
$feedback['suggestions'],
35-
"default suggestion #1"
35+
'default suggestion #1'
3636
);
3737
}
3838

@@ -41,52 +41,52 @@ public function testHighScoringSequence(): void
4141
$match = new Bruteforce('a', 0, 1, 'a');
4242
$feedback = $this->feedback->getFeedback(3, [$match]);
4343

44-
$this->assertSame('', $feedback['warning'], "no warning for good score");
45-
$this->assertEmpty($feedback['suggestions'], "no suggestions for good score");
44+
$this->assertSame('', $feedback['warning'], 'no warning for good score');
45+
$this->assertEmpty($feedback['suggestions'], 'no suggestions for good score');
4646
}
4747

4848
public function testLongestMatchGetsFeedback(): void
4949
{
5050
$match1 = new SequenceMatch('abcd26-01-1991', 0, 4, 'abcd');
5151
$match2 = new DateMatch('abcd26-01-1991', 4, 14, '26-01-1991', [
52-
'day' => 26,
53-
'month' => 1,
54-
'year' => 1991,
52+
'day' => 26,
53+
'month' => 1,
54+
'year' => 1991,
5555
'separator' => '-',
5656
]);
5757
$feedback = $this->feedback->getFeedback(1, [$match1, $match2]);
5858

5959
$this->assertSame(
6060
'Dates are often easy to guess',
6161
$feedback['warning'],
62-
"warning provided for the longest match"
62+
'warning provided for the longest match'
6363
);
6464
$this->assertContains(
6565
'Avoid dates and years that are associated with you',
6666
$feedback['suggestions'],
67-
"suggestion provided for the longest match"
67+
'suggestion provided for the longest match'
6868
);
6969
$this->assertNotContains(
7070
'Avoid sequences',
7171
$feedback['suggestions'],
72-
"no suggestion provided for the shorter match"
72+
'no suggestion provided for the shorter match'
7373
);
7474
}
7575

7676
public function testDefaultSuggestion(): void
7777
{
7878
$match = new DateMatch('26-01-1991', 0, 10, '26-01-1991', [
79-
'day' => 26,
80-
'month' => 1,
81-
'year' => 1991,
79+
'day' => 26,
80+
'month' => 1,
81+
'year' => 1991,
8282
'separator' => '-',
8383
]);
8484
$feedback = $this->feedback->getFeedback(1, [$match]);
8585

8686
$this->assertContains(
8787
'Add another word or two. Uncommon words are better.',
8888
$feedback['suggestions'],
89-
"default suggestion provided"
89+
'default suggestion provided'
9090
);
9191
$this->assertCount(2, $feedback['suggestions'], "default suggestion doesn\'t override existing suggestion");
9292
}
@@ -96,11 +96,11 @@ public function testBruteforceFeedback(): void
9696
$match = new Bruteforce('qkcriv', 0, 6, 'qkcriv');
9797
$feedback = $this->feedback->getFeedback(1, [$match]);
9898

99-
$this->assertSame('', $feedback['warning'], "bruteforce match has no warning");
99+
$this->assertSame('', $feedback['warning'], 'bruteforce match has no warning');
100100
$this->assertSame(
101101
['Add another word or two. Uncommon words are better.'],
102102
$feedback['suggestions'],
103-
"bruteforce match only has the default suggestion"
103+
'bruteforce match only has the default suggestion'
104104
);
105105
}
106106
}

test/MatcherTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function testMultiplePatterns(): void
4242
['dictionary', [ 0, 6]],
4343
['dictionary', [ 7, 15]],
4444
['date', [16, 23]],
45-
['repeat', [24, 27]]
45+
['repeat', [24, 27]],
4646
];
4747

4848
$matches = $matcher->getMatches($password);
@@ -53,7 +53,7 @@ public function testMultiplePatterns(): void
5353
}
5454
}
5555

56-
$this->assertEmpty($expectedMatches, "matches multiple patterns");
56+
$this->assertEmpty($expectedMatches, 'matches multiple patterns');
5757
}
5858

5959
/**
@@ -65,8 +65,8 @@ public function testUserDefinedWords(): void
6565
$matcher = new Matcher();
6666
$matches = $matcher->getMatches('_wQbgL491', ['PJnD', 'WQBG', 'ZhwZ']);
6767

68-
$this->assertInstanceOf(DictionaryMatch::class, $matches[0], "user input match is correct class");
69-
$this->assertSame('wQbg', $matches[0]->token, "user input match has correct token");
68+
$this->assertInstanceOf(DictionaryMatch::class, $matches[0], 'user input match is correct class');
69+
$this->assertSame('wQbg', $matches[0]->token, 'user input match has correct token');
7070
}
7171

7272
public function testAddMatcherWillThrowException(): void

test/Matchers/AbstractMatchTest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ abstract class AbstractMatchTest extends TestCase
1818
*
1919
* @param array<int, string> $prefixes
2020
* @param array<int, string> $suffixes
21+
*
2122
* @return array<int, mixed> a list of triplets [variant, i, j] where [i,j] is the start/end of the pattern, inclusive
2223
*/
2324
protected function generatePasswords(string $pattern, array $prefixes, array $suffixes): array
2425
{
2526
$output = [];
2627

27-
if (!in_array('', $prefixes)) {
28+
if (! in_array('', $prefixes)) {
2829
array_unshift($prefixes, '');
2930
}
30-
if (!in_array('', $suffixes)) {
31+
if (! in_array('', $suffixes)) {
3132
array_unshift($suffixes, '');
3233
}
3334

@@ -39,7 +40,7 @@ protected function generatePasswords(string $pattern, array $prefixes, array $su
3940
$output[] = [
4041
$prefix . $pattern . $suffix,
4142
$i,
42-
$j
43+
$j,
4344
];
4445
}
4546
}
@@ -72,7 +73,7 @@ protected function checkMatches(
7273
$this->assertCount(
7374
count($patterns),
7475
$matches,
75-
$prefix . ": matches.length == " . count($patterns)
76+
$prefix . ': matches.length == ' . count($patterns)
7677
);
7778

7879
foreach ($patterns as $k => $pattern) {
@@ -84,17 +85,17 @@ protected function checkMatches(
8485
$this->assertSame(
8586
$patternName,
8687
$match->pattern,
87-
"$prefix matches[$k].pattern == '$patternName'"
88+
"{$prefix} matches[{$k}].pattern == '{$patternName}'"
8889
);
8990
$this->assertSame(
9091
[$i, $j],
9192
[$match->begin, $match->end],
92-
"$prefix matches[$k] should have [i, j] of [$i, $j]"
93+
"{$prefix} matches[{$k}] should have [i, j] of [{$i}, {$j}]"
9394
);
9495
$this->assertSame(
9596
$pattern,
9697
$match->token,
97-
"$prefix matches[$k].token == '$pattern'"
98+
"{$prefix} matches[{$k}].token == '{$pattern}'"
9899
);
99100

100101
foreach ($props as $propName => $propList) {
@@ -103,7 +104,7 @@ protected function checkMatches(
103104
$this->assertSame(
104105
$propList[$k],
105106
$match->$propName,
106-
"$prefix matches[$k].$propName == $propMessage"
107+
"{$prefix} matches[{$k}].{$propName} == {$propMessage}"
107108
);
108109
}
109110
}

test/Matchers/BruteforceTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function testMatch(): void
1313
$password = 'uH2nvQbugW';
1414

1515
$this->checkMatches(
16-
"matches entire string",
16+
'matches entire string',
1717
Bruteforce::match($password),
1818
'bruteforce',
1919
[$password],
@@ -27,7 +27,7 @@ public function testMultibyteMatch(): void
2727
$password = '中华人民共和国';
2828

2929
$this->checkMatches(
30-
"matches entire string with multibyte characters",
30+
'matches entire string with multibyte characters',
3131
Bruteforce::match($password),
3232
'bruteforce',
3333
[$password],
@@ -47,6 +47,6 @@ public function testGuessesMultibyteCharacter(): void
4747
{
4848
$token = '🙂'; // smiley face emoji
4949
$match = new Bruteforce($token, 0, 1, $token);
50-
$this->assertEqualsWithDelta(11.0, $match->getGuesses(), PHP_FLOAT_EPSILON, "multibyte character treated as one character");
50+
$this->assertEqualsWithDelta(11.0, $match->getGuesses(), PHP_FLOAT_EPSILON, 'multibyte character treated as one character');
5151
}
5252
}

0 commit comments

Comments
 (0)