mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-26 11:14:06 +00:00
81 - Ensuring Uniqueness
This commit is contained in:
@@ -6,6 +6,8 @@ class RandomOrderConfirmationNumberGenerator implements OrderConfirmationNumberG
|
||||
{
|
||||
public function generate()
|
||||
{
|
||||
return str_repeat('A', 24);
|
||||
$pool = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
|
||||
|
||||
return substr(str_shuffle(str_repeat($pool, 24)), 0, 24);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,4 +47,16 @@ class RandomOrderConfirmationNumberGeneratorTest extends TestCase
|
||||
$this->assertFalse(strpos($confirmationNumber, '0'));
|
||||
$this->assertFalse(strpos($confirmationNumber, 'O'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function confirmation_numbers_must_be_unique()
|
||||
{
|
||||
$generator = new RandomOrderConfirmationNumberGenerator;
|
||||
|
||||
$confirmationNumbers = array_map(function ($i) use ($generator) {
|
||||
return $generator->generate();
|
||||
}, range(1, 100));
|
||||
|
||||
$this->assertCount(100, array_unique($confirmationNumbers));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user