Skip to content

Commit

Permalink
Add missing parameter type assertions in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
guvra committed Oct 17, 2024
1 parent b1e51b7 commit 8ce617b
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions tests/unit/Converter/Anonymizer/AnonymizeDateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function testConverter(): void

$date = '1990-12-31';
$value = $converter->convert($date);
$this->assertIsString($value);
$this->assertDateIsAnonymized($value, $date, 'Y-m-d');
}

Expand All @@ -37,6 +38,7 @@ public function testFormatParameter(): void

$date = '31/12/1990';
$value = $converter->convert($date);
$this->assertIsString($value);
$this->assertDateIsAnonymized($value, $date, $format);
}

Expand Down
2 changes: 2 additions & 0 deletions tests/unit/Converter/Anonymizer/AnonymizeDateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function testConverter(): void

$date = '1990-12-31 12:05:41';
$value = $converter->convert($date);
$this->assertIsString($value);
$this->assertDateIsAnonymized($value, $date, 'Y-m-d H:i:s');
}

Expand All @@ -32,6 +33,7 @@ public function testFormatParameter(): void

$date = '31/12/1990 12:05:41';
$value = $converter->convert($date);
$this->assertIsString($value);
$this->assertDateIsAnonymized($value, $date, $format);
}

Expand Down
4 changes: 4 additions & 0 deletions tests/unit/Converter/Generator/RandomDateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function testConverter(): void

$date = '1990-12-31';
$value = $converter->convert($date);
$this->assertIsString($value);
$this->assertDateIsRandomized($value, $date, 'Y-m-d');
}

Expand All @@ -36,6 +37,7 @@ public function testFormatParameter(): void

$date = '31/12/1990';
$value = $converter->convert($date);
$this->assertIsString($value);
$this->assertDateIsRandomized($value, $date, $format);
}

Expand All @@ -51,6 +53,7 @@ public function testYearParameters(): void

$date = '1990-12-31';
$value = $converter->convert($date);
$this->assertIsString($value);
$this->assertDateIsRandomized($value, $date, 'Y-m-d');
}

Expand All @@ -66,6 +69,7 @@ public function testNullYears(): void

$date = '1990-12-31';
$value = $converter->convert($date);
$this->assertIsString($value);

$currentYear = (new DateTime())->format('Y');
$randomizedYear = (new DateTime($value))->format('Y');
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/Converter/Generator/RandomDateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function testConverter(): void

$date = '1990-12-31 12:05:41';
$value = $converter->convert($date);
$this->assertIsString($value);
$this->assertDateIsRandomized($value, $date, 'Y-m-d H:i:s');
}

Expand All @@ -35,6 +36,7 @@ public function testFormatParameter(): void

$date = '31/12/1990 12:05:41';
$randomizedDate = $converter->convert($date);
$this->assertIsString($randomizedDate);
$this->assertDateIsRandomized($randomizedDate, $date, $format);
}

Expand All @@ -50,6 +52,7 @@ public function testYearParameters(): void

$date = '1990-12-31 12:05:41';
$randomizedDate = $converter->convert($date);
$this->assertIsString($randomizedDate);
$this->assertDateIsRandomized($randomizedDate, $date, 'Y-m-d H:i:s');
}

Expand All @@ -65,6 +68,7 @@ public function testNullYears(): void

$date = '1990-12-31 12:05:41';
$randomizedDate = $converter->convert($date);
$this->assertIsString($randomizedDate);

$currentYear = (new DateTime())->format('Y');
$randomizedYear = (new DateTime($randomizedDate))->format('Y');
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/Converter/Generator/RandomEmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function testConverter(): void
$this->assertNotNull($value);

$value = $converter->convert('[email protected]');
$this->assertIsString($value);
$this->assertStringNotContainsString('user1', $value);
$this->assertStringNotContainsString('@gmail.com', $value);
$this->assertStringEndsWith('@example.org', $value);
Expand All @@ -38,6 +39,7 @@ public function testCustomLength(): void
]);

$value = $converter->convert('[email protected]');
$this->assertIsString($value);
$this->assertStringEndsWith('@example.org', $value);

$parts = explode('@', $value);
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/Converter/Generator/RandomTextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function testConverter(): void
$this->assertNotNull($value);

$value = $converter->convert('user1');
$this->assertIsString($value);
$this->assertStringNotContainsString('user1', $value);
$this->assertGreaterThanOrEqual(3, strlen($value));
}
Expand All @@ -37,6 +38,7 @@ public function testCustomLength(): void
]);

$value = $converter->convert('user1');
$this->assertIsString($value);
$this->assertSame(20, strlen($value));
}

Expand Down
1 change: 1 addition & 0 deletions tests/unit/Converter/Proxy/JsonDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function testConverter(): void
$this->assertNull($value);

$value = $converter->convert($this->getJsonData());
$this->assertIsString($value);
$this->assertJson($this->getExpectedData(), $value);
}

Expand Down
2 changes: 2 additions & 0 deletions tests/unit/Converter/Randomizer/RandomizeEmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function testConverter(): void
$this->assertSame('', $value);

$value = $converter->convert('[email protected]');
$this->assertIsString($value);
$this->assertStringNotContainsString('user1', $value);
$this->assertStringNotContainsString('@gmail.com', $value);
$this->assertStringEndsWith('@example.org', $value);
Expand All @@ -37,6 +38,7 @@ public function testCustomLength(): void
]);

$value = $converter->convert('[email protected]');
$this->assertIsString($value);
$this->assertStringEndsWith('@example.org', $value);

$parts = explode('@', $value);
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/Converter/Randomizer/RandomizeNumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ public function testConverter(): void
$this->assertSame('', $value);

$value = $converter->convert('+33601010101');
$this->assertIsString($value);
$this->assertStringStartsWith('+', $value);
$this->assertSame(12, strlen($value));

// Assert that the part without the "+" is still a numeric value
$valueWithoutPlus = substr($value, 1);
$this->assertTrue(is_numeric($valueWithoutPlus));
$this->assertIsNumeric($valueWithoutPlus);
$this->assertNotSame('33601010101', $valueWithoutPlus);
}
}
2 changes: 2 additions & 0 deletions tests/unit/Converter/Randomizer/RandomizeTextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function testConverter(): void
$this->assertSame('', $value);

$value = $converter->convert('user1');
$this->assertIsString($value);
$this->assertStringNotContainsString('user1', $value);
}

Expand All @@ -32,6 +33,7 @@ public function testCustomLength(): void
$converter = $this->createConverter(RandomizeText::class, ['min_length' => 10]);

$value = $converter->convert('user1');
$this->assertIsString($value);
$this->assertSame(10, strlen($value));
}

Expand Down
2 changes: 2 additions & 0 deletions tests/unit/Converter/Transformer/HashTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function testConverter(): void
$this->assertSame('', $value);

$value = $converter->convert('user1');
$this->assertIsString($value);
$this->assertSame(40, strlen($value));
}

Expand All @@ -33,6 +34,7 @@ public function testCustomAlgorithm(): void
$converter = $this->createConverter(Hash::class, ['algorithm' => 'sha256']);

$value = $converter->convert('user1');
$this->assertIsString($value);
$this->assertSame(64, strlen($value));
}

Expand Down

0 comments on commit 8ce617b

Please sign in to comment.