From ded1a049002f47fa6105dc6137b442d367dd763d Mon Sep 17 00:00:00 2001 From: Meritoo Date: Fri, 6 Sep 2019 11:58:40 +0200 Subject: [PATCH] Add test for the BaseTestCaseTrait trait --- .../Base/BaseTestCaseTrait/SimpleTestCase.php | 22 +++ .../Test/Base/BaseTestCaseTraitTest.php | 160 ++++++++++++++++++ 2 files changed, 182 insertions(+) create mode 100644 tests/Traits/Test/Base/BaseTestCaseTrait/SimpleTestCase.php create mode 100644 tests/Traits/Test/Base/BaseTestCaseTraitTest.php diff --git a/tests/Traits/Test/Base/BaseTestCaseTrait/SimpleTestCase.php b/tests/Traits/Test/Base/BaseTestCaseTrait/SimpleTestCase.php new file mode 100644 index 0000000..191beb4 --- /dev/null +++ b/tests/Traits/Test/Base/BaseTestCaseTrait/SimpleTestCase.php @@ -0,0 +1,22 @@ + + * @copyright Meritoo + * + * @internal + * @covers \Meritoo\Common\Traits\Test\Base\BaseTestCaseTrait + */ +class BaseTestCaseTraitTest extends BaseTestCase +{ + public function testProvideEmptyValue(): void + { + $testCase = new SimpleTestCase(); + $values = $testCase->provideEmptyValue(); + + $expected = [ + [''], + [' '], + [null], + [0], + [false], + [[]], + ]; + + foreach ($values as $index => $value) { + static::assertSame($expected[$index], $value); + } + } + + public function testProvideEmptyScalarValue(): void + { + $testCase = new SimpleTestCase(); + $values = $testCase->provideEmptyScalarValue(); + + $expected = [ + [''], + [' '], + [null], + [0], + [false], + ]; + + foreach ($values as $index => $value) { + static::assertSame($expected[$index], $value); + } + } + + public function testProvideBooleanValue(): void + { + $testCase = new SimpleTestCase(); + $values = $testCase->provideBooleanValue(); + + $expected = [ + [false], + [true], + ]; + + foreach ($values as $index => $value) { + static::assertSame($expected[$index], $value); + } + } + + public function testProvideDateTimeInstance(): void + { + $testCase = new SimpleTestCase(); + $instances = $testCase->provideDateTimeInstance(); + + $expected = [ + [new DateTime()], + [new DateTime('yesterday')], + [new DateTime('now')], + [new DateTime('tomorrow')], + ]; + + foreach ($instances as $index => $instance) { + /** @var DateTime $expectedInstance */ + $expectedInstance = $expected[$index][0]; + + /** @var DateTime $instance */ + $instance = $instance[0]; + + static::assertInstanceOf(DateTime::class, $instance); + static::assertEquals($expectedInstance->getTimestamp(), $instance->getTimestamp()); + } + } + + public function testProvideDateTimeRelativeFormatInstance(): void + { + $testCase = new SimpleTestCase(); + $formats = $testCase->provideDateTimeRelativeFormat(); + + $expected = [ + ['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'], + ]; + + foreach ($formats as $index => $format) { + static::assertSame($expected[$index], $format); + } + } + + public function testProvideNotExistingFilePath(): void + { + $testCase = new SimpleTestCase(); + $paths = $testCase->provideNotExistingFilePath(); + + $expected = [ + ['lets-test.doc'], + ['lorem/ipsum.jpg'], + ['surprise/me/one/more/time.txt'], + ]; + + foreach ($paths as $index => $path) { + static::assertSame($expected[$index], $path); + } + } + + public function testProvideNonScalarValue(): void + { + $testCase = new SimpleTestCase(); + $values = $testCase->provideNonScalarValue(); + + $expected = [ + [[]], + [null], + [new stdClass()], + ]; + + foreach ($values as $index => $value) { + static::assertEquals($expected[$index], $value); + } + } +}