Skip to content

Commit

Permalink
Cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
axlon committed Dec 24, 2024
1 parent 572ee02 commit f3bc709
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 180 deletions.
48 changes: 0 additions & 48 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -84,54 +84,6 @@ parameters:
count: 1
path: src/ValidationServiceProvider.php

-
message: '#^Cannot call method make\(\) on Illuminate\\Foundation\\Application\|null\.$#'
identifier: method.nonObject
count: 1
path: tests/Integration/FacadeTest.php

-
message: '#^Cannot call method all\(\) on mixed\.$#'
identifier: method.nonObject
count: 6
path: tests/Integration/PostalCodeForTest.php

-
message: '#^Cannot call method errors\(\) on mixed\.$#'
identifier: method.nonObject
count: 6
path: tests/Integration/PostalCodeForTest.php

-
message: '#^Cannot call method make\(\) on Illuminate\\Foundation\\Application\|null\.$#'
identifier: method.nonObject
count: 7
path: tests/Integration/PostalCodeForTest.php

-
message: '#^Cannot call method make\(\) on mixed\.$#'
identifier: method.nonObject
count: 7
path: tests/Integration/PostalCodeForTest.php

-
message: '#^Cannot call method passes\(\) on mixed\.$#'
identifier: method.nonObject
count: 6
path: tests/Integration/PostalCodeForTest.php

-
message: '#^Cannot call method validate\(\) on mixed\.$#'
identifier: method.nonObject
count: 1
path: tests/Integration/PostalCodeForTest.php

-
message: '#^Parameter \#2 \$haystack of static method PHPUnit\\Framework\\Assert\:\:assertContains\(\) expects iterable, mixed given\.$#'
identifier: argument.type
count: 3
path: tests/Integration/PostalCodeForTest.php

-
message: '#^Cannot call method all\(\) on mixed\.$#'
identifier: method.nonObject
Expand Down
7 changes: 1 addition & 6 deletions tests/Integration/FacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@

class FacadeTest extends TestCase
{
/**
* Test if the facade properly proxies the pattern matcher instance.
*
* @return void
*/
public function testFacadesProxiesPatternMatcher(): void
{
self::assertSame($this->app->make('postal_codes'), PostalCodes::getFacadeRoot());
self::assertSame($this->app?->make('postal_codes'), PostalCodes::getFacadeRoot());
}
}
43 changes: 8 additions & 35 deletions tests/Integration/PostalCodeForTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@

namespace Tests\Integration;

use Illuminate\Support\Facades\Validator;
use InvalidArgumentException;
use Tests\TestCase;

class PostalCodeForTest extends TestCase
{
/**
* Test if the 'postal_code_for' rule fails on invalid countries.
*
* @return void
*/
public function testValidationFailsInvalidCountry(): void
{
$validator = $this->app->make('validator')->make(
$validator = Validator::make(
['postal_code' => '1234 AB', 'country' => 'not-a-country'],
['postal_code' => 'postal_code_for:country'],
);
Expand All @@ -25,14 +21,9 @@ public function testValidationFailsInvalidCountry(): void
self::assertContains('validation.postal_code_for', $validator->errors()->all());
}

/**
* Test if the 'postal_code_for' rule fails invalid input.
*
* @return void
*/
public function testValidationFailsInvalidPostalCode(): void
{
$validator = $this->app->make('validator')->make(
$validator = Validator::make(
['postal_code' => 'not-a-postal-code', 'country' => 'NL'],
['postal_code' => 'postal_code_for:country'],
);
Expand All @@ -42,14 +33,11 @@ public function testValidationFailsInvalidPostalCode(): void
}

/**
* Test if the 'postal_code' rule fails null input.
*
* @return void
* @link https://github.com/axlon/laravel-postal-code-validation/issues/23
*/
public function testValidationFailsNullPostalCode(): void
{
$validator = $this->app->make('validator')->make(
$validator = Validator::make(
['postal_code' => null, 'country' => 'DE'],
['postal_code' => 'postal_code_for:country'],
);
Expand All @@ -60,7 +48,7 @@ public function testValidationFailsNullPostalCode(): void

public function testValidationPassesIfAllFieldsAreMissing(): void
{
$validator = $this->app->make('validator')->make(
$validator = Validator::make(
['postal_code' => '1234 AB'],
['postal_code' => 'postal_code_for:country'],
);
Expand All @@ -69,14 +57,9 @@ public function testValidationPassesIfAllFieldsAreMissing(): void
self::assertEmpty($validator->errors()->all());
}

/**
* Test if the 'postal_code_for' rule ignores references that aren't present.
*
* @return void
*/
public function testValidationIgnoresMissingFields(): void
{
$validator = $this->app->make('validator')->make(
$validator = Validator::make(
['postal_code' => '1234 AB', 'empty' => '', 'null' => null, 'country' => 'NL'],
['postal_code' => 'postal_code_for:empty,missing,null,country'],
);
Expand All @@ -85,14 +68,9 @@ public function testValidationIgnoresMissingFields(): void
self::assertEmpty($validator->errors()->all());
}

/**
* Test if the 'postal_code_for' rule passes valid input.
*
* @return void
*/
public function testValidationPassesValidPostalCode(): void
{
$validator = $this->app->make('validator')->make(
$validator = Validator::make(
['postal_code' => '1234 AB', 'country' => 'NL'],
['postal_code' => 'postal_code_for:country'],
);
Expand All @@ -101,14 +79,9 @@ public function testValidationPassesValidPostalCode(): void
self::assertEmpty($validator->errors()->all());
}

/**
* Test if an exception is thrown when calling the 'postal_code' rule without arguments.
*
* @return void
*/
public function testValidationThrowsWithoutParameters(): void
{
$validator = $this->app->make('validator')->make(
$validator = Validator::make(
['postal_code' => '1234 AB'],
['postal_code' => 'postal_code_for'],
);
Expand Down
23 changes: 0 additions & 23 deletions tests/Integration/PostalCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@

class PostalCodeTest extends TestCase
{
/**
* Test if the 'postal_code' rule fails on invalid countries.
*
* @return void
*/
public function testValidationFailsInvalidCountry(): void
{
$validator = $this->app->make('validator')->make(
Expand All @@ -25,11 +20,6 @@ public function testValidationFailsInvalidCountry(): void
self::assertContains('validation.postal_code', $validator->errors()->all());
}

/**
* Test if the 'postal_code' rule fails invalid input.
*
* @return void
*/
public function testValidationFailsInvalidPostalCode(): void
{
$validator = $this->app->make('validator')->make(
Expand All @@ -42,9 +32,6 @@ public function testValidationFailsInvalidPostalCode(): void
}

/**
* Test if the 'postal_code' rule fails null input.
*
* @return void
* @link https://github.com/axlon/laravel-postal-code-validation/issues/23
*/
public function testValidationFailsNullPostalCode(): void
Expand All @@ -58,11 +45,6 @@ public function testValidationFailsNullPostalCode(): void
self::assertContains('validation.postal_code', $validator->errors()->all());
}

/**
* Test if the 'postal_code' rule passes valid input.
*
* @return void
*/
public function testValidationPassesValidPostalCode(): void
{
$validator = $this->app->make('validator')->make(
Expand All @@ -74,11 +56,6 @@ public function testValidationPassesValidPostalCode(): void
self::assertEmpty($validator->errors()->all());
}

/**
* Test if an exception is thrown when calling the 'postal_code' rule without arguments.
*
* @return void
*/
public function testValidationThrowsWithoutParameters(): void
{
$validator = $this->app->make('validator')->make(
Expand Down
38 changes: 0 additions & 38 deletions tests/Integration/PostalCodeWithTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@

class PostalCodeWithTest extends TestCase
{
/**
* Test if the 'postal_code_with' rule fails on invalid countries.
*
* @return void
*/
public function testValidationFailsInvalidCountry(): void
{
$validator = $this->app->make('validator')->make(
Expand All @@ -25,11 +20,6 @@ public function testValidationFailsInvalidCountry(): void
self::assertContains('validation.postal_code_with', $validator->errors()->all());
}

/**
* Test if the 'postal_code_with' rule fails invalid input.
*
* @return void
*/
public function testValidationFailsInvalidPostalCode(): void
{
$validator = $this->app->make('validator')->make(
Expand All @@ -41,11 +31,6 @@ public function testValidationFailsInvalidPostalCode(): void
self::assertContains('validation.postal_code_with', $validator->errors()->all());
}

/**
* Test if the 'postal_code_with' rule fails invalid input.
*
* @return void
*/
public function testValidationFailsInvalidPostalCodeInArray(): void
{
$validator = $this->app->make('validator')->make(
Expand All @@ -58,9 +43,6 @@ public function testValidationFailsInvalidPostalCodeInArray(): void
}

/**
* Test if the 'postal_code' rule fails null input.
*
* @return void
* @link https://github.com/axlon/laravel-postal-code-validation/issues/23
*/
public function testValidationFailsNullPostalCode(): void
Expand All @@ -85,11 +67,6 @@ public function testValidationPassesIfAllFieldsAreMissing(): void
self::assertEmpty($validator->errors()->all());
}

/**
* Test if the 'postal_code_with' rule ignores references that aren't present.
*
* @return void
*/
public function testValidationIgnoresMissingFields(): void
{
$validator = $this->app->make('validator')->make(
Expand All @@ -112,11 +89,6 @@ public function testValidationIgnoresMissingFieldsFailing(): void
self::assertContains('validation.postal_code_with', $validator->errors()->all());
}

/**
* Test if the 'postal_code_with' rule passes valid input.
*
* @return void
*/
public function testValidationPassesValidPostalCode(): void
{
$validator = $this->app->make('validator')->make(
Expand All @@ -128,11 +100,6 @@ public function testValidationPassesValidPostalCode(): void
self::assertEmpty($validator->errors()->all());
}

/**
* Test if the 'postal_code_with' rule passes valid input.
*
* @return void
*/
public function testValidationPassesValidPostalCodeInArray(): void
{
$validator = $this->app->make('validator')->make(
Expand All @@ -144,11 +111,6 @@ public function testValidationPassesValidPostalCodeInArray(): void
self::assertEmpty($validator->errors()->all());
}

/**
* Test if an exception is thrown when calling the 'postal_code' rule without arguments.
*
* @return void
*/
public function testValidationThrowsWithoutParameters(): void
{
$validator = $this->app->make('validator')->make(
Expand Down
10 changes: 0 additions & 10 deletions tests/Integration/ReplacerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@

class ReplacerTest extends TestCase
{
/**
* Test the error replacer for the 'postal_code' rule.
*
* @return void
*/
public function testPostalCodeReplacer(): void
{
$locale = is_callable([$this->app, 'getLocale']) ? $this->app->getLocale() : 'en';
Expand All @@ -33,11 +28,6 @@ public function testPostalCodeReplacer(): void
);
}

/**
* Test the error replacer for the 'postal_code_for' rule.
*
* @return void
*/
public function testPostalCodeForReplacer(): void
{
$locale = is_callable([$this->app, 'getLocale']) ? $this->app->getLocale() : 'en';
Expand Down
25 changes: 6 additions & 19 deletions tests/Unit/PostalCodeExamplesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,18 @@

class PostalCodeExamplesTest extends TestCase
{
/**
* The postal code examples.
*
* @var \Axlon\PostalCodeValidation\Support\PostalCodeExamples
*/
protected $examples;

/**
* @inheritDoc
*/
protected function setUp(): void
{
$this->examples = new PostalCodeExamples();
}

/**
* Test the retrieval of valid postal code examples.
*
* @return void
*/
public function testExampleRetrieval(): void
{
self::assertEquals('1234 AB', $this->examples->get('NL'));
self::assertEquals('4000', $this->examples->get('be')); # Lowercase country code
self::assertNull($this->examples->get('GH')); # Country code without a pattern
self::assertNull($this->examples->get('XX')); # Non-existent country code
$examples = new PostalCodeExamples();

self::assertEquals('1234 AB', $examples->get('NL'));
self::assertEquals('4000', $examples->get('be')); // Lowercase country code
self::assertNull($examples->get('GH')); // Country code without a pattern
self::assertNull($examples->get('XX')); // Non-existent country code
}
}
Loading

0 comments on commit f3bc709

Please sign in to comment.