Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Propaganistas authored Jan 31, 2023
1 parent b2e1c55 commit db0a93c
Showing 1 changed file with 58 additions and 22 deletions.
80 changes: 58 additions & 22 deletions tests/PhoneNumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,32 @@
class PhoneNumberTest extends TestCase
{
/** @test */
public function it_can_construct()
public function it_constructs_without_country()
{
$object = new PhoneNumber('012345678');
$this->assertInstanceOf(PhoneNumber::class, $object);

}

/** @test */
public function it_constructs_with_string_country()
{
$object = new PhoneNumber('012345678', 'BE');
$this->assertInstanceOf(PhoneNumber::class, $object);

}

/** @test */
public function it_constructs_with_array_country()
{
$object = new PhoneNumber('012345678', ['BE', 'NL']);
$this->assertInstanceOf(PhoneNumber::class, $object);
}

/** @test */
public function it_constructs_with_null_country()
{
$object = new PhoneNumber('012345678', null);
$this->assertInstanceOf(PhoneNumber::class, $object);
}

/** @test */
public function it_returns_the_raw_number()
Expand Down Expand Up @@ -404,25 +419,6 @@ public function it_returns_empty_string_when_null_is_cast_to_string()
$this->assertEquals('', (string) $object);
}

/** @test */
public function it_has_a_helper_function()
{
// Test international landline number without country and format parameters.
$actual = phone('+32 12 34 56 78');
$expected = new PhoneNumber('012345678', 'BE');
$this->assertEquals($expected, (string) $actual);

// Test landline number without format parameter.
$actual = phone('012345678', 'BE');
$expected = new PhoneNumber('012345678', 'BE');
$this->assertEquals($expected, $actual);

// Test landline number with format parameter.
$actual = phone('012345678', 'BE', PhoneNumberFormat::NATIONAL);
$expected = '012 34 56 78';
$this->assertEquals($expected, $actual);
}

/** @test */
public function it_gets_the_exceptions_number()
{
Expand Down Expand Up @@ -489,4 +485,44 @@ public function it_doesnt_throw_for_invalid_numbers_when_checking_inequality()
$this->assertTrue($object->notEquals('1234'));
$this->assertTrue($object->notEquals('012345678', 'NL'));
}

/** @test */
public function helper_function_constructs_without_country()
{
$actual = phone('+32 12 34 56 78');
$expected = new PhoneNumber('+32 12 34 56 78');
$this->assertEquals($expected, $actual);
}

/** @test */
public function helper_function_constructs_with_string_country()
{
$actual = phone('012 34 56 78', 'BE');
$expected = new PhoneNumber('012 34 56 78', 'BE');
$this->assertEquals($expected, $actual);
}

/** @test */
public function helper_function_constructs_with_array_country()
{
$actual = phone('012 34 56 78', ['BE', 'NL']);
$expected = new PhoneNumber('012 34 56 78', ['BE', 'NL']);
$this->assertEquals($expected, $actual);
}

/** @test */
public function helper_function_constructs_with_null_country()
{
$actual = phone('+32 12 34 56 78', null);
$expected = new PhoneNumber('+32 12 34 56 78', null);
$this->assertEquals($expected, $actual);
}

/** @test */
public function helper_function_formats()
{
$actual = phone('012345678', 'BE', PhoneNumberFormat::NATIONAL);
$expected = '012 34 56 78';
$this->assertEquals($expected, $actual);
}
}

0 comments on commit db0a93c

Please sign in to comment.