Exceptions > create instance of exception using static "create()" method (instead of constructor)

This commit is contained in:
Meritoo
2018-07-02 08:52:01 +02:00
parent 9342f0e87e
commit 834b24f348
35 changed files with 139 additions and 105 deletions

View File

@@ -23,7 +23,7 @@ class UnknownTypeExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(UnknownTestTypeException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
static::assertConstructorVisibilityAndArguments(UnknownTestTypeException::class, OopVisibilityType::IS_PUBLIC, 3);
}
public function testWithoutException()
@@ -60,13 +60,17 @@ class TestType extends BaseType
class UnknownTestTypeException extends UnknownTypeException
{
/**
* Class constructor
* Creates exception
*
* @param int|string $unknownType The unknown type of something (for testing purposes)
* @param string $unknownType The unknown type of something (for testing purposes)
* @return UnknownTestTypeException
*/
public function __construct($unknownType)
public static function createException($unknownType)
{
parent::__construct($unknownType, new TestType(), 'type of something used for testing');
/* @var UnknownTestTypeException $exception */
$exception = parent::create($unknownType, new TestType(), 'type of something used for testing');
return $exception;
}
}

View File

@@ -9,7 +9,7 @@
namespace Meritoo\Common\Test\Exception\Date;
use Generator;
use Meritoo\Common\Exception\Date\UnknownDatePartTypeException;
use Meritoo\Common\Exception\Type\UnknownDatePartTypeException;
use Meritoo\Common\Test\Base\BaseTestCase;
use Meritoo\Common\Type\DatePartType;
use Meritoo\Common\Type\OopVisibilityType;
@@ -24,7 +24,7 @@ class UnknownDatePartTypeExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(UnknownDatePartTypeException::class, OopVisibilityType::IS_PUBLIC, 2, 2);
static::assertConstructorVisibilityAndArguments(UnknownDatePartTypeException::class, OopVisibilityType::IS_PUBLIC, 3);
}
/**
@@ -34,9 +34,9 @@ class UnknownDatePartTypeExceptionTest extends BaseTestCase
*
* @dataProvider provideDatePartAndValue
*/
public function testConstructorMessage($unknownDatePart, $value, $expectedMessage)
public function testMessage($unknownDatePart, $value, $expectedMessage)
{
$exception = new UnknownDatePartTypeException($unknownDatePart, $value);
$exception = UnknownDatePartTypeException::createException($unknownDatePart, $value);
static::assertEquals($expectedMessage, $exception->getMessage());
}

View File

@@ -23,7 +23,7 @@ class EmptyFileExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(EmptyFileException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
static::assertConstructorVisibilityAndArguments(EmptyFileException::class, OopVisibilityType::IS_PUBLIC, 3);
}
/**
@@ -32,9 +32,9 @@ class EmptyFileExceptionTest extends BaseTestCase
*
* @dataProvider providePathOfFile
*/
public function testConstructorMessage($emptyFilePath, $expectedMessage)
public function testMessage($emptyFilePath, $expectedMessage)
{
$exception = new EmptyFileException($emptyFilePath);
$exception = EmptyFileException::create($emptyFilePath);
static::assertEquals($expectedMessage, $exception->getMessage());
}

View File

@@ -22,12 +22,12 @@ class EmptyFilePathExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(EmptyFilePathException::class, OopVisibilityType::IS_PUBLIC);
static::assertConstructorVisibilityAndArguments(EmptyFilePathException::class, OopVisibilityType::IS_PUBLIC, 3);
}
public function testConstructorMessage()
{
$exception = new EmptyFilePathException();
$exception = EmptyFilePathException::create();
static::assertEquals('Path of the file is empty. Did you provide path of proper file?', $exception->getMessage());
}
}

View File

@@ -23,7 +23,7 @@ class NotExistingFileExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(NotExistingFileException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
static::assertConstructorVisibilityAndArguments(NotExistingFileException::class, OopVisibilityType::IS_PUBLIC, 3);
}
/**
@@ -34,7 +34,7 @@ class NotExistingFileExceptionTest extends BaseTestCase
*/
public function testConstructorMessage($notExistingFilePath, $expectedMessage)
{
$exception = new NotExistingFileException($notExistingFilePath);
$exception = NotExistingFileException::create($notExistingFilePath);
static::assertEquals($expectedMessage, $exception->getMessage());
}

View File

@@ -23,7 +23,7 @@ class DisabledMethodExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(DisabledMethodException::class, OopVisibilityType::IS_PUBLIC, 2, 1);
static::assertConstructorVisibilityAndArguments(DisabledMethodException::class, OopVisibilityType::IS_PUBLIC, 3);
}
/**
@@ -36,7 +36,7 @@ class DisabledMethodExceptionTest extends BaseTestCase
*/
public function testConstructorMessage($disabledMethod, $alternativeMethod, $expectedMessage)
{
$exception = new DisabledMethodException($disabledMethod, $alternativeMethod);
$exception = DisabledMethodException::create($disabledMethod, $alternativeMethod);
static::assertEquals($expectedMessage, $exception->getMessage());
}

View File

@@ -23,7 +23,7 @@ class CannotResolveClassNameExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(CannotResolveClassNameException::class, OopVisibilityType::IS_PUBLIC, 2, 1);
static::assertConstructorVisibilityAndArguments(CannotResolveClassNameException::class, OopVisibilityType::IS_PUBLIC, 3);
}
/**
@@ -37,7 +37,7 @@ class CannotResolveClassNameExceptionTest extends BaseTestCase
*/
public function testConstructorMessage($source, $forClass, $expectedMessage)
{
$exception = new CannotResolveClassNameException($source, $forClass);
$exception = CannotResolveClassNameException::create($source, $forClass);
static::assertEquals($expectedMessage, $exception->getMessage());
}

View File

@@ -23,7 +23,7 @@ class MissingChildClassesExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(MissingChildClassesException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
static::assertConstructorVisibilityAndArguments(MissingChildClassesException::class, OopVisibilityType::IS_PUBLIC, 3);
}
/**
@@ -35,7 +35,7 @@ class MissingChildClassesExceptionTest extends BaseTestCase
*/
public function testConstructorMessage($parentClass, $expectedMessage)
{
$exception = new MissingChildClassesException($parentClass);
$exception = MissingChildClassesException::create($parentClass);
static::assertEquals($expectedMessage, $exception->getMessage());
}

View File

@@ -23,7 +23,7 @@ class TooManyChildClassesExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(TooManyChildClassesException::class, OopVisibilityType::IS_PUBLIC, 2, 2);
static::assertConstructorVisibilityAndArguments(TooManyChildClassesException::class, OopVisibilityType::IS_PUBLIC, 3);
}
/**
@@ -36,7 +36,7 @@ class TooManyChildClassesExceptionTest extends BaseTestCase
*/
public function testConstructorMessage($parentClass, array $childClasses, $expectedMessage)
{
$exception = new TooManyChildClassesException($parentClass, $childClasses);
$exception = TooManyChildClassesException::create($parentClass, $childClasses);
static::assertEquals($expectedMessage, $exception->getMessage());
}

View File

@@ -23,7 +23,7 @@ class IncorrectColorHexLengthExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(IncorrectColorHexLengthException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
static::assertConstructorVisibilityAndArguments(IncorrectColorHexLengthException::class, OopVisibilityType::IS_PUBLIC, 3);
}
/**
@@ -34,7 +34,7 @@ class IncorrectColorHexLengthExceptionTest extends BaseTestCase
*/
public function testConstructorMessage($color, $expectedMessage)
{
$exception = new IncorrectColorHexLengthException($color);
$exception = IncorrectColorHexLengthException::create($color);
static::assertEquals($expectedMessage, $exception->getMessage());
}

View File

@@ -10,7 +10,6 @@ namespace Meritoo\Common\Test\Exception\Regex;
use Generator;
use Meritoo\Common\Exception\Regex\InvalidColorHexValueException;
use Meritoo\Common\Exception\Type\UnknownOopVisibilityTypeException;
use Meritoo\Common\Test\Base\BaseTestCase;
use Meritoo\Common\Type\OopVisibilityType;
@@ -22,12 +21,9 @@ use Meritoo\Common\Type\OopVisibilityType;
*/
class InvalidColorHexValueExceptionTest extends BaseTestCase
{
/**
* @throws UnknownOopVisibilityTypeException
*/
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(InvalidColorHexValueException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
static::assertConstructorVisibilityAndArguments(InvalidColorHexValueException::class, OopVisibilityType::IS_PUBLIC, 3);
}
/**
@@ -38,7 +34,7 @@ class InvalidColorHexValueExceptionTest extends BaseTestCase
*/
public function testConstructorMessage($color, $expectedMessage)
{
$exception = new InvalidColorHexValueException($color);
$exception = InvalidColorHexValueException::create($color);
static::assertEquals($expectedMessage, $exception->getMessage());
}

View File

@@ -10,7 +10,6 @@ namespace Meritoo\Common\Test\Exception\Regex;
use Generator;
use Meritoo\Common\Exception\Regex\InvalidHtmlAttributesException;
use Meritoo\Common\Exception\Type\UnknownOopVisibilityTypeException;
use Meritoo\Common\Test\Base\BaseTestCase;
use Meritoo\Common\Type\OopVisibilityType;
@@ -22,12 +21,9 @@ use Meritoo\Common\Type\OopVisibilityType;
*/
class InvalidHtmlAttributesExceptionTest extends BaseTestCase
{
/**
* @throws UnknownOopVisibilityTypeException
*/
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(InvalidHtmlAttributesException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
static::assertConstructorVisibilityAndArguments(InvalidHtmlAttributesException::class, OopVisibilityType::IS_PUBLIC, 3);
}
/**
@@ -38,7 +34,7 @@ class InvalidHtmlAttributesExceptionTest extends BaseTestCase
*/
public function testConstructorMessage($htmlAttributes, $expectedMessage)
{
$exception = new InvalidHtmlAttributesException($htmlAttributes);
$exception = InvalidHtmlAttributesException::create($htmlAttributes);
static::assertEquals($expectedMessage, $exception->getMessage());
}

View File

@@ -23,7 +23,7 @@ class InvalidUrlExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(InvalidUrlException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
static::assertConstructorVisibilityAndArguments(InvalidUrlException::class, OopVisibilityType::IS_PUBLIC, 3);
}
/**
@@ -34,7 +34,7 @@ class InvalidUrlExceptionTest extends BaseTestCase
*/
public function testConstructorMessage($url, $expectedMessage)
{
$exception = new InvalidUrlException($url);
$exception = InvalidUrlException::create($url);
static::assertEquals($expectedMessage, $exception->getMessage());
}

View File

@@ -24,7 +24,7 @@ class UnknownOopVisibilityTypeExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(UnknownOopVisibilityTypeException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
static::assertConstructorVisibilityAndArguments(UnknownOopVisibilityTypeException::class, OopVisibilityType::IS_PUBLIC, 3);
}
/**
@@ -35,7 +35,7 @@ class UnknownOopVisibilityTypeExceptionTest extends BaseTestCase
*/
public function testConstructorMessage($unknownType, $expectedMessage)
{
$exception = new UnknownOopVisibilityTypeException($unknownType);
$exception = UnknownOopVisibilityTypeException::createException($unknownType);
static::assertEquals($expectedMessage, $exception->getMessage());
}