From 36ddb326b96e6fe4104237a90705394e2e651e87 Mon Sep 17 00:00:00 2001 From: Meritoo Date: Tue, 31 Oct 2017 21:27:42 +0100 Subject: [PATCH] Tests - increase code coverage --- src/Test/Base/BaseTypeTestCase.php | 6 ++ tests/Test/Base/BaseTestCaseTest.php | 156 +++++++++++++++++++++++++++ tests/Type/Base/BaseTypeTest.php | 9 +- 3 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 tests/Test/Base/BaseTestCaseTest.php diff --git a/src/Test/Base/BaseTypeTestCase.php b/src/Test/Base/BaseTypeTestCase.php index e1b5d45..b945522 100644 --- a/src/Test/Base/BaseTypeTestCase.php +++ b/src/Test/Base/BaseTypeTestCase.php @@ -1,5 +1,11 @@ + * @copyright Meritoo.pl + */ +class BaseTestCaseTest extends BaseTestCase +{ + public function testConstructor() + { + static::assertConstructorVisibilityAndArguments(BaseTestCase::class, OopVisibilityType::IS_PUBLIC, 3); + } + + public function testProvideEmptyValue() + { + $elements = [ + [''], + [' '], + [null], + [0], + [false], + [[]], + ]; + + $generator = (new SimpleTestCase())->provideEmptyValue(); + self::assertEquals($elements, GeneratorUtility::getGeneratorElements($generator)); + } + + public function testProvideBooleanValue() + { + $elements = [ + [false], + [true], + ]; + + $generator = (new SimpleTestCase())->provideBooleanValue(); + self::assertEquals($elements, GeneratorUtility::getGeneratorElements($generator)); + } + + public function testProvideDateTimeInstance() + { + $elements = [ + [new DateTime()], + [new DateTime('yesterday')], + [new DateTime('now')], + [new DateTime('tomorrow')], + ]; + + $generator = (new SimpleTestCase())->provideDateTimeInstance(); + self::assertEquals($elements, GeneratorUtility::getGeneratorElements($generator)); + } + + public function testProvideDateTimeRelativeFormat() + { + $elements = [ + ['now'], + ['yesterday'], + ['tomorrow'], + ['back of 10'], + ['front of 10'], + ['last day of February'], + ['first day of next month'], + ['last day of previous month'], + ['last day of next month'], + ['Y-m-d'], + ['Y-m-d 10:00'], + ]; + + $generator = (new SimpleTestCase())->provideDateTimeRelativeFormat(); + self::assertEquals($elements, GeneratorUtility::getGeneratorElements($generator)); + } + + public function testProvideNotExistingFilePath() + { + $elements = [ + ['lets-test.doc'], + ['lorem/ipsum.jpg'], + ['surprise/me/one/more/time.txt'], + ]; + + $generator = (new SimpleTestCase())->provideNotExistingFilePath(); + self::assertEquals($elements, GeneratorUtility::getGeneratorElements($generator)); + } + + /** + * @param string $fileName Name of file + * @param string $directoryPath Path of directory containing the file + * + * @dataProvider provideFileNameAndDirectoryPath + */ + public function testGetFilePathForTesting($fileName, $directoryPath) + { + $path = (new SimpleTestCase())->getFilePathForTesting($fileName, $directoryPath); + + if (!empty($directoryPath)) { + $directoryPath .= '/'; + } + + $expectedContains = sprintf('/.data/tests/%s%s', $directoryPath, $fileName); + static::assertContains($expectedContains, $path); + } + + /** + * Provides name of file and path of directory containing the file + * + * @return Generator + */ + public function provideFileNameAndDirectoryPath() + { + yield[ + 'abc.jpg', + '', + ]; + + yield[ + 'abc.def.jpg', + '', + ]; + + yield[ + 'abc.jpg', + 'def', + ]; + + yield[ + 'abc.def.jpg', + 'def', + ]; + } +} + +/** + * Simple test case + * + * @author Krzysztof Niziol + * @copyright Meritoo.pl + */ +class SimpleTestCase extends BaseTestCase +{ +} diff --git a/tests/Type/Base/BaseTypeTest.php b/tests/Type/Base/BaseTypeTest.php index e7d1cea..0f7399a 100644 --- a/tests/Type/Base/BaseTypeTest.php +++ b/tests/Type/Base/BaseTypeTest.php @@ -9,8 +9,8 @@ namespace Meritoo\Common\Test\Type\Base; use Generator; +use Meritoo\Common\Test\Base\BaseTestCase; use Meritoo\Common\Type\Base\BaseType; -use PHPUnit\Framework\TestCase; /** * Test case of the base / abstract type of something @@ -18,8 +18,13 @@ use PHPUnit\Framework\TestCase; * @author Krzysztof Niziol * @copyright Meritoo.pl */ -class BaseTypeTest extends TestCase +class BaseTypeTest extends BaseTestCase { + public function testConstructor() + { + static::assertHasNoConstructor(BaseType::class); + } + /** * @param BaseType $type Type of something * @param array $expectedTypes Expected concrete types of given instance of type