Skip to content

Commit

Permalink
code coverage fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrenkoAnton committed Feb 8, 2024
1 parent 5dc6a87 commit 72cb232
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 43 deletions.
8 changes: 4 additions & 4 deletions app/Core/Validators/PNValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace App\Core\Validators;

use App\Exceptions\AppException\PNException\InvalidPNFormatException;
use App\Exceptions\AppException\PNException\NumericPNException;
use App\Exceptions\AppException\PNException\NotNumericPNException;
use App\Exceptions\AppException\PNException\UnsupportedCodePNException;

use function config;
Expand All @@ -17,7 +17,7 @@
class PNValidator
{
/**
* @throws NumericPNException
* @throws NotNumericPNException
* @throws InvalidPNFormatException
* @throws UnsupportedCodePNException
*/
Expand All @@ -31,12 +31,12 @@ public function validate(string $pn): void
}

/**
* @throws NumericPNException
* @throws NotNumericPNException
*/
private function validateNumeric(string $pn): void
{
if (!is_numeric($pn)) {
throw new NumericPNException();
throw new NotNumericPNException();
}
}

Expand Down
13 changes: 13 additions & 0 deletions app/Exceptions/AppException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,17 @@

class AppException extends Exception
{
protected const INVALID_FORMAT_PN = 100;
protected const NOT_NUMERIC_PN = 101;
protected const UNSUPPORTED_CODE_PN = 102;

protected const INTERNAL_ERROR = 500;

protected function __construct(string $message, int $code)
{
parent::__construct(
message: $message,
code: $code,
);
}
}
7 changes: 7 additions & 0 deletions app/Exceptions/AppException/PNException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@

class PNException extends AppException
{
protected function __construct(string $message, int $code)
{
parent::__construct(
message: $message,
code: $code,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
namespace App\Exceptions\AppException\PNException;

use App\Exceptions\AppException\PNException;
use Throwable;

class InvalidPNFormatException extends PNException
final class InvalidPNFormatException extends PNException
{
public function __construct(int $code = 0, ?Throwable $previous = null)
public function __construct()
{
parent::__construct('Invalid phone number format', $code, $previous);
parent::__construct(
message: 'Invalid phone number format',
code: self::INVALID_FORMAT_PN,
);
}
}
18 changes: 18 additions & 0 deletions app/Exceptions/AppException/PNException/NotNumericPNException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace App\Exceptions\AppException\PNException;

use App\Exceptions\AppException\PNException;

final class NotNumericPNException extends PNException
{
public function __construct()
{
parent::__construct(
message: 'Not numeric phone number',
code: self::NOT_NUMERIC_PN,
);
}
}
16 changes: 0 additions & 16 deletions app/Exceptions/AppException/PNException/NumericPNException.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
namespace App\Exceptions\AppException\PNException;

use App\Exceptions\AppException\PNException;
use Throwable;

class UnsupportedCodePNException extends PNException
final class UnsupportedCodePNException extends PNException
{
public function __construct(int $code = 0, ?Throwable $previous = null)
public function __construct()
{
parent::__construct('Unsupported operator code', $code, $previous);
parent::__construct(
message: 'Unsupported operator code',
code: self::UNSUPPORTED_CODE_PN,
);
}
}
11 changes: 0 additions & 11 deletions app/Exceptions/AppException/UrlFormatterException.php

This file was deleted.

7 changes: 7 additions & 0 deletions app/Exceptions/Internal/InternalException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@

class InternalException extends AppException
{
public function __construct(string $message, int $code = self::INTERNAL_ERROR)
{
parent::__construct(
message: $message,
code: $code,
);
}
}
8 changes: 4 additions & 4 deletions tests/Feature/PNValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use App\Core\Validators\PNValidator;
use App\Exceptions\AppException;
use App\Exceptions\AppException\PNException\InvalidPNFormatException;
use App\Exceptions\AppException\PNException\NumericPNException;
use App\Exceptions\AppException\PNException\NotNumericPNException;
use App\Exceptions\AppException\PNException\UnsupportedCodePNException;
use Tests\TestCase;

Expand Down Expand Up @@ -57,9 +57,9 @@ public function testValidateThrowsException(string $pn, AppException $e): void
public static function dpInvalid(): array
{
return [
['qwerty', new NumericPNException()],
['q', new NumericPNException()],
['q71234567', new NumericPNException()],
['qwerty', new NotNumericPNException()],
['q', new NotNumericPNException()],
['q71234567', new NotNumericPNException()],

['0', new InvalidPNFormatException()],
['000', new InvalidPNFormatException()],
Expand Down

0 comments on commit 72cb232

Please sign in to comment.