mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 09:31:51 +01:00
161 lines
4.1 KiB
PHP
161 lines
4.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* (c) Meritoo.pl, http://www.meritoo.pl
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Meritoo\Test\Common\Traits\Test\Base;
|
|
|
|
use DateTime;
|
|
use Meritoo\Common\Test\Base\BaseTestCase;
|
|
use Meritoo\Test\Common\Traits\Test\Base\BaseTestCaseTrait\SimpleTestCase;
|
|
use stdClass;
|
|
|
|
/**
|
|
* Test case of the trait for the base test case
|
|
*
|
|
* @author Meritoo <github@meritoo.pl>
|
|
* @copyright Meritoo <http://www.meritoo.pl>
|
|
*
|
|
* @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);
|
|
}
|
|
}
|
|
}
|