Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion tests/C0/ProcessRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,36 @@

namespace Tests\C0;

use App\ProcessRunner;
use PHPUnit\Framework\TestCase;

class ProcessRunnerTest extends TestCase
{
// TODO: write 2 tests to coverage 100% code
public function test_return_2_WHEN_pass_case_1_case_3()
{
$sut = new ProcessRunner;

$actualResult = $sut->run(12, 1);

$expectedResult = 2;
$this->assertEquals($expectedResult, $actualResult);
$this->assertTrue($sut->wasProcess1Called());
$this->assertTrue($sut->wasProcess3Called());
$this->assertFalse($sut->wasProcess2Called());
$this->assertFalse($sut->wasProcess4Called());
}

public function test_return_2_WHEN_pass_case_2_case_4()
{
$sut = new ProcessRunner;

$actualResult = $sut->run(1, 1);

$expectedResult = 2;
$this->assertEquals($expectedResult, $actualResult);
$this->assertTrue($sut->wasProcess2Called());
$this->assertTrue($sut->wasProcess4Called());
$this->assertFalse($sut->wasProcess1Called());
$this->assertFalse($sut->wasProcess3Called());
}
}
60 changes: 59 additions & 1 deletion tests/C0/UsernameValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,67 @@

namespace Tests\C0;

use App\UsernameValidation;
use PHPUnit\Framework\TestCase;

class UsernameValidationTest extends TestCase
{
// TODO: write 6 tests to coverage 100% code
public function test_return_false_when_user_name_lt_min_length()
{
$sut = new UsernameValidation;

$actualResult = $sut->isValid('');

$this->assertFalse($actualResult);
$this->assertEquals('Minimum length is 1', $sut->getMessage());
}

public function test_return_false_when_user_name_gt_max_length()
{
$sut = new UsernameValidation;

$actualResult = $sut->isValid('012345678901234567890');

$this->assertFalse($actualResult);
$this->assertEquals('Maximum length is 20', $sut->getMessage());
}

public function test_return_false_when_user_name_not_allow_dash_begin_or_end()
{
$sut = new UsernameValidation;

$actualResult = $sut->isValid('-1234');

$this->assertFalse($actualResult);
$this->assertEquals('- cannot appear at begin or end of name', $sut->getMessage());
}

public function test_return_false_when_user_name_not_allow_double_dash()
{
$sut = new UsernameValidation;

$actualResult = $sut->isValid('1--2');

$this->assertFalse($actualResult);
$this->assertEquals('Only single - is allowed', $sut->getMessage());
}

public function test_return_false_when_user_name_not_allow_invalid_character()
{
$sut = new UsernameValidation;

$actualResult = $sut->isValid('@');

$this->assertFalse($actualResult);
$this->assertEquals('Invalid character. Use only letters, digits and -', $sut->getMessage());
}

public function test_return_true_when_user_name_valid()
{
$sut = new UsernameValidation;

$actualResult = $sut->isValid('lethibaongan');

$this->assertTrue($actualResult);
}
}