mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-27 07:45:07 +00:00
(rename unit folder back as Unit)
This commit is contained in:
64
tests/Unit/HashidsTicketCodeGeneratorTest.php
Normal file
64
tests/Unit/HashidsTicketCodeGeneratorTest.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Ticket;
|
||||
use Tests\TestCase;
|
||||
use App\HashidsTicketCodeGenerator;
|
||||
|
||||
class HashidsTicketCodeGeneratorTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
function ticket_codes_are_at_least_6_characters_long()
|
||||
{
|
||||
$ticketCodeGenerator = new HashidsTicketCodeGenerator('testsalt1');
|
||||
|
||||
$code = $ticketCodeGenerator->generateFor(new Ticket(['id' => 1]));
|
||||
|
||||
$this->assertTrue(strlen($code) >= 6);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function ticket_codes_can_only_contain_uppercase_letters()
|
||||
{
|
||||
$ticketCodeGenerator = new HashidsTicketCodeGenerator('testsalt1');
|
||||
|
||||
$code = $ticketCodeGenerator->generateFor(new Ticket(['id' => 1]));
|
||||
|
||||
$this->assertRegExp('/^[A-Z]+$/', $code);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function ticket_codes_for_the_same_ticket_id_are_the_same()
|
||||
{
|
||||
$ticketCodeGenerator = new HashidsTicketCodeGenerator('testsalt1');
|
||||
|
||||
$code1 = $ticketCodeGenerator->generateFor(new Ticket(['id' => 1]));
|
||||
$code2 = $ticketCodeGenerator->generateFor(new Ticket(['id' => 1]));
|
||||
|
||||
$this->assertEquals($code1, $code2);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function ticket_codes_for_different_ticket_ids_are_different()
|
||||
{
|
||||
$ticketCodeGenerator = new HashidsTicketCodeGenerator('testsalt1');
|
||||
|
||||
$code1 = $ticketCodeGenerator->generateFor(new Ticket(['id' => 1]));
|
||||
$code2 = $ticketCodeGenerator->generateFor(new Ticket(['id' => 2]));
|
||||
|
||||
$this->assertNotEquals($code1, $code2);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function ticket_codes_generated_with_different_salts_are_different()
|
||||
{
|
||||
$ticketCodeGenerator1 = new HashidsTicketCodeGenerator('testsalt1');
|
||||
$ticketCodeGenerator2 = new HashidsTicketCodeGenerator('testsalt2');
|
||||
|
||||
$code1 = $ticketCodeGenerator1->generateFor(new Ticket(['id' => 1]));
|
||||
$code2 = $ticketCodeGenerator2->generateFor(new Ticket(['id' => 1]));
|
||||
|
||||
$this->assertNotEquals($code1, $code2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user