mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-26 18:45:01 +00:00
63 lines
1.7 KiB
PHP
63 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use Tests\TestCase;
|
|
use App\RandomOrderConfirmationNumberGenerator;
|
|
|
|
class RandomOrderConfirmationNumberGeneratorTest extends TestCase
|
|
{
|
|
// Must be 24 characters long
|
|
// Can only contain uppercase letters and numbers
|
|
// Cannot contain ambiguous characters
|
|
// All order confirmation numbers must be unique
|
|
//
|
|
// ABCDEFGHJKLMNPQRSTUVWXYZ
|
|
// 23456789
|
|
|
|
/** @test */
|
|
function must_be_24_characters_long()
|
|
{
|
|
$generator = new RandomOrderConfirmationNumberGenerator;
|
|
|
|
$confirmationNumber = $generator->generate();
|
|
|
|
$this->assertEquals(24, strlen($confirmationNumber));
|
|
}
|
|
|
|
/** @test */
|
|
function can_only_contain_uppercase_letters_and_numbers()
|
|
{
|
|
$generator = new RandomOrderConfirmationNumberGenerator;
|
|
|
|
$confirmationNumber = $generator->generate();
|
|
|
|
$this->assertRegExp('/^[A-Z0-9]+$/', $confirmationNumber);
|
|
}
|
|
|
|
/** @test */
|
|
function cannot_contain_ambiguous_characters()
|
|
{
|
|
$generator = new RandomOrderConfirmationNumberGenerator;
|
|
|
|
$confirmationNumber = $generator->generate();
|
|
|
|
$this->assertFalse(strpos($confirmationNumber, '1'));
|
|
$this->assertFalse(strpos($confirmationNumber, 'I'));
|
|
$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));
|
|
}
|
|
}
|