Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests #216

Merged
merged 2 commits into from
Jan 31, 2023
Merged
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
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);
}
}