From 0d3265d7b6c8239124e2f5de0afc78486f7b28ff Mon Sep 17 00:00:00 2001 From: Meritoo Date: Sun, 4 Apr 2021 23:26:35 +0200 Subject: [PATCH] Increase code coverage of the BaseTestCaseTrait --- .../Base/BaseTestCaseTrait/SimpleTestCase.php | 4 ++ .../Test/Base/BaseTestCaseTraitTest.php | 38 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/tests/Traits/Test/Base/BaseTestCaseTrait/SimpleTestCase.php b/tests/Traits/Test/Base/BaseTestCaseTrait/SimpleTestCase.php index 191beb4..02258b6 100644 --- a/tests/Traits/Test/Base/BaseTestCaseTrait/SimpleTestCase.php +++ b/tests/Traits/Test/Base/BaseTestCaseTrait/SimpleTestCase.php @@ -19,4 +19,8 @@ use Meritoo\Common\Traits\Test\Base\BaseTestCaseTrait; class SimpleTestCase { use BaseTestCaseTrait; + + private function thePrivateMethod(): void + { + } } diff --git a/tests/Traits/Test/Base/BaseTestCaseTraitTest.php b/tests/Traits/Test/Base/BaseTestCaseTraitTest.php index a74e6fd..7b9bf4b 100644 --- a/tests/Traits/Test/Base/BaseTestCaseTraitTest.php +++ b/tests/Traits/Test/Base/BaseTestCaseTraitTest.php @@ -11,8 +11,13 @@ declare(strict_types=1); namespace Meritoo\Test\Common\Traits\Test\Base; use DateTime; +use Meritoo\Common\Exception\Reflection\ClassWithoutConstructorException; +use Meritoo\Common\Exception\Type\UnknownOopVisibilityTypeException; use Meritoo\Common\Test\Base\BaseTestCase; +use Meritoo\Common\Traits\Test\Base\BaseTestCaseTrait; +use Meritoo\Common\Type\OopVisibilityType; use Meritoo\Test\Common\Traits\Test\Base\BaseTestCaseTrait\SimpleTestCase; +use ReflectionMethod; use stdClass; /** @@ -26,6 +31,39 @@ use stdClass; */ class BaseTestCaseTraitTest extends BaseTestCase { + use BaseTestCaseTrait; + + public function testAssertMethodVisibility(): void + { + $method = new ReflectionMethod(SimpleTestCase::class, 'assertMethodVisibility'); + static::assertMethodVisibility($method, OopVisibilityType::IS_PROTECTED); + } + + public function testAssertMethodVisibilityUsingIncorrectVisibility(): void + { + $this->expectException(UnknownOopVisibilityTypeException::class); + + $method = new ReflectionMethod(SimpleTestCase::class, 'assertMethodVisibility'); + static::assertMethodVisibility($method, '4'); + } + + public function testAssertMethodVisibilityUsingPrivate(): void + { + $method = new ReflectionMethod(SimpleTestCase::class, 'thePrivateMethod'); + static::assertMethodVisibility($method, OopVisibilityType::IS_PRIVATE); + } + + public function testAssertConstructorVisibilityAndArgumentsUsingClassWithoutConstructor(): void + { + $this->expectException(ClassWithoutConstructorException::class); + static::assertConstructorVisibilityAndArguments(SimpleTestCase::class, OopVisibilityType::IS_PUBLIC); + } + + public function testAssertHasNoConstructor(): void + { + static::assertHasNoConstructor(SimpleTestCase::class); + } + public function testProvideEmptyValue(): void { $testCase = new SimpleTestCase();