mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 09:31:51 +01:00
Reformat code automatically
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -27,6 +27,44 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
*/
|
||||
class DateTimeCollectionTest extends BaseTestCase
|
||||
{
|
||||
public function provideDifferentTypesOfElements(): ?Generator
|
||||
{
|
||||
yield [
|
||||
'An empty array',
|
||||
[],
|
||||
[],
|
||||
];
|
||||
|
||||
yield [
|
||||
'Valid elements only',
|
||||
[
|
||||
new DateTime('2001-01-01'),
|
||||
new DateTime('2001-01-02'),
|
||||
],
|
||||
[
|
||||
new DateTime('2001-01-01'),
|
||||
new DateTime('2001-01-02'),
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
'Mixed elements',
|
||||
[
|
||||
1,
|
||||
'test',
|
||||
new DateTime('2001-01-01'),
|
||||
'',
|
||||
[],
|
||||
234,
|
||||
new DateTime('2001-01-02'),
|
||||
],
|
||||
[
|
||||
2 => new DateTime('2001-01-01'),
|
||||
6 => new DateTime('2001-01-02'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -51,42 +89,4 @@ class DateTimeCollectionTest extends BaseTestCase
|
||||
$collection = new DateTimeCollection($elements);
|
||||
static::assertEquals($expectedElements, $collection->toArray(), $description);
|
||||
}
|
||||
|
||||
public function provideDifferentTypesOfElements(): ?Generator
|
||||
{
|
||||
yield[
|
||||
'An empty array',
|
||||
[],
|
||||
[],
|
||||
];
|
||||
|
||||
yield[
|
||||
'Valid elements only',
|
||||
[
|
||||
new DateTime('2001-01-01'),
|
||||
new DateTime('2001-01-02'),
|
||||
],
|
||||
[
|
||||
new DateTime('2001-01-01'),
|
||||
new DateTime('2001-01-02'),
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
'Mixed elements',
|
||||
[
|
||||
1,
|
||||
'test',
|
||||
new DateTime('2001-01-01'),
|
||||
'',
|
||||
[],
|
||||
234,
|
||||
new DateTime('2001-01-02'),
|
||||
],
|
||||
[
|
||||
2 => new DateTime('2001-01-01'),
|
||||
6 => new DateTime('2001-01-02'),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Meritoo\Test\Common\Collection;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Collection\IntegerCollection;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
@@ -25,6 +26,45 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
*/
|
||||
class IntegerCollectionTest extends BaseTestCase
|
||||
{
|
||||
public function provideDifferentTypesOfElements(): ?Generator
|
||||
{
|
||||
yield [
|
||||
'An empty array',
|
||||
[],
|
||||
[],
|
||||
];
|
||||
|
||||
yield [
|
||||
'Valid elements only',
|
||||
[
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
],
|
||||
[
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
'Mixed elements',
|
||||
[
|
||||
1,
|
||||
'test',
|
||||
'',
|
||||
[],
|
||||
234,
|
||||
'test',
|
||||
],
|
||||
[
|
||||
0 => 1,
|
||||
4 => 234,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -49,43 +89,4 @@ class IntegerCollectionTest extends BaseTestCase
|
||||
$collection = new IntegerCollection($elements);
|
||||
static::assertSame($expectedElements, $collection->toArray(), $description);
|
||||
}
|
||||
|
||||
public function provideDifferentTypesOfElements(): ?\Generator
|
||||
{
|
||||
yield[
|
||||
'An empty array',
|
||||
[],
|
||||
[],
|
||||
];
|
||||
|
||||
yield[
|
||||
'Valid elements only',
|
||||
[
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
],
|
||||
[
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
'Mixed elements',
|
||||
[
|
||||
1,
|
||||
'test',
|
||||
'',
|
||||
[],
|
||||
234,
|
||||
'test',
|
||||
],
|
||||
[
|
||||
0 => 1,
|
||||
4 => 234,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Meritoo\Test\Common\Collection;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Collection\StringCollection;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
@@ -25,6 +26,46 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
*/
|
||||
class StringCollectionTest extends BaseTestCase
|
||||
{
|
||||
public function provideDifferentTypesOfElements(): ?Generator
|
||||
{
|
||||
yield [
|
||||
'An empty array',
|
||||
[],
|
||||
[],
|
||||
];
|
||||
|
||||
yield [
|
||||
'Valid elements only',
|
||||
[
|
||||
'1',
|
||||
'test',
|
||||
'',
|
||||
],
|
||||
[
|
||||
'1',
|
||||
'test',
|
||||
'',
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
'Mixed elements',
|
||||
[
|
||||
1,
|
||||
'test',
|
||||
'',
|
||||
[],
|
||||
234,
|
||||
'test',
|
||||
],
|
||||
[
|
||||
1 => 'test',
|
||||
2 => '',
|
||||
5 => 'test',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -49,44 +90,4 @@ class StringCollectionTest extends BaseTestCase
|
||||
$collection = new StringCollection($elements);
|
||||
static::assertSame($expectedElements, $collection->toArray(), $description);
|
||||
}
|
||||
|
||||
public function provideDifferentTypesOfElements(): ?\Generator
|
||||
{
|
||||
yield[
|
||||
'An empty array',
|
||||
[],
|
||||
[],
|
||||
];
|
||||
|
||||
yield[
|
||||
'Valid elements only',
|
||||
[
|
||||
'1',
|
||||
'test',
|
||||
'',
|
||||
],
|
||||
[
|
||||
'1',
|
||||
'test',
|
||||
'',
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
'Mixed elements',
|
||||
[
|
||||
1,
|
||||
'test',
|
||||
'',
|
||||
[],
|
||||
234,
|
||||
'test',
|
||||
],
|
||||
[
|
||||
1 => 'test',
|
||||
2 => '',
|
||||
5 => 'test',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,102 @@ use Meritoo\Common\ValueObject\Template;
|
||||
*/
|
||||
class TemplatesTest extends BaseTestCase
|
||||
{
|
||||
public function provideArrayWithTemplates(): ?Generator
|
||||
{
|
||||
yield [
|
||||
'An empty array',
|
||||
[],
|
||||
new Templates(),
|
||||
];
|
||||
|
||||
yield [
|
||||
'Number-based indexes',
|
||||
[
|
||||
'First name: %first_name%',
|
||||
'Last name: %last_name%',
|
||||
],
|
||||
new Templates([
|
||||
new Template('First name: %first_name%'),
|
||||
new Template('Last name: %last_name%'),
|
||||
]),
|
||||
];
|
||||
|
||||
yield [
|
||||
'String-based indexes',
|
||||
[
|
||||
'first' => 'First name: %first_name%',
|
||||
'last' => 'Last name: %last_name%',
|
||||
],
|
||||
new Templates([
|
||||
'first' => new Template('First name: %first_name%'),
|
||||
'last' => new Template('Last name: %last_name%'),
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
public function provideTemplatesToFind(): ?Generator
|
||||
{
|
||||
yield [
|
||||
'2 templates only',
|
||||
new Templates([
|
||||
'first' => new Template('First name: %first_name%'),
|
||||
'last' => new Template('Last name: %last_name%'),
|
||||
]),
|
||||
'first',
|
||||
new Template('First name: %first_name%'),
|
||||
];
|
||||
|
||||
yield [
|
||||
'Different indexes',
|
||||
new Templates([
|
||||
'first' => new Template('First name: %first_name%'),
|
||||
'last' => new Template('Last name: %last_name%'),
|
||||
1 => new Template('Hi %name%, how are you?'),
|
||||
'2' => new Template('Your score is: %score%'),
|
||||
]),
|
||||
'1',
|
||||
new Template('Hi %name%, how are you?'),
|
||||
];
|
||||
}
|
||||
|
||||
public function provideTemplatesWithNotExistingIndex(): ?Generator
|
||||
{
|
||||
$template = 'Template with \'%s\' index was not found. Did you provide all required templates?';
|
||||
|
||||
yield [
|
||||
new Templates(),
|
||||
'test',
|
||||
sprintf($template, 'test'),
|
||||
];
|
||||
|
||||
yield [
|
||||
new Templates([
|
||||
'first' => new Template('First name: %first_name%'),
|
||||
'last' => new Template('Last name: %last_name%'),
|
||||
]),
|
||||
'test',
|
||||
sprintf($template, 'test'),
|
||||
];
|
||||
|
||||
yield [
|
||||
new Templates([
|
||||
'first' => new Template('First name: %first_name%'),
|
||||
'last' => new Template('Last name: %last_name%'),
|
||||
]),
|
||||
'',
|
||||
sprintf($template, ''),
|
||||
];
|
||||
|
||||
yield [
|
||||
new Templates([
|
||||
'first' => new Template('First name: %first_name%'),
|
||||
'last' => new Template('Last name: %last_name%'),
|
||||
]),
|
||||
'4',
|
||||
sprintf($template, 4),
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -37,14 +133,15 @@ class TemplatesTest extends BaseTestCase
|
||||
|
||||
/**
|
||||
* @param string $description Description of test
|
||||
* @param array $templates Pairs of key-value where: key - template's index, value - template's content
|
||||
* @param Templates $expected Expected collection/storage of templates
|
||||
* @param Templates $templates All templates
|
||||
* @param string $index Index that contains required template
|
||||
* @param Template $expected Expected template
|
||||
*
|
||||
* @dataProvider provideArrayWithTemplates
|
||||
* @dataProvider provideTemplatesToFind
|
||||
*/
|
||||
public function testFromArray(string $description, array $templates, Templates $expected): void
|
||||
public function testFindTemplate(string $description, Templates $templates, string $index, Template $expected): void
|
||||
{
|
||||
static::assertEquals($expected, Templates::fromArray($templates), $description);
|
||||
static::assertEquals($expected, $templates->findTemplate($index), $description);
|
||||
}
|
||||
|
||||
public function testFindTemplateUsingEmptyCollection(): void
|
||||
@@ -79,110 +176,13 @@ class TemplatesTest extends BaseTestCase
|
||||
|
||||
/**
|
||||
* @param string $description Description of test
|
||||
* @param Templates $templates All templates
|
||||
* @param string $index Index that contains required template
|
||||
* @param Template $expected Expected template
|
||||
* @param array $templates Pairs of key-value where: key - template's index, value - template's content
|
||||
* @param Templates $expected Expected collection/storage of templates
|
||||
*
|
||||
* @dataProvider provideTemplatesToFind
|
||||
* @dataProvider provideArrayWithTemplates
|
||||
*/
|
||||
public function testFindTemplate(string $description, Templates $templates, string $index, Template $expected): void
|
||||
public function testFromArray(string $description, array $templates, Templates $expected): void
|
||||
{
|
||||
static::assertEquals($expected, $templates->findTemplate($index), $description);
|
||||
}
|
||||
|
||||
public function provideArrayWithTemplates(): ?Generator
|
||||
{
|
||||
yield[
|
||||
'An empty array',
|
||||
[],
|
||||
new Templates(),
|
||||
];
|
||||
|
||||
yield[
|
||||
'Number-based indexes',
|
||||
[
|
||||
'First name: %first_name%',
|
||||
'Last name: %last_name%',
|
||||
],
|
||||
new Templates([
|
||||
new Template('First name: %first_name%'),
|
||||
new Template('Last name: %last_name%'),
|
||||
]),
|
||||
];
|
||||
|
||||
yield[
|
||||
'String-based indexes',
|
||||
[
|
||||
'first' => 'First name: %first_name%',
|
||||
'last' => 'Last name: %last_name%',
|
||||
],
|
||||
new Templates([
|
||||
'first' => new Template('First name: %first_name%'),
|
||||
'last' => new Template('Last name: %last_name%'),
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
public function provideTemplatesWithNotExistingIndex(): ?Generator
|
||||
{
|
||||
$template = 'Template with \'%s\' index was not found. Did you provide all required templates?';
|
||||
|
||||
yield[
|
||||
new Templates(),
|
||||
'test',
|
||||
sprintf($template, 'test'),
|
||||
];
|
||||
|
||||
yield[
|
||||
new Templates([
|
||||
'first' => new Template('First name: %first_name%'),
|
||||
'last' => new Template('Last name: %last_name%'),
|
||||
]),
|
||||
'test',
|
||||
sprintf($template, 'test'),
|
||||
];
|
||||
|
||||
yield[
|
||||
new Templates([
|
||||
'first' => new Template('First name: %first_name%'),
|
||||
'last' => new Template('Last name: %last_name%'),
|
||||
]),
|
||||
'',
|
||||
sprintf($template, ''),
|
||||
];
|
||||
|
||||
yield[
|
||||
new Templates([
|
||||
'first' => new Template('First name: %first_name%'),
|
||||
'last' => new Template('Last name: %last_name%'),
|
||||
]),
|
||||
'4',
|
||||
sprintf($template, 4),
|
||||
];
|
||||
}
|
||||
|
||||
public function provideTemplatesToFind(): ?Generator
|
||||
{
|
||||
yield[
|
||||
'2 templates only',
|
||||
new Templates([
|
||||
'first' => new Template('First name: %first_name%'),
|
||||
'last' => new Template('Last name: %last_name%'),
|
||||
]),
|
||||
'first',
|
||||
new Template('First name: %first_name%'),
|
||||
];
|
||||
|
||||
yield[
|
||||
'Different indexes',
|
||||
new Templates([
|
||||
'first' => new Template('First name: %first_name%'),
|
||||
'last' => new Template('Last name: %last_name%'),
|
||||
1 => new Template('Hi %name%, how are you?'),
|
||||
'2' => new Template('Your score is: %score%'),
|
||||
]),
|
||||
'1',
|
||||
new Template('Hi %name%, how are you?'),
|
||||
];
|
||||
static::assertEquals($expected, Templates::fromArray($templates), $description);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,16 +29,16 @@ class UnknownTypeExceptionTest extends BaseTestCase
|
||||
static::assertConstructorVisibilityAndArguments(UnknownTypeException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
}
|
||||
|
||||
public function testWithoutException()
|
||||
{
|
||||
self::assertEquals('Test 2', (new TestService())->getTranslatedType('test_2'));
|
||||
}
|
||||
|
||||
public function testTheException()
|
||||
{
|
||||
$this->expectException(UnknownTestTypeException::class);
|
||||
self::assertEmpty((new TestService())->getTranslatedType('test_3'));
|
||||
}
|
||||
|
||||
public function testWithoutException()
|
||||
{
|
||||
self::assertEquals('Test 2', (new TestService())->getTranslatedType('test_2'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,8 +89,8 @@ class TestService
|
||||
* Returns translated type (for testing purposes)
|
||||
*
|
||||
* @param string $type Type of something (for testing purposes)
|
||||
* @throws UnknownTestTypeException
|
||||
* @return string
|
||||
* @throws UnknownTestTypeException
|
||||
*/
|
||||
public function getTranslatedType(string $type): string
|
||||
{
|
||||
|
||||
@@ -20,10 +20,34 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\Bundle\IncorrectBundleNameException
|
||||
* @covers \Meritoo\Common\Exception\Bundle\IncorrectBundleNameException
|
||||
*/
|
||||
class IncorrectBundleNameExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function provideBundleNameAndMessage(): Generator
|
||||
{
|
||||
$template = 'Name of bundle \'%s\' is incorrect. It should start with big letter and end with "Bundle". Is'
|
||||
.' there everything ok?';
|
||||
|
||||
yield [
|
||||
'An empty string as name of bundle',
|
||||
'',
|
||||
sprintf($template, ''),
|
||||
];
|
||||
|
||||
yield [
|
||||
'String with spaces as name of bundle',
|
||||
'This is test',
|
||||
sprintf($template, 'This is test'),
|
||||
];
|
||||
|
||||
yield [
|
||||
'String without spaces as name of bundle',
|
||||
'ThisIsTest',
|
||||
sprintf($template, 'ThisIsTest'),
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -45,28 +69,4 @@ class IncorrectBundleNameExceptionTest extends BaseTestCase
|
||||
$exception = IncorrectBundleNameException::create($bundleName);
|
||||
static::assertSame($expectedMessage, $exception->getMessage(), $description);
|
||||
}
|
||||
|
||||
public function provideBundleNameAndMessage(): Generator
|
||||
{
|
||||
$template = 'Name of bundle \'%s\' is incorrect. It should start with big letter and end with "Bundle". Is'
|
||||
. ' there everything ok?';
|
||||
|
||||
yield[
|
||||
'An empty string as name of bundle',
|
||||
'',
|
||||
sprintf($template, ''),
|
||||
];
|
||||
|
||||
yield[
|
||||
'String with spaces as name of bundle',
|
||||
'This is test',
|
||||
sprintf($template, 'This is test'),
|
||||
];
|
||||
|
||||
yield[
|
||||
'String without spaces as name of bundle',
|
||||
'ThisIsTest',
|
||||
sprintf($template, 'ThisIsTest'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,10 +21,39 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\Type\UnknownDatePartTypeException
|
||||
* @covers \Meritoo\Common\Exception\Type\UnknownDatePartTypeException
|
||||
*/
|
||||
class UnknownDatePartTypeExceptionTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Provides type of date part, incorrect value and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideDatePartAndValue()
|
||||
{
|
||||
$template = 'The \'%s\' type of date part (with value %s) is unknown. Probably doesn\'t exist or there is a'
|
||||
.' typo. You should use one of these types: day, hour, minute, month, second, year.';
|
||||
|
||||
yield [
|
||||
DatePartType::DAY,
|
||||
'44',
|
||||
sprintf($template, DatePartType::DAY, '44'),
|
||||
];
|
||||
|
||||
yield [
|
||||
DatePartType::MONTH,
|
||||
'22',
|
||||
sprintf($template, DatePartType::MONTH, '22'),
|
||||
];
|
||||
|
||||
yield [
|
||||
DatePartType::MINUTE,
|
||||
'77',
|
||||
sprintf($template, DatePartType::MINUTE, '77'),
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(UnknownDatePartTypeException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
@@ -42,33 +71,4 @@ class UnknownDatePartTypeExceptionTest extends BaseTestCase
|
||||
$exception = UnknownDatePartTypeException::createException($unknownDatePart, $value);
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides type of date part, incorrect value and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideDatePartAndValue()
|
||||
{
|
||||
$template = 'The \'%s\' type of date part (with value %s) is unknown. Probably doesn\'t exist or there is a'
|
||||
. ' typo. You should use one of these types: day, hour, minute, month, second, year.';
|
||||
|
||||
yield[
|
||||
DatePartType::DAY,
|
||||
'44',
|
||||
sprintf($template, DatePartType::DAY, '44'),
|
||||
];
|
||||
|
||||
yield[
|
||||
DatePartType::MONTH,
|
||||
'22',
|
||||
sprintf($template, DatePartType::MONTH, '22'),
|
||||
];
|
||||
|
||||
yield[
|
||||
DatePartType::MINUTE,
|
||||
'77',
|
||||
sprintf($template, DatePartType::MINUTE, '77'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,10 +20,30 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\File\EmptyFileException
|
||||
* @covers \Meritoo\Common\Exception\File\EmptyFileException
|
||||
*/
|
||||
class EmptyFileExceptionTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Provides path of the empty file and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function providePathOfFile()
|
||||
{
|
||||
$template = 'File with path \'%s\' is empty (has no content). Did you provide path of proper file?';
|
||||
|
||||
yield [
|
||||
'aa/bb/cc',
|
||||
sprintf($template, 'aa/bb/cc'),
|
||||
];
|
||||
|
||||
yield [
|
||||
'images/show/car.jpg',
|
||||
sprintf($template, 'images/show/car.jpg'),
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(EmptyFileException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
@@ -40,24 +60,4 @@ class EmptyFileExceptionTest extends BaseTestCase
|
||||
$exception = EmptyFileException::create($emptyFilePath);
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides path of the empty file and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function providePathOfFile()
|
||||
{
|
||||
$template = 'File with path \'%s\' is empty (has no content). Did you provide path of proper file?';
|
||||
|
||||
yield[
|
||||
'aa/bb/cc',
|
||||
sprintf($template, 'aa/bb/cc'),
|
||||
];
|
||||
|
||||
yield[
|
||||
'images/show/car.jpg',
|
||||
sprintf($template, 'images/show/car.jpg'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,18 +19,18 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\File\EmptyFilePathException
|
||||
* @covers \Meritoo\Common\Exception\File\EmptyFilePathException
|
||||
*/
|
||||
class EmptyFilePathExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(EmptyFilePathException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
}
|
||||
|
||||
public function testConstructorMessage()
|
||||
{
|
||||
$exception = EmptyFilePathException::create();
|
||||
static::assertSame('Path of the file is empty. Did you provide path of proper file?', $exception->getMessage());
|
||||
}
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(EmptyFilePathException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,28 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\File\NotExistingFileException
|
||||
* @covers \Meritoo\Common\Exception\File\NotExistingFileException
|
||||
*/
|
||||
class NotExistingFileExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
/**
|
||||
* Provides path of not existing file and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function providePathOfFile()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(NotExistingFileException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
$template = 'File with path \'%s\' does not exist (or is not readable). Did you provide path of proper file?';
|
||||
|
||||
yield [
|
||||
'aa/bb/cc',
|
||||
sprintf($template, 'aa/bb/cc'),
|
||||
];
|
||||
|
||||
yield [
|
||||
'images/show/car.jpg',
|
||||
sprintf($template, 'images/show/car.jpg'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,23 +56,8 @@ class NotExistingFileExceptionTest extends BaseTestCase
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides path of not existing file and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function providePathOfFile()
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
$template = 'File with path \'%s\' does not exist (or is not readable). Did you provide path of proper file?';
|
||||
|
||||
yield[
|
||||
'aa/bb/cc',
|
||||
sprintf($template, 'aa/bb/cc'),
|
||||
];
|
||||
|
||||
yield[
|
||||
'images/show/car.jpg',
|
||||
sprintf($template, 'images/show/car.jpg'),
|
||||
];
|
||||
static::assertConstructorVisibilityAndArguments(NotExistingFileException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,31 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\Method\DisabledMethodException
|
||||
* @covers \Meritoo\Common\Exception\Method\DisabledMethodException
|
||||
*/
|
||||
class DisabledMethodExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
/**
|
||||
* Provides name of the disabled method, name of the alternative method and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideMethodsNames()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(DisabledMethodException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
$templateShort = 'Method %s() cannot be called, because is disabled.';
|
||||
$templateLong = $templateShort.' Use %s() instead.';
|
||||
|
||||
yield [
|
||||
'FooBar::loremIpsum',
|
||||
'',
|
||||
sprintf($templateShort, 'FooBar::loremIpsum'),
|
||||
];
|
||||
|
||||
yield [
|
||||
'FooBar::loremIpsum',
|
||||
'AnotherClass::alternativeMethod',
|
||||
sprintf($templateLong, 'FooBar::loremIpsum', 'AnotherClass::alternativeMethod'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,26 +61,8 @@ class DisabledMethodExceptionTest extends BaseTestCase
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides name of the disabled method, name of the alternative method and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideMethodsNames()
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
$templateShort = 'Method %s() cannot be called, because is disabled.';
|
||||
$templateLong = $templateShort . ' Use %s() instead.';
|
||||
|
||||
yield[
|
||||
'FooBar::loremIpsum',
|
||||
'',
|
||||
sprintf($templateShort, 'FooBar::loremIpsum'),
|
||||
];
|
||||
|
||||
yield[
|
||||
'FooBar::loremIpsum',
|
||||
'AnotherClass::alternativeMethod',
|
||||
sprintf($templateLong, 'FooBar::loremIpsum', 'AnotherClass::alternativeMethod'),
|
||||
];
|
||||
static::assertConstructorVisibilityAndArguments(DisabledMethodException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,33 @@ use stdClass;
|
||||
*/
|
||||
class CannotResolveClassNameExceptionTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Provides source of the class's / trait's name, information if message of this exception should be prepared for
|
||||
* class and the expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideClassName(): Generator
|
||||
{
|
||||
yield [
|
||||
'Not\Existing\Class',
|
||||
true,
|
||||
'Name of class from given \'string\' Not\Existing\Class cannot be resolved. Is there everything ok?',
|
||||
];
|
||||
|
||||
yield [
|
||||
'Not\Existing\Trait',
|
||||
false,
|
||||
'Name of trait from given \'string\' Not\Existing\Trait cannot be resolved. Is there everything ok?',
|
||||
];
|
||||
|
||||
yield [
|
||||
stdClass::class,
|
||||
true,
|
||||
'Name of class from given \'string\' stdClass cannot be resolved. Is there everything ok?',
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructorVisibilityAndArguments(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -34,14 +61,6 @@ class CannotResolveClassNameExceptionTest extends BaseTestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreateUsingDefaults(): void
|
||||
{
|
||||
$exception = CannotResolveClassNameException::create(stdClass::class);
|
||||
$expectedMessage = 'Name of class from given \'string\' stdClass cannot be resolved. Is there everything ok?';
|
||||
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $source Source of name of the class or trait
|
||||
* @param bool $forClass (optional) If is set to true, message of this exception for class is prepared.
|
||||
@@ -56,30 +75,11 @@ class CannotResolveClassNameExceptionTest extends BaseTestCase
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides source of the class's / trait's name, information if message of this exception should be prepared for
|
||||
* class and the expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideClassName(): Generator
|
||||
public function testCreateUsingDefaults(): void
|
||||
{
|
||||
yield[
|
||||
'Not\Existing\Class',
|
||||
true,
|
||||
'Name of class from given \'string\' Not\Existing\Class cannot be resolved. Is there everything ok?',
|
||||
];
|
||||
$exception = CannotResolveClassNameException::create(stdClass::class);
|
||||
$expectedMessage = 'Name of class from given \'string\' stdClass cannot be resolved. Is there everything ok?';
|
||||
|
||||
yield[
|
||||
'Not\Existing\Trait',
|
||||
false,
|
||||
'Name of trait from given \'string\' Not\Existing\Trait cannot be resolved. Is there everything ok?',
|
||||
];
|
||||
|
||||
yield[
|
||||
stdClass::class,
|
||||
true,
|
||||
'Name of class from given \'string\' stdClass cannot be resolved. Is there everything ok?',
|
||||
];
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,23 @@ use Meritoo\Common\Utilities\Arrays;
|
||||
*/
|
||||
class ClassWithoutConstructorExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function provideClassName(): Generator
|
||||
{
|
||||
$template = 'Oops, class \'%s\' hasn\'t constructor. Did you use proper class?';
|
||||
|
||||
yield [
|
||||
'An empty name of class',
|
||||
'',
|
||||
sprintf($template, ''),
|
||||
];
|
||||
|
||||
yield [
|
||||
'The Arrays class',
|
||||
Arrays::class,
|
||||
sprintf($template, Arrays::class),
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -46,21 +63,4 @@ class ClassWithoutConstructorExceptionTest extends BaseTestCase
|
||||
$exception = ClassWithoutConstructorException::create($className);
|
||||
static::assertSame($expectedMessage, $exception->getMessage(), $description);
|
||||
}
|
||||
|
||||
public function provideClassName(): Generator
|
||||
{
|
||||
$template = 'Oops, class \'%s\' hasn\'t constructor. Did you use proper class?';
|
||||
|
||||
yield[
|
||||
'An empty name of class',
|
||||
'',
|
||||
sprintf($template, ''),
|
||||
];
|
||||
|
||||
yield[
|
||||
'The Arrays class',
|
||||
Arrays::class,
|
||||
sprintf($template, Arrays::class),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ use Generator;
|
||||
use Meritoo\Common\Exception\Reflection\MissingChildClassesException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while given class has no child classes
|
||||
@@ -24,6 +25,30 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
*/
|
||||
class MissingChildClassesExceptionTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Provides name of class that hasn't child classes, but it should, and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideParentClass(): ?Generator
|
||||
{
|
||||
$template = 'The \'%s\' class requires one child class at least who will extend her (maybe is an abstract'
|
||||
.' class), but the child classes are missing. Did you forget to extend this class?';
|
||||
|
||||
yield [
|
||||
MissingChildClassesException::class,
|
||||
sprintf($template, MissingChildClassesException::class),
|
||||
];
|
||||
|
||||
yield [
|
||||
[
|
||||
new stdClass(),
|
||||
new stdClass(),
|
||||
],
|
||||
sprintf($template, stdClass::class),
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructorVisibilityAndArguments(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -45,28 +70,4 @@ class MissingChildClassesExceptionTest extends BaseTestCase
|
||||
$exception = MissingChildClassesException::create($parentClass);
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides name of class that hasn't child classes, but it should, and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideParentClass(): ?Generator
|
||||
{
|
||||
$template = 'The \'%s\' class requires one child class at least who will extend her (maybe is an abstract'
|
||||
. ' class), but the child classes are missing. Did you forget to extend this class?';
|
||||
|
||||
yield[
|
||||
MissingChildClassesException::class,
|
||||
sprintf($template, MissingChildClassesException::class),
|
||||
];
|
||||
|
||||
yield[
|
||||
[
|
||||
new \stdClass(),
|
||||
new \stdClass(),
|
||||
],
|
||||
sprintf($template, \stdClass::class),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,11 @@
|
||||
|
||||
namespace Meritoo\Test\Common\Exception\Reflection;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Exception\Reflection\NotExistingPropertyException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Class NotExistingPropertyExceptionTest
|
||||
@@ -23,6 +25,39 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
*/
|
||||
class NotExistingPropertyExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function provideObjectPropertyAndMessage(): ?Generator
|
||||
{
|
||||
$template = 'Property \'%s\' does not exist in instance of class \'%s\'. Did you use proper name of property?';
|
||||
|
||||
yield [
|
||||
'An empty string as name of property',
|
||||
new stdClass(),
|
||||
'',
|
||||
sprintf($template, '', get_class(new stdClass())),
|
||||
];
|
||||
|
||||
yield [
|
||||
'Null as name of property',
|
||||
new stdClass(),
|
||||
null,
|
||||
sprintf($template, '', get_class(new stdClass())),
|
||||
];
|
||||
|
||||
yield [
|
||||
'String with spaces as name of property',
|
||||
new stdClass(),
|
||||
'This is test',
|
||||
sprintf($template, 'This is test', get_class(new stdClass())),
|
||||
];
|
||||
|
||||
yield [
|
||||
'String without spaces as name of property',
|
||||
new stdClass(),
|
||||
'ThisIsTest',
|
||||
sprintf($template, 'ThisIsTest', get_class(new stdClass())),
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -45,37 +80,4 @@ class NotExistingPropertyExceptionTest extends BaseTestCase
|
||||
$exception = NotExistingPropertyException::create($object, $property);
|
||||
static::assertSame($expectedMessage, $exception->getMessage(), $description);
|
||||
}
|
||||
|
||||
public function provideObjectPropertyAndMessage(): ?\Generator
|
||||
{
|
||||
$template = 'Property \'%s\' does not exist in instance of class \'%s\'. Did you use proper name of property?';
|
||||
|
||||
yield[
|
||||
'An empty string as name of property',
|
||||
new \stdClass(),
|
||||
'',
|
||||
sprintf($template, '', get_class(new \stdClass())),
|
||||
];
|
||||
|
||||
yield[
|
||||
'Null as name of property',
|
||||
new \stdClass(),
|
||||
null,
|
||||
sprintf($template, '', get_class(new \stdClass())),
|
||||
];
|
||||
|
||||
yield[
|
||||
'String with spaces as name of property',
|
||||
new \stdClass(),
|
||||
'This is test',
|
||||
sprintf($template, 'This is test', get_class(new \stdClass())),
|
||||
];
|
||||
|
||||
yield[
|
||||
'String without spaces as name of property',
|
||||
new \stdClass(),
|
||||
'ThisIsTest',
|
||||
sprintf($template, 'ThisIsTest', get_class(new \stdClass())),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ use Generator;
|
||||
use Meritoo\Common\Exception\Reflection\TooManyChildClassesException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while given class has more than one child class
|
||||
@@ -24,6 +25,38 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
*/
|
||||
class TooManyChildClassesExceptionTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Provides name of class that has more than one child class, but it shouldn't, child classes, and expected
|
||||
* exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideParentAndChildClasses(): ?Generator
|
||||
{
|
||||
$template = "The '%s' class requires one child class at most who will extend her, but more than one child"
|
||||
." class was found:\n- %s\n\nWhy did you create more than one classes that extend '%s' class?";
|
||||
|
||||
yield [
|
||||
BaseTestCase::class,
|
||||
[
|
||||
stdClass::class,
|
||||
OopVisibilityType::class,
|
||||
],
|
||||
sprintf($template, BaseTestCase::class, implode("\n- ", [
|
||||
stdClass::class,
|
||||
OopVisibilityType::class,
|
||||
]), BaseTestCase::class),
|
||||
];
|
||||
|
||||
yield [
|
||||
TooManyChildClassesException::class,
|
||||
[
|
||||
stdClass::class,
|
||||
],
|
||||
sprintf($template, TooManyChildClassesException::class, implode("\n- ", [stdClass::class]), TooManyChildClassesException::class),
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -46,36 +79,4 @@ class TooManyChildClassesExceptionTest extends BaseTestCase
|
||||
$exception = TooManyChildClassesException::create($parentClass, $childClasses);
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides name of class that has more than one child class, but it shouldn't, child classes, and expected
|
||||
* exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideParentAndChildClasses(): ?Generator
|
||||
{
|
||||
$template = "The '%s' class requires one child class at most who will extend her, but more than one child"
|
||||
. " class was found:\n- %s\n\nWhy did you create more than one classes that extend '%s' class?";
|
||||
|
||||
yield[
|
||||
BaseTestCase::class,
|
||||
[
|
||||
\stdClass::class,
|
||||
OopVisibilityType::class,
|
||||
],
|
||||
sprintf($template, BaseTestCase::class, implode("\n- ", [
|
||||
\stdClass::class,
|
||||
OopVisibilityType::class,
|
||||
]), BaseTestCase::class),
|
||||
];
|
||||
|
||||
yield[
|
||||
TooManyChildClassesException::class,
|
||||
[
|
||||
\stdClass::class,
|
||||
],
|
||||
sprintf($template, TooManyChildClassesException::class, implode("\n- ", [\stdClass::class]), TooManyChildClassesException::class),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,28 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\Regex\IncorrectColorHexLengthException
|
||||
* @covers \Meritoo\Common\Exception\Regex\IncorrectColorHexLengthException
|
||||
*/
|
||||
class IncorrectColorHexLengthExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
/**
|
||||
* Provides incorrect hexadecimal value of color and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideColor()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(IncorrectColorHexLengthException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
$template = 'Length of hexadecimal value of color \'%s\' is incorrect. It\'s %d, but it should be 3 or 6. Is there everything ok?';
|
||||
|
||||
yield [
|
||||
'',
|
||||
sprintf($template, '', strlen('')),
|
||||
];
|
||||
|
||||
yield [
|
||||
'aa-bb-cc',
|
||||
sprintf($template, 'aa-bb-cc', strlen('aa-bb-cc')),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,23 +56,8 @@ class IncorrectColorHexLengthExceptionTest extends BaseTestCase
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides incorrect hexadecimal value of color and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideColor()
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
$template = 'Length of hexadecimal value of color \'%s\' is incorrect. It\'s %d, but it should be 3 or 6. Is there everything ok?';
|
||||
|
||||
yield[
|
||||
'',
|
||||
sprintf($template, '', strlen('')),
|
||||
];
|
||||
|
||||
yield[
|
||||
'aa-bb-cc',
|
||||
sprintf($template, 'aa-bb-cc', strlen('aa-bb-cc')),
|
||||
];
|
||||
static::assertConstructorVisibilityAndArguments(IncorrectColorHexLengthException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,28 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\Regex\InvalidColorHexValueException
|
||||
* @covers \Meritoo\Common\Exception\Regex\InvalidColorHexValueException
|
||||
*/
|
||||
class InvalidColorHexValueExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
/**
|
||||
* Provides invalid hexadecimal value of color and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideColor()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(InvalidColorHexValueException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
$template = 'Hexadecimal value of color \'%s\' is invalid. Is there everything ok?';
|
||||
|
||||
yield [
|
||||
'',
|
||||
sprintf($template, ''),
|
||||
];
|
||||
|
||||
yield [
|
||||
'aa-bb-cc',
|
||||
sprintf($template, 'aa-bb-cc'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,23 +56,8 @@ class InvalidColorHexValueExceptionTest extends BaseTestCase
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides invalid hexadecimal value of color and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideColor()
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
$template = 'Hexadecimal value of color \'%s\' is invalid. Is there everything ok?';
|
||||
|
||||
yield[
|
||||
'',
|
||||
sprintf($template, ''),
|
||||
];
|
||||
|
||||
yield[
|
||||
'aa-bb-cc',
|
||||
sprintf($template, 'aa-bb-cc'),
|
||||
];
|
||||
static::assertConstructorVisibilityAndArguments(InvalidColorHexValueException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,33 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\Regex\InvalidHtmlAttributesException
|
||||
* @covers \Meritoo\Common\Exception\Regex\InvalidHtmlAttributesException
|
||||
*/
|
||||
class InvalidHtmlAttributesExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
/**
|
||||
* Provides html attributes
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideHtmlAttributes()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(InvalidHtmlAttributesException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
$template = 'HTML attributes \'%s\' are invalid. Is there everything ok?';
|
||||
|
||||
yield [
|
||||
'abc = def',
|
||||
sprintf($template, 'abc = def'),
|
||||
];
|
||||
|
||||
yield [
|
||||
'abc = def ghi = jkl',
|
||||
sprintf($template, 'abc = def ghi = jkl'),
|
||||
];
|
||||
|
||||
yield [
|
||||
'abc=def ghi=jkl',
|
||||
sprintf($template, 'abc=def ghi=jkl'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,28 +61,8 @@ class InvalidHtmlAttributesExceptionTest extends BaseTestCase
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides html attributes
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideHtmlAttributes()
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
$template = 'HTML attributes \'%s\' are invalid. Is there everything ok?';
|
||||
|
||||
yield[
|
||||
'abc = def',
|
||||
sprintf($template, 'abc = def'),
|
||||
];
|
||||
|
||||
yield[
|
||||
'abc = def ghi = jkl',
|
||||
sprintf($template, 'abc = def ghi = jkl'),
|
||||
];
|
||||
|
||||
yield[
|
||||
'abc=def ghi=jkl',
|
||||
sprintf($template, 'abc=def ghi=jkl'),
|
||||
];
|
||||
static::assertConstructorVisibilityAndArguments(InvalidHtmlAttributesException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,28 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\Regex\InvalidUrlException
|
||||
* @covers \Meritoo\Common\Exception\Regex\InvalidUrlException
|
||||
*/
|
||||
class InvalidUrlExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
/**
|
||||
* Provides invalid url and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideUrl()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(InvalidUrlException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
$template = 'Url \'%s\' is invalid. Is there everything ok?';
|
||||
|
||||
yield [
|
||||
'aa/bb/cc',
|
||||
sprintf($template, 'aa/bb/cc'),
|
||||
];
|
||||
|
||||
yield [
|
||||
'http:/images\show\car.jpg',
|
||||
sprintf($template, 'http:/images\show\car.jpg'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,23 +56,8 @@ class InvalidUrlExceptionTest extends BaseTestCase
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides invalid url and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideUrl()
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
$template = 'Url \'%s\' is invalid. Is there everything ok?';
|
||||
|
||||
yield[
|
||||
'aa/bb/cc',
|
||||
sprintf($template, 'aa/bb/cc'),
|
||||
];
|
||||
|
||||
yield[
|
||||
'http:/images\show\car.jpg',
|
||||
sprintf($template, 'http:/images\show\car.jpg'),
|
||||
];
|
||||
static::assertConstructorVisibilityAndArguments(InvalidUrlException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,13 +25,27 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
*/
|
||||
class UnknownOopVisibilityTypeExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments(): void
|
||||
/**
|
||||
* Provides path of the empty file and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideUnknownType(): Generator
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
UnknownOopVisibilityTypeException::class,
|
||||
OopVisibilityType::IS_PUBLIC,
|
||||
3
|
||||
);
|
||||
$allTypes = (new OopVisibilityType())->getAll();
|
||||
|
||||
$template = 'The \'%s\' type of OOP-related visibility is unknown. Probably doesn\'t exist or there is a typo.'
|
||||
.' You should use one of these types: %s.';
|
||||
|
||||
yield [
|
||||
'',
|
||||
sprintf($template, '', implode(', ', $allTypes)),
|
||||
];
|
||||
|
||||
yield [
|
||||
123,
|
||||
sprintf($template, 123, implode(', ', $allTypes)),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,26 +60,12 @@ class UnknownOopVisibilityTypeExceptionTest extends BaseTestCase
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides path of the empty file and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideUnknownType(): Generator
|
||||
public function testConstructorVisibilityAndArguments(): void
|
||||
{
|
||||
$allTypes = (new OopVisibilityType())->getAll();
|
||||
|
||||
$template = 'The \'%s\' type of OOP-related visibility is unknown. Probably doesn\'t exist or there is a typo.'
|
||||
. ' You should use one of these types: %s.';
|
||||
|
||||
yield[
|
||||
'',
|
||||
sprintf($template, '', implode(', ', $allTypes)),
|
||||
];
|
||||
|
||||
yield[
|
||||
123,
|
||||
sprintf($template, 123, implode(', ', $allTypes)),
|
||||
];
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
UnknownOopVisibilityTypeException::class,
|
||||
OopVisibilityType::IS_PUBLIC,
|
||||
3
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,33 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\ValueObject\InvalidSizeDimensionsException
|
||||
* @covers \Meritoo\Common\Exception\ValueObject\InvalidSizeDimensionsException
|
||||
*/
|
||||
class InvalidSizeDimensionsExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function provideWidthAndHeight()
|
||||
{
|
||||
$template = 'Dimensions of size should be positive, but they are not: %d, %d. Is there everything ok?';
|
||||
|
||||
yield [
|
||||
0,
|
||||
0,
|
||||
sprintf($template, 0, 0),
|
||||
];
|
||||
|
||||
yield [
|
||||
-1,
|
||||
-1,
|
||||
sprintf($template, -1, -1),
|
||||
];
|
||||
|
||||
yield [
|
||||
200,
|
||||
100,
|
||||
sprintf($template, 200, 100),
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -44,27 +67,4 @@ class InvalidSizeDimensionsExceptionTest extends BaseTestCase
|
||||
$exception = InvalidSizeDimensionsException::create($width, $height);
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
public function provideWidthAndHeight()
|
||||
{
|
||||
$template = 'Dimensions of size should be positive, but they are not: %d, %d. Is there everything ok?';
|
||||
|
||||
yield[
|
||||
0,
|
||||
0,
|
||||
sprintf($template, 0, 0),
|
||||
];
|
||||
|
||||
yield[
|
||||
-1,
|
||||
-1,
|
||||
sprintf($template, -1, -1),
|
||||
];
|
||||
|
||||
yield[
|
||||
200,
|
||||
100,
|
||||
sprintf($template, 200, 100),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,29 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
*/
|
||||
class InvalidContentExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function provideContent(): ?Generator
|
||||
{
|
||||
$template = 'Content of template \'%s\' is invalid. Did you use string with 1 placeholder at least?';
|
||||
|
||||
yield [
|
||||
'An empty string',
|
||||
'',
|
||||
sprintf($template, ''),
|
||||
];
|
||||
|
||||
yield [
|
||||
'Simple string',
|
||||
'Lorem ipsum',
|
||||
sprintf($template, 'Lorem ipsum'),
|
||||
];
|
||||
|
||||
yield [
|
||||
'One sentence',
|
||||
'Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh.',
|
||||
sprintf($template, 'Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh.'),
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructorVisibilityAndArguments(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -45,27 +68,4 @@ class InvalidContentExceptionTest extends BaseTestCase
|
||||
$exception = InvalidContentException::create($content);
|
||||
static::assertSame($expectedMessage, $exception->getMessage(), $description);
|
||||
}
|
||||
|
||||
public function provideContent(): ?Generator
|
||||
{
|
||||
$template = 'Content of template \'%s\' is invalid. Did you use string with 1 placeholder at least?';
|
||||
|
||||
yield[
|
||||
'An empty string',
|
||||
'',
|
||||
sprintf($template, ''),
|
||||
];
|
||||
|
||||
yield[
|
||||
'Simple string',
|
||||
'Lorem ipsum',
|
||||
sprintf($template, 'Lorem ipsum'),
|
||||
];
|
||||
|
||||
yield[
|
||||
'One sentence',
|
||||
'Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh.',
|
||||
sprintf($template, 'Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh.'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
namespace Meritoo\Test\Common\Exception\ValueObject\Template;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Exception\ValueObject\Template\MissingPlaceholdersInValuesException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
@@ -23,6 +24,39 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
*/
|
||||
class MissingPlaceholdersInValuesExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function provideContentAndMissingPlaceholders(): ?Generator
|
||||
{
|
||||
$template = 'Cannot fill template \'%s\', because of missing values for placeholder(s): %s. Did you provide all'
|
||||
.' required values?';
|
||||
|
||||
yield [
|
||||
'Missing 2nd placeholder',
|
||||
'%test1% - %test2%',
|
||||
[
|
||||
'test2',
|
||||
],
|
||||
sprintf(
|
||||
$template,
|
||||
'%test1% - %test2%',
|
||||
'test2'
|
||||
),
|
||||
];
|
||||
|
||||
yield [
|
||||
'Missing 2nd and 3rd placeholder',
|
||||
'%test1% / %test2% / %test3%',
|
||||
[
|
||||
'test2',
|
||||
'test3',
|
||||
],
|
||||
sprintf(
|
||||
$template,
|
||||
'%test1% / %test2% / %test3%',
|
||||
'test2, test3'
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructorVisibilityAndArguments(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -49,37 +83,4 @@ class MissingPlaceholdersInValuesExceptionTest extends BaseTestCase
|
||||
$exception = MissingPlaceholdersInValuesException::create($content, $missingPlaceholders);
|
||||
static::assertSame($expectedMessage, $exception->getMessage(), $description);
|
||||
}
|
||||
|
||||
public function provideContentAndMissingPlaceholders(): ?\Generator
|
||||
{
|
||||
$template = 'Cannot fill template \'%s\', because of missing values for placeholder(s): %s. Did you provide all'
|
||||
. ' required values?';
|
||||
|
||||
yield[
|
||||
'Missing 2nd placeholder',
|
||||
'%test1% - %test2%',
|
||||
[
|
||||
'test2',
|
||||
],
|
||||
sprintf(
|
||||
$template,
|
||||
'%test1% - %test2%',
|
||||
'test2'
|
||||
),
|
||||
];
|
||||
|
||||
yield[
|
||||
'Missing 2nd and 3rd placeholder',
|
||||
'%test1% / %test2% / %test3%',
|
||||
[
|
||||
'test2',
|
||||
'test3',
|
||||
],
|
||||
sprintf(
|
||||
$template,
|
||||
'%test1% / %test2% / %test3%',
|
||||
'test2, test3'
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,29 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
*/
|
||||
class TemplateNotFoundExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function provideIndexAndException(): ?Generator
|
||||
{
|
||||
$template = 'Template with \'%s\' index was not found. Did you provide all required templates?';
|
||||
|
||||
yield [
|
||||
'An empty string',
|
||||
'',
|
||||
new TemplateNotFoundException(sprintf($template, '')),
|
||||
];
|
||||
|
||||
yield [
|
||||
'Non-empty string',
|
||||
'test',
|
||||
new TemplateNotFoundException(sprintf($template, 'test')),
|
||||
];
|
||||
|
||||
yield [
|
||||
'Integer',
|
||||
'2',
|
||||
new TemplateNotFoundException(sprintf($template, 2)),
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -45,27 +68,4 @@ class TemplateNotFoundExceptionTest extends BaseTestCase
|
||||
$created = TemplateNotFoundException::create($index);
|
||||
static::assertEquals($expected, $created, $description);
|
||||
}
|
||||
|
||||
public function provideIndexAndException(): ?Generator
|
||||
{
|
||||
$template = 'Template with \'%s\' index was not found. Did you provide all required templates?';
|
||||
|
||||
yield[
|
||||
'An empty string',
|
||||
'',
|
||||
new TemplateNotFoundException(sprintf($template, '')),
|
||||
];
|
||||
|
||||
yield[
|
||||
'Non-empty string',
|
||||
'test',
|
||||
new TemplateNotFoundException(sprintf($template, 'test')),
|
||||
];
|
||||
|
||||
yield[
|
||||
'Integer',
|
||||
'2',
|
||||
new TemplateNotFoundException(sprintf($template, 2)),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,28 +21,59 @@ use Meritoo\Common\Utilities\GeneratorUtility;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Test\Base\BaseTestCase
|
||||
* @covers \Meritoo\Common\Test\Base\BaseTestCase
|
||||
*/
|
||||
class BaseTestCaseTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* 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',
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(BaseTestCase::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
}
|
||||
|
||||
public function testProvideEmptyValue()
|
||||
/**
|
||||
* @param string $fileName Name of file
|
||||
* @param string $directoryPath Path of directory containing the file
|
||||
*
|
||||
* @dataProvider provideFileNameAndDirectoryPath
|
||||
*/
|
||||
public function testGetFilePathForTesting($fileName, $directoryPath)
|
||||
{
|
||||
$elements = [
|
||||
[''],
|
||||
[' '],
|
||||
[null],
|
||||
[0],
|
||||
[false],
|
||||
[[]],
|
||||
];
|
||||
$path = (new SimpleTestCase())->getFilePathForTesting($fileName, $directoryPath);
|
||||
|
||||
$generator = (new SimpleTestCase())->provideEmptyValue();
|
||||
self::assertEquals($elements, GeneratorUtility::getGeneratorElements($generator));
|
||||
if (!empty($directoryPath)) {
|
||||
$directoryPath .= '/';
|
||||
}
|
||||
|
||||
$expectedContains = sprintf('/data/tests/%s%s', $directoryPath, $fileName);
|
||||
static::assertStringContainsString($expectedContains, $path);
|
||||
}
|
||||
|
||||
public function testProvideBooleanValue()
|
||||
@@ -109,6 +140,21 @@ class BaseTestCaseTest extends BaseTestCase
|
||||
self::assertEquals($elements, GeneratorUtility::getGeneratorElements($generator));
|
||||
}
|
||||
|
||||
public function testProvideEmptyValue()
|
||||
{
|
||||
$elements = [
|
||||
[''],
|
||||
[' '],
|
||||
[null],
|
||||
[0],
|
||||
[false],
|
||||
[[]],
|
||||
];
|
||||
|
||||
$generator = (new SimpleTestCase())->provideEmptyValue();
|
||||
self::assertEquals($elements, GeneratorUtility::getGeneratorElements($generator));
|
||||
}
|
||||
|
||||
public function testProvideNotExistingFilePath()
|
||||
{
|
||||
$elements = [
|
||||
@@ -120,52 +166,6 @@ class BaseTestCaseTest extends BaseTestCase
|
||||
$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::assertStringContainsString($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',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,6 +33,17 @@ class BaseTestCaseTraitTest extends BaseTestCase
|
||||
{
|
||||
use BaseTestCaseTrait;
|
||||
|
||||
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 testAssertMethodVisibility(): void
|
||||
{
|
||||
$method = new ReflectionMethod(SimpleTestCase::class, 'assertMethodVisibility');
|
||||
@@ -53,54 +64,6 @@ class BaseTestCaseTraitTest extends BaseTestCase
|
||||
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();
|
||||
$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();
|
||||
@@ -164,19 +127,40 @@ class BaseTestCaseTraitTest extends BaseTestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testProvideNotExistingFilePath(): void
|
||||
public function testProvideEmptyScalarValue(): void
|
||||
{
|
||||
$testCase = new SimpleTestCase();
|
||||
$paths = $testCase->provideNotExistingFilePath();
|
||||
$values = $testCase->provideEmptyScalarValue();
|
||||
|
||||
$expected = [
|
||||
['lets-test.doc'],
|
||||
['lorem/ipsum.jpg'],
|
||||
['surprise/me/one/more/time.txt'],
|
||||
[''],
|
||||
[' '],
|
||||
[null],
|
||||
[0],
|
||||
[false],
|
||||
];
|
||||
|
||||
foreach ($paths as $index => $path) {
|
||||
static::assertSame($expected[$index], $path);
|
||||
foreach ($values as $index => $value) {
|
||||
static::assertSame($expected[$index], $value);
|
||||
}
|
||||
}
|
||||
|
||||
public function testProvideEmptyValue(): void
|
||||
{
|
||||
$testCase = new SimpleTestCase();
|
||||
$values = $testCase->provideEmptyValue();
|
||||
|
||||
$expected = [
|
||||
[''],
|
||||
[' '],
|
||||
[null],
|
||||
[0],
|
||||
[false],
|
||||
[[]],
|
||||
];
|
||||
|
||||
foreach ($values as $index => $value) {
|
||||
static::assertSame($expected[$index], $value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,4 +179,20 @@ class BaseTestCaseTraitTest extends BaseTestCase
|
||||
static::assertEquals($expected[$index], $value);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,138 @@ use Meritoo\Common\Type\Base\BaseType;
|
||||
*/
|
||||
class BaseTypeTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Provides type of something for testing the getAll() method
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideType(): ?Generator
|
||||
{
|
||||
yield [
|
||||
new TestEmptyType(),
|
||||
[],
|
||||
];
|
||||
|
||||
yield [
|
||||
new TestType(),
|
||||
[
|
||||
'TEST_1' => TestType::TEST_1,
|
||||
'TEST_2' => TestType::TEST_2,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides type of something for testing the isCorrectType() method
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideTypeToVerifyUsingTestEmptyType(): ?Generator
|
||||
{
|
||||
yield [
|
||||
null,
|
||||
false,
|
||||
];
|
||||
|
||||
yield [
|
||||
'null',
|
||||
false,
|
||||
];
|
||||
|
||||
yield [
|
||||
'false',
|
||||
false,
|
||||
];
|
||||
|
||||
yield [
|
||||
'true',
|
||||
false,
|
||||
];
|
||||
|
||||
yield [
|
||||
'',
|
||||
false,
|
||||
];
|
||||
|
||||
yield [
|
||||
'0',
|
||||
false,
|
||||
];
|
||||
|
||||
yield [
|
||||
'1',
|
||||
false,
|
||||
];
|
||||
|
||||
yield [
|
||||
'lorem',
|
||||
false,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides type of something for testing the isCorrectType() method
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideTypeToVerifyUsingTestType(): ?Generator
|
||||
{
|
||||
yield [
|
||||
null,
|
||||
false,
|
||||
];
|
||||
|
||||
yield [
|
||||
'null',
|
||||
false,
|
||||
];
|
||||
|
||||
yield [
|
||||
'false',
|
||||
false,
|
||||
];
|
||||
|
||||
yield [
|
||||
'true',
|
||||
false,
|
||||
];
|
||||
|
||||
yield [
|
||||
'',
|
||||
false,
|
||||
];
|
||||
|
||||
yield [
|
||||
'0',
|
||||
false,
|
||||
];
|
||||
|
||||
yield [
|
||||
'1',
|
||||
false,
|
||||
];
|
||||
|
||||
yield [
|
||||
'lorem',
|
||||
false,
|
||||
];
|
||||
|
||||
yield [
|
||||
'test',
|
||||
false,
|
||||
];
|
||||
|
||||
yield [
|
||||
'test_1',
|
||||
true,
|
||||
];
|
||||
|
||||
yield [
|
||||
'test_2',
|
||||
true,
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
static::assertHasNoConstructor(BaseType::class);
|
||||
@@ -61,138 +193,6 @@ class BaseTypeTest extends BaseTestCase
|
||||
{
|
||||
self::assertEquals($isCorrect, TestType::isCorrectType($toVerifyType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides type of something for testing the getAll() method
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideType(): ?Generator
|
||||
{
|
||||
yield[
|
||||
new TestEmptyType(),
|
||||
[],
|
||||
];
|
||||
|
||||
yield[
|
||||
new TestType(),
|
||||
[
|
||||
'TEST_1' => TestType::TEST_1,
|
||||
'TEST_2' => TestType::TEST_2,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides type of something for testing the isCorrectType() method
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideTypeToVerifyUsingTestEmptyType(): ?Generator
|
||||
{
|
||||
yield[
|
||||
null,
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'null',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'false',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'true',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'0',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'1',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'lorem',
|
||||
false,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides type of something for testing the isCorrectType() method
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideTypeToVerifyUsingTestType(): ?Generator
|
||||
{
|
||||
yield[
|
||||
null,
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'null',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'false',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'true',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'0',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'1',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'lorem',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'test',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'test_1',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'test_2',
|
||||
true,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,7 +20,7 @@ use Meritoo\Common\Type\DatePartType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Type\DatePartType
|
||||
* @covers \Meritoo\Common\Type\DatePartType
|
||||
*/
|
||||
class DatePartTypeTest extends BaseTypeTestCase
|
||||
{
|
||||
@@ -29,52 +29,52 @@ class DatePartTypeTest extends BaseTypeTestCase
|
||||
*/
|
||||
public function provideTypeToVerify(): Generator
|
||||
{
|
||||
yield[
|
||||
yield [
|
||||
DatePartType::isCorrectType(''),
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
yield [
|
||||
DatePartType::isCorrectType(null),
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
yield [
|
||||
DatePartType::isCorrectType('0'),
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
yield [
|
||||
DatePartType::isCorrectType('1'),
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
yield [
|
||||
DatePartType::isCorrectType('day'),
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
yield [
|
||||
DatePartType::isCorrectType('hour'),
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
yield [
|
||||
DatePartType::isCorrectType('minute'),
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
yield [
|
||||
DatePartType::isCorrectType('month'),
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
yield [
|
||||
DatePartType::isCorrectType('second'),
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
yield [
|
||||
DatePartType::isCorrectType('year'),
|
||||
true,
|
||||
];
|
||||
@@ -86,12 +86,12 @@ class DatePartTypeTest extends BaseTypeTestCase
|
||||
protected function getAllExpectedTypes(): array
|
||||
{
|
||||
return [
|
||||
'DAY' => 'day',
|
||||
'HOUR' => 'hour',
|
||||
'DAY' => 'day',
|
||||
'HOUR' => 'hour',
|
||||
'MINUTE' => 'minute',
|
||||
'MONTH' => 'month',
|
||||
'MONTH' => 'month',
|
||||
'SECOND' => 'second',
|
||||
'YEAR' => 'year',
|
||||
'YEAR' => 'year',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -26,13 +26,222 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
*/
|
||||
class DatePeriodTest extends BaseTypeTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments(): void
|
||||
/**
|
||||
* Provides the start and end date of date period
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideDatePeriod(): Generator
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
DatePeriod::class,
|
||||
OopVisibilityType::IS_PUBLIC,
|
||||
2
|
||||
);
|
||||
$startDate = new DateTime('2001-01-01');
|
||||
$endDate = new DateTime('2002-02-02');
|
||||
|
||||
yield [
|
||||
null,
|
||||
null,
|
||||
];
|
||||
|
||||
yield [
|
||||
$startDate,
|
||||
$startDate,
|
||||
null,
|
||||
];
|
||||
|
||||
yield [
|
||||
null,
|
||||
null,
|
||||
$endDate,
|
||||
];
|
||||
|
||||
yield [
|
||||
$startDate,
|
||||
$endDate,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides period and format of date to verify
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideDatePeriodAndDateFormat(): Generator
|
||||
{
|
||||
$startDate = new DateTime('2001-01-01');
|
||||
$endDate = new DateTime('2002-02-02');
|
||||
|
||||
// For start date
|
||||
yield [
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'Y',
|
||||
true,
|
||||
'2001',
|
||||
];
|
||||
|
||||
yield [
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'D',
|
||||
true,
|
||||
'Mon',
|
||||
];
|
||||
|
||||
yield [
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'Y-m-d',
|
||||
true,
|
||||
'2001-01-01',
|
||||
];
|
||||
|
||||
yield [
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'Y-m-d H:i',
|
||||
true,
|
||||
'2001-01-01 00:00',
|
||||
];
|
||||
|
||||
// For end date
|
||||
yield [
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'Y',
|
||||
false,
|
||||
'2002',
|
||||
];
|
||||
|
||||
yield [
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'D',
|
||||
false,
|
||||
'Sat',
|
||||
];
|
||||
|
||||
yield [
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'Y-m-d',
|
||||
false,
|
||||
'2002-02-02',
|
||||
];
|
||||
|
||||
yield [
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'Y-m-d H:i',
|
||||
false,
|
||||
'2002-02-02 00:00',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides period and format of date to verify using the start date
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideDatePeriodAndDateFormatUsingStartDateOnly(): Generator
|
||||
{
|
||||
$startDate = new DateTime('2001-01-01');
|
||||
$endDate = new DateTime('2002-02-02');
|
||||
|
||||
yield [
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'Y',
|
||||
'2001',
|
||||
];
|
||||
|
||||
yield [
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'D',
|
||||
'Mon',
|
||||
];
|
||||
|
||||
yield [
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'Y-m-d',
|
||||
'2001-01-01',
|
||||
];
|
||||
|
||||
yield [
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'Y-m-d H:i',
|
||||
'2001-01-01 00:00',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides period and incorrect format of date to verify
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideDatePeriodAndIncorrectDateFormat(): Generator
|
||||
{
|
||||
$startDate = new DateTime('2001-01-01');
|
||||
$endDate = new DateTime('2002-02-02');
|
||||
|
||||
yield [
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'',
|
||||
];
|
||||
|
||||
yield [
|
||||
new DatePeriod($startDate, $endDate),
|
||||
false,
|
||||
];
|
||||
}
|
||||
|
||||
public function provideDatePeriodAndUnknownDate(): ?Generator
|
||||
{
|
||||
$date = new DateTime('2001-01-01');
|
||||
|
||||
yield [
|
||||
new DatePeriod(),
|
||||
'Y-m-d',
|
||||
false,
|
||||
];
|
||||
|
||||
yield [
|
||||
new DatePeriod(),
|
||||
'Y-m-d',
|
||||
true,
|
||||
];
|
||||
|
||||
yield [
|
||||
new DatePeriod($date),
|
||||
'Y-m-d',
|
||||
false,
|
||||
];
|
||||
|
||||
yield [
|
||||
new DatePeriod(null, $date),
|
||||
'Y-m-d',
|
||||
true,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function provideTypeToVerify(): Generator
|
||||
{
|
||||
yield [
|
||||
DatePeriod::isCorrectType(''),
|
||||
false,
|
||||
];
|
||||
|
||||
yield [
|
||||
DatePeriod::isCorrectType('-1'),
|
||||
false,
|
||||
];
|
||||
|
||||
yield [
|
||||
DatePeriod::isCorrectType('4'),
|
||||
true,
|
||||
];
|
||||
|
||||
yield [
|
||||
DatePeriod::isCorrectType('3'),
|
||||
true,
|
||||
];
|
||||
|
||||
yield [
|
||||
DatePeriod::isCorrectType('8'),
|
||||
true,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,6 +258,63 @@ class DatePeriodTest extends BaseTypeTestCase
|
||||
self::assertEquals($endDate, $period->getEndDate());
|
||||
}
|
||||
|
||||
public function testConstructorVisibilityAndArguments(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
DatePeriod::class,
|
||||
OopVisibilityType::IS_PUBLIC,
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DatePeriod $period The date period to verify
|
||||
* @param string $format Format used to format the date
|
||||
* @param bool $startDate If is set to true, start date is formatted. Otherwise - end date.
|
||||
* @param string $expected Expected, formatted date
|
||||
*
|
||||
* @dataProvider provideDatePeriodAndDateFormat
|
||||
*/
|
||||
public function testGetFormattedDate(DatePeriod $period, $format, $startDate, $expected): void
|
||||
{
|
||||
self::assertEquals($expected, $period->getFormattedDate($format, $startDate));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DatePeriod $period The date period to verify
|
||||
* @param string $format Format used to format the date
|
||||
*
|
||||
* @dataProvider provideDatePeriodAndIncorrectDateFormat
|
||||
*/
|
||||
public function testGetFormattedDateUsingIncorrectDateFormat(DatePeriod $period, $format): void
|
||||
{
|
||||
self::assertEquals('', $period->getFormattedDate($format));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DatePeriod $period The date period to verify
|
||||
* @param string $format Format used to format the date
|
||||
* @param string $expected Expected, formatted date
|
||||
*
|
||||
* @dataProvider provideDatePeriodAndDateFormatUsingStartDateOnly
|
||||
*/
|
||||
public function testGetFormattedDateUsingStartDateOnly(DatePeriod $period, $format, $expected): void
|
||||
{
|
||||
self::assertEquals($expected, $period->getFormattedDate($format));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DatePeriod $period The date period to verify
|
||||
* @param string $format Format used to format the date
|
||||
* @param bool $startDate If is set to true, start date is formatted. Otherwise - end date.
|
||||
*
|
||||
* @dataProvider provideDatePeriodAndUnknownDate
|
||||
*/
|
||||
public function testGetFormattedDateUsingUnknownDate(DatePeriod $period, $format, $startDate): void
|
||||
{
|
||||
self::assertEquals('', $period->getFormattedDate($format, $startDate));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTime $startDate (optional) Start date of period
|
||||
* @param DateTime $endDate (optional) End date of period
|
||||
@@ -66,272 +332,6 @@ class DatePeriodTest extends BaseTypeTestCase
|
||||
self::assertEquals($endDate, $period->getEndDate());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DatePeriod $period The date period to verify
|
||||
* @param string $format Format used to format the date
|
||||
*
|
||||
* @dataProvider provideDatePeriodAndIncorrectDateFormat
|
||||
*/
|
||||
public function testGetFormattedDateUsingIncorrectDateFormat(DatePeriod $period, $format): void
|
||||
{
|
||||
self::assertEquals('', $period->getFormattedDate($format));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DatePeriod $period The date period to verify
|
||||
* @param string $format Format used to format the date
|
||||
* @param bool $startDate If is set to true, start date is formatted. Otherwise - end date.
|
||||
*
|
||||
* @dataProvider provideDatePeriodAndUnknownDate
|
||||
*/
|
||||
public function testGetFormattedDateUsingUnknownDate(DatePeriod $period, $format, $startDate): void
|
||||
{
|
||||
self::assertEquals('', $period->getFormattedDate($format, $startDate));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DatePeriod $period The date period to verify
|
||||
* @param string $format Format used to format the date
|
||||
* @param string $expected Expected, formatted date
|
||||
*
|
||||
* @dataProvider provideDatePeriodAndDateFormatUsingStartDateOnly
|
||||
*/
|
||||
public function testGetFormattedDateUsingStartDateOnly(DatePeriod $period, $format, $expected): void
|
||||
{
|
||||
self::assertEquals($expected, $period->getFormattedDate($format));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DatePeriod $period The date period to verify
|
||||
* @param string $format Format used to format the date
|
||||
* @param bool $startDate If is set to true, start date is formatted. Otherwise - end date.
|
||||
* @param string $expected Expected, formatted date
|
||||
*
|
||||
* @dataProvider provideDatePeriodAndDateFormat
|
||||
*/
|
||||
public function testGetFormattedDate(DatePeriod $period, $format, $startDate, $expected): void
|
||||
{
|
||||
self::assertEquals($expected, $period->getFormattedDate($format, $startDate));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the start and end date of date period
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideDatePeriod(): Generator
|
||||
{
|
||||
$startDate = new DateTime('2001-01-01');
|
||||
$endDate = new DateTime('2002-02-02');
|
||||
|
||||
yield[
|
||||
null,
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
$startDate,
|
||||
$startDate,
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
null,
|
||||
null,
|
||||
$endDate,
|
||||
];
|
||||
|
||||
yield[
|
||||
$startDate,
|
||||
$endDate,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides period and incorrect format of date to verify
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideDatePeriodAndIncorrectDateFormat(): Generator
|
||||
{
|
||||
$startDate = new DateTime('2001-01-01');
|
||||
$endDate = new DateTime('2002-02-02');
|
||||
|
||||
yield[
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'',
|
||||
];
|
||||
|
||||
yield[
|
||||
new DatePeriod($startDate, $endDate),
|
||||
false,
|
||||
];
|
||||
}
|
||||
|
||||
public function provideDatePeriodAndUnknownDate(): ?Generator
|
||||
{
|
||||
$date = new DateTime('2001-01-01');
|
||||
|
||||
yield[
|
||||
new DatePeriod(),
|
||||
'Y-m-d',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
new DatePeriod(),
|
||||
'Y-m-d',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
new DatePeriod($date),
|
||||
'Y-m-d',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
new DatePeriod(null, $date),
|
||||
'Y-m-d',
|
||||
true,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides period and format of date to verify using the start date
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideDatePeriodAndDateFormatUsingStartDateOnly(): Generator
|
||||
{
|
||||
$startDate = new DateTime('2001-01-01');
|
||||
$endDate = new DateTime('2002-02-02');
|
||||
|
||||
yield[
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'Y',
|
||||
'2001',
|
||||
];
|
||||
|
||||
yield[
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'D',
|
||||
'Mon',
|
||||
];
|
||||
|
||||
yield[
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'Y-m-d',
|
||||
'2001-01-01',
|
||||
];
|
||||
|
||||
yield[
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'Y-m-d H:i',
|
||||
'2001-01-01 00:00',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides period and format of date to verify
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideDatePeriodAndDateFormat(): Generator
|
||||
{
|
||||
$startDate = new DateTime('2001-01-01');
|
||||
$endDate = new DateTime('2002-02-02');
|
||||
|
||||
// For start date
|
||||
yield[
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'Y',
|
||||
true,
|
||||
'2001',
|
||||
];
|
||||
|
||||
yield[
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'D',
|
||||
true,
|
||||
'Mon',
|
||||
];
|
||||
|
||||
yield[
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'Y-m-d',
|
||||
true,
|
||||
'2001-01-01',
|
||||
];
|
||||
|
||||
yield[
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'Y-m-d H:i',
|
||||
true,
|
||||
'2001-01-01 00:00',
|
||||
];
|
||||
|
||||
// For end date
|
||||
yield[
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'Y',
|
||||
false,
|
||||
'2002',
|
||||
];
|
||||
|
||||
yield[
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'D',
|
||||
false,
|
||||
'Sat',
|
||||
];
|
||||
|
||||
yield[
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'Y-m-d',
|
||||
false,
|
||||
'2002-02-02',
|
||||
];
|
||||
|
||||
yield[
|
||||
new DatePeriod($startDate, $endDate),
|
||||
'Y-m-d H:i',
|
||||
false,
|
||||
'2002-02-02 00:00',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function provideTypeToVerify(): Generator
|
||||
{
|
||||
yield[
|
||||
DatePeriod::isCorrectType(''),
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
DatePeriod::isCorrectType('-1'),
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
DatePeriod::isCorrectType('4'),
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
DatePeriod::isCorrectType('3'),
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
DatePeriod::isCorrectType('8'),
|
||||
true,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all expected types of the tested type
|
||||
*
|
||||
@@ -341,14 +341,14 @@ class DatePeriodTest extends BaseTypeTestCase
|
||||
{
|
||||
return [
|
||||
'LAST_MONTH' => 4,
|
||||
'LAST_WEEK' => 1,
|
||||
'LAST_YEAR' => 7,
|
||||
'LAST_WEEK' => 1,
|
||||
'LAST_YEAR' => 7,
|
||||
'NEXT_MONTH' => 6,
|
||||
'NEXT_WEEK' => 3,
|
||||
'NEXT_YEAR' => 9,
|
||||
'NEXT_WEEK' => 3,
|
||||
'NEXT_YEAR' => 9,
|
||||
'THIS_MONTH' => 5,
|
||||
'THIS_WEEK' => 2,
|
||||
'THIS_YEAR' => 8,
|
||||
'THIS_WEEK' => 2,
|
||||
'THIS_YEAR' => 8,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -29,32 +29,32 @@ class OopVisibilityTypeTest extends BaseTypeTestCase
|
||||
*/
|
||||
public function provideTypeToVerify(): Generator
|
||||
{
|
||||
yield[
|
||||
yield [
|
||||
OopVisibilityType::isCorrectType(''),
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
yield [
|
||||
OopVisibilityType::isCorrectType(null),
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
yield [
|
||||
OopVisibilityType::isCorrectType('-1'),
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
yield [
|
||||
OopVisibilityType::isCorrectType('1'),
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
yield [
|
||||
OopVisibilityType::isCorrectType('2'),
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
yield [
|
||||
OopVisibilityType::isCorrectType('3'),
|
||||
true,
|
||||
];
|
||||
@@ -66,9 +66,9 @@ class OopVisibilityTypeTest extends BaseTypeTestCase
|
||||
protected function getAllExpectedTypes(): array
|
||||
{
|
||||
return [
|
||||
'IS_PRIVATE' => 3,
|
||||
'IS_PRIVATE' => 3,
|
||||
'IS_PROTECTED' => 2,
|
||||
'IS_PUBLIC' => 1,
|
||||
'IS_PUBLIC' => 1,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -8,6 +8,7 @@
|
||||
|
||||
namespace Meritoo\Test\Common\Utilities;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Utilities\Bootstrap4CssSelector;
|
||||
|
||||
@@ -18,28 +19,145 @@ use Meritoo\Common\Utilities\Bootstrap4CssSelector;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Utilities\Bootstrap4CssSelector
|
||||
* @covers \Meritoo\Common\Utilities\Bootstrap4CssSelector
|
||||
*/
|
||||
class Bootstrap4CssSelectorTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Provides name of form and expected selector
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideFormNameAndSelector()
|
||||
{
|
||||
yield [
|
||||
'test',
|
||||
'form[name="test"] .form-group',
|
||||
];
|
||||
|
||||
yield [
|
||||
'test-123-test-456',
|
||||
'form[name="test-123-test-456"] .form-group',
|
||||
];
|
||||
|
||||
yield [
|
||||
'test_something_098_different',
|
||||
'form[name="test_something_098_different"] .form-group',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides name of form, name of field and expected selector
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideFormNameFieldNameAndSelector()
|
||||
{
|
||||
yield [
|
||||
'test',
|
||||
'test',
|
||||
'form[name="test"] label[for="test"] .invalid-feedback .form-error-message',
|
||||
];
|
||||
|
||||
yield [
|
||||
'test-123-test-456',
|
||||
'great-000-field',
|
||||
'form[name="test-123-test-456"] label[for="great-000-field"] .invalid-feedback .form-error-message',
|
||||
];
|
||||
|
||||
yield [
|
||||
'test_something_098_different',
|
||||
'this-is-the-123789-field',
|
||||
'form[name="test_something_098_different"] label[for="this-is-the-123789-field"] .invalid-feedback .form-error-message',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides name of form, index/position of the field-set and expected selector
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideFormNameFieldSetIndexAndSelector()
|
||||
{
|
||||
yield [
|
||||
'test',
|
||||
0,
|
||||
'form[name="test"] fieldset:nth-of-type(0) legend.col-form-label .invalid-feedback .form-error-message',
|
||||
];
|
||||
|
||||
yield [
|
||||
'test-123-test-456',
|
||||
1,
|
||||
'form[name="test-123-test-456"] fieldset:nth-of-type(1) legend.col-form-label .invalid-feedback .form-error-message',
|
||||
];
|
||||
|
||||
yield [
|
||||
'test_something_098_different',
|
||||
1245,
|
||||
'form[name="test_something_098_different"] fieldset:nth-of-type(1245) legend.col-form-label .invalid-feedback .form-error-message',
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
static::assertHasNoConstructor(Bootstrap4CssSelector::class);
|
||||
}
|
||||
|
||||
public function testGetFieldErrorContainerSelector()
|
||||
{
|
||||
static::assertSame('.invalid-feedback .form-error-message', Bootstrap4CssSelector::getFieldErrorContainerSelector());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $formName Name of form (value of the "name" attribute)
|
||||
* @param string $fieldName Name of field (value of the "name" attribute)
|
||||
* @param string $expected Expected selector
|
||||
*
|
||||
* @dataProvider provideFormNameFieldNameAndSelector
|
||||
*/
|
||||
public function testGetFieldErrorSelector($formName, $fieldName, $expected)
|
||||
{
|
||||
static::assertSame($expected, Bootstrap4CssSelector::getFieldErrorSelector($formName, $fieldName));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $emptyValue Name of field (value of the "name" attribute)
|
||||
* @dataProvider provideEmptyScalarValue
|
||||
*/
|
||||
public function testGetFieldErrorSelectorUsingEmptyFieldName($emptyValue)
|
||||
{
|
||||
$formName = 'test';
|
||||
static::assertSame('', Bootstrap4CssSelector::getFieldErrorSelector($formName, $emptyValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $emptyValue Name of form (value of the "name" attribute)
|
||||
* @dataProvider provideEmptyScalarValue
|
||||
*/
|
||||
public function testGetRadioButtonErrorSelectorUsingEmptyFormName($emptyValue)
|
||||
public function testGetFieldErrorSelectorUsingEmptyFormName($emptyValue)
|
||||
{
|
||||
$fieldSetIndex = 1;
|
||||
static::assertSame('', Bootstrap4CssSelector::getRadioButtonErrorSelector($emptyValue, $fieldSetIndex));
|
||||
$fieldName = 'test';
|
||||
static::assertSame('', Bootstrap4CssSelector::getFieldErrorSelector($emptyValue, $fieldName));
|
||||
}
|
||||
|
||||
public function testGetRadioButtonErrorSelectorUsingNegativeFieldSetIndex()
|
||||
/**
|
||||
* @param string $formName Name of form (value of the "name" attribute)
|
||||
* @param string $expected Expected selector
|
||||
*
|
||||
* @dataProvider provideFormNameAndSelector
|
||||
*/
|
||||
public function testGetFieldGroupSelector($formName, $expected)
|
||||
{
|
||||
static::assertSame('', Bootstrap4CssSelector::getRadioButtonErrorSelector('test-test', -1));
|
||||
static::assertSame($expected, Bootstrap4CssSelector::getFieldGroupSelector($formName));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $emptyValue Name of form (value of the "name" attribute)
|
||||
* @dataProvider provideEmptyScalarValue
|
||||
*/
|
||||
public function testGetFieldGroupSelectorUsingEmptyFormName($emptyValue)
|
||||
{
|
||||
static::assertSame('', Bootstrap4CssSelector::getFieldGroupSelector($emptyValue));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,131 +176,14 @@ class Bootstrap4CssSelectorTest extends BaseTestCase
|
||||
* @param string $emptyValue Name of form (value of the "name" attribute)
|
||||
* @dataProvider provideEmptyScalarValue
|
||||
*/
|
||||
public function testGetFieldErrorSelectorUsingEmptyFormName($emptyValue)
|
||||
public function testGetRadioButtonErrorSelectorUsingEmptyFormName($emptyValue)
|
||||
{
|
||||
$fieldName = 'test';
|
||||
static::assertSame('', Bootstrap4CssSelector::getFieldErrorSelector($emptyValue, $fieldName));
|
||||
$fieldSetIndex = 1;
|
||||
static::assertSame('', Bootstrap4CssSelector::getRadioButtonErrorSelector($emptyValue, $fieldSetIndex));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $emptyValue Name of field (value of the "name" attribute)
|
||||
* @dataProvider provideEmptyScalarValue
|
||||
*/
|
||||
public function testGetFieldErrorSelectorUsingEmptyFieldName($emptyValue)
|
||||
public function testGetRadioButtonErrorSelectorUsingNegativeFieldSetIndex()
|
||||
{
|
||||
$formName = 'test';
|
||||
static::assertSame('', Bootstrap4CssSelector::getFieldErrorSelector($formName, $emptyValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $formName Name of form (value of the "name" attribute)
|
||||
* @param string $fieldName Name of field (value of the "name" attribute)
|
||||
* @param string $expected Expected selector
|
||||
*
|
||||
* @dataProvider provideFormNameFieldNameAndSelector
|
||||
*/
|
||||
public function testGetFieldErrorSelector($formName, $fieldName, $expected)
|
||||
{
|
||||
static::assertSame($expected, Bootstrap4CssSelector::getFieldErrorSelector($formName, $fieldName));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $emptyValue Name of form (value of the "name" attribute)
|
||||
* @dataProvider provideEmptyScalarValue
|
||||
*/
|
||||
public function testGetFieldGroupSelectorUsingEmptyFormName($emptyValue)
|
||||
{
|
||||
static::assertSame('', Bootstrap4CssSelector::getFieldGroupSelector($emptyValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $formName Name of form (value of the "name" attribute)
|
||||
* @param string $expected Expected selector
|
||||
*
|
||||
* @dataProvider provideFormNameAndSelector
|
||||
*/
|
||||
public function testGetFieldGroupSelector($formName, $expected)
|
||||
{
|
||||
static::assertSame($expected, Bootstrap4CssSelector::getFieldGroupSelector($formName));
|
||||
}
|
||||
|
||||
public function testGetFieldErrorContainerSelector()
|
||||
{
|
||||
static::assertSame('.invalid-feedback .form-error-message', Bootstrap4CssSelector::getFieldErrorContainerSelector());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides name of form, index/position of the field-set and expected selector
|
||||
*
|
||||
* @return \Generator
|
||||
*/
|
||||
public function provideFormNameFieldSetIndexAndSelector()
|
||||
{
|
||||
yield[
|
||||
'test',
|
||||
0,
|
||||
'form[name="test"] fieldset:nth-of-type(0) legend.col-form-label .invalid-feedback .form-error-message',
|
||||
];
|
||||
|
||||
yield[
|
||||
'test-123-test-456',
|
||||
1,
|
||||
'form[name="test-123-test-456"] fieldset:nth-of-type(1) legend.col-form-label .invalid-feedback .form-error-message',
|
||||
];
|
||||
|
||||
yield[
|
||||
'test_something_098_different',
|
||||
1245,
|
||||
'form[name="test_something_098_different"] fieldset:nth-of-type(1245) legend.col-form-label .invalid-feedback .form-error-message',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides name of form, name of field and expected selector
|
||||
*
|
||||
* @return \Generator
|
||||
*/
|
||||
public function provideFormNameFieldNameAndSelector()
|
||||
{
|
||||
yield[
|
||||
'test',
|
||||
'test',
|
||||
'form[name="test"] label[for="test"] .invalid-feedback .form-error-message',
|
||||
];
|
||||
|
||||
yield[
|
||||
'test-123-test-456',
|
||||
'great-000-field',
|
||||
'form[name="test-123-test-456"] label[for="great-000-field"] .invalid-feedback .form-error-message',
|
||||
];
|
||||
|
||||
yield[
|
||||
'test_something_098_different',
|
||||
'this-is-the-123789-field',
|
||||
'form[name="test_something_098_different"] label[for="this-is-the-123789-field"] .invalid-feedback .form-error-message',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides name of form and expected selector
|
||||
*
|
||||
* @return \Generator
|
||||
*/
|
||||
public function provideFormNameAndSelector()
|
||||
{
|
||||
yield[
|
||||
'test',
|
||||
'form[name="test"] .form-group',
|
||||
];
|
||||
|
||||
yield[
|
||||
'test-123-test-456',
|
||||
'form[name="test-123-test-456"] .form-group',
|
||||
];
|
||||
|
||||
yield[
|
||||
'test_something_098_different',
|
||||
'form[name="test_something_098_different"] .form-group',
|
||||
];
|
||||
static::assertSame('', Bootstrap4CssSelector::getRadioButtonErrorSelector('test-test', -1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,15 +20,174 @@ use Meritoo\Common\Utilities\Bundle;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Utilities\Bundle
|
||||
* @covers \Meritoo\Common\Utilities\Bundle
|
||||
*/
|
||||
class BundleTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Provides empty path of the view / template and/or name of bundle
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideEmptyViewPathAndBundle()
|
||||
{
|
||||
yield [
|
||||
'',
|
||||
'',
|
||||
];
|
||||
|
||||
yield [
|
||||
'test',
|
||||
'',
|
||||
];
|
||||
|
||||
yield [
|
||||
'',
|
||||
'test',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides full and short name of bundle
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideFullAndShortBundleName()
|
||||
{
|
||||
yield [
|
||||
'MyExtraBundle',
|
||||
'MyExtra',
|
||||
];
|
||||
|
||||
yield [
|
||||
'MySuperExtraGorgeousBundle',
|
||||
'MySuperExtraGorgeous',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides incorrect name of bundle
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideIncorrectBundleName()
|
||||
{
|
||||
yield [
|
||||
'myExtra',
|
||||
];
|
||||
|
||||
yield [
|
||||
'MyExtra',
|
||||
];
|
||||
|
||||
yield [
|
||||
'MySuperExtraGorgeous',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides path of the view / template and name of bundle
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideViewPathAndBundle()
|
||||
{
|
||||
yield [
|
||||
'User',
|
||||
'MyExtraBundle',
|
||||
'@MyExtra/User.html.twig',
|
||||
];
|
||||
|
||||
yield [
|
||||
'User:Active',
|
||||
'MyExtraBundle',
|
||||
'@MyExtra/User/Active.html.twig',
|
||||
];
|
||||
|
||||
yield [
|
||||
'User:Active',
|
||||
'MySuperExtraGorgeousBundle',
|
||||
'@MySuperExtraGorgeous/User/Active.html.twig',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides path of the view / template, name of bundle and extension of the view / template
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideViewPathAndBundleAndExtension()
|
||||
{
|
||||
yield [
|
||||
'User:Active',
|
||||
'MyExtraBundle',
|
||||
'',
|
||||
null,
|
||||
];
|
||||
|
||||
yield [
|
||||
'User:Active',
|
||||
'MyExtraBundle',
|
||||
'js.twig',
|
||||
'@MyExtra/User/Active.js.twig',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides path of the view / template and incorrect name of bundle
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideViewPathAndIncorrectBundleName()
|
||||
{
|
||||
yield [
|
||||
'User:Active',
|
||||
'myExtra',
|
||||
];
|
||||
|
||||
yield [
|
||||
'User:Active',
|
||||
'MyExtra',
|
||||
];
|
||||
|
||||
yield [
|
||||
'User:Active',
|
||||
'MySuperExtraGorgeous',
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
static::assertHasNoConstructor(Bundle::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $viewPath Path of the view / template, e.g. "MyDirectory/my-template"
|
||||
* @param string $bundleName Full name of the bundle, e.g. "MyExtraBundle"
|
||||
* @param string $extension (optional) Extension of the view / template
|
||||
* @param string $expected Expected path to view / template
|
||||
*
|
||||
* @throws IncorrectBundleNameException
|
||||
* @dataProvider provideViewPathAndBundleAndExtension
|
||||
*/
|
||||
public function testGetBundleViewPathUsingCustomExtension($viewPath, $bundleName, $extension, $expected)
|
||||
{
|
||||
self::assertEquals($expected, Bundle::getBundleViewPath($viewPath, $bundleName, $extension));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $viewPath Path of the view / template, e.g. "MyDirectory/my-template"
|
||||
* @param string $bundleName Full name of the bundle, e.g. "MyExtraBundle"
|
||||
* @param string $expected Expected path to view / template
|
||||
*
|
||||
* @throws IncorrectBundleNameException
|
||||
* @dataProvider provideViewPathAndBundle
|
||||
*/
|
||||
public function testGetBundleViewPathUsingDefaultExtension($viewPath, $bundleName, $expected)
|
||||
{
|
||||
self::assertEquals($expected, Bundle::getBundleViewPath($viewPath, $bundleName));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $viewPath Path of the view / template, e.g. "MyDirectory/my-template"
|
||||
* @param string $bundleName Full name of the bundle, e.g. "MyExtraBundle"
|
||||
@@ -50,7 +209,7 @@ class BundleTest extends BaseTestCase
|
||||
public function testGetBundleViewPathUsingIncorrectBundleName($viewPath, $bundleName)
|
||||
{
|
||||
$template = 'Name of bundle \'%s\' is incorrect. It should start with big letter and end with "Bundle". Is'
|
||||
. ' there everything ok?';
|
||||
.' there everything ok?';
|
||||
|
||||
$this->expectException(IncorrectBundleNameException::class);
|
||||
$this->expectExceptionMessage(sprintf($template, $bundleName));
|
||||
@@ -59,30 +218,15 @@ class BundleTest extends BaseTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $viewPath Path of the view / template, e.g. "MyDirectory/my-template"
|
||||
* @param string $bundleName Full name of the bundle, e.g. "MyExtraBundle"
|
||||
* @param string $expected Expected path to view / template
|
||||
* @param string $fullBundleName Full name of the bundle, e.g. "MyExtraBundle"
|
||||
* @param string $shortBundleName Short name of bundle (without "Bundle")
|
||||
*
|
||||
* @throws IncorrectBundleNameException
|
||||
* @dataProvider provideViewPathAndBundle
|
||||
* @dataProvider provideFullAndShortBundleName
|
||||
*/
|
||||
public function testGetBundleViewPathUsingDefaultExtension($viewPath, $bundleName, $expected)
|
||||
public function testGetShortBundleName($fullBundleName, $shortBundleName)
|
||||
{
|
||||
self::assertEquals($expected, Bundle::getBundleViewPath($viewPath, $bundleName));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $viewPath Path of the view / template, e.g. "MyDirectory/my-template"
|
||||
* @param string $bundleName Full name of the bundle, e.g. "MyExtraBundle"
|
||||
* @param string $extension (optional) Extension of the view / template
|
||||
* @param string $expected Expected path to view / template
|
||||
*
|
||||
* @throws IncorrectBundleNameException
|
||||
* @dataProvider provideViewPathAndBundleAndExtension
|
||||
*/
|
||||
public function testGetBundleViewPathUsingCustomExtension($viewPath, $bundleName, $extension, $expected)
|
||||
{
|
||||
self::assertEquals($expected, Bundle::getBundleViewPath($viewPath, $bundleName, $extension));
|
||||
self::assertEquals($shortBundleName, Bundle::getShortBundleName($fullBundleName));
|
||||
}
|
||||
|
||||
public function testGetShortBundleNameUsingEmptyValue(): void
|
||||
@@ -102,148 +246,4 @@ class BundleTest extends BaseTestCase
|
||||
$this->expectException(IncorrectBundleNameException::class);
|
||||
Bundle::getShortBundleName($bundleName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $fullBundleName Full name of the bundle, e.g. "MyExtraBundle"
|
||||
* @param string $shortBundleName Short name of bundle (without "Bundle")
|
||||
*
|
||||
* @throws IncorrectBundleNameException
|
||||
* @dataProvider provideFullAndShortBundleName
|
||||
*/
|
||||
public function testGetShortBundleName($fullBundleName, $shortBundleName)
|
||||
{
|
||||
self::assertEquals($shortBundleName, Bundle::getShortBundleName($fullBundleName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides empty path of the view / template and/or name of bundle
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideEmptyViewPathAndBundle()
|
||||
{
|
||||
yield[
|
||||
'',
|
||||
'',
|
||||
];
|
||||
|
||||
yield[
|
||||
'test',
|
||||
'',
|
||||
];
|
||||
|
||||
yield[
|
||||
'',
|
||||
'test',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides path of the view / template and incorrect name of bundle
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideViewPathAndIncorrectBundleName()
|
||||
{
|
||||
yield[
|
||||
'User:Active',
|
||||
'myExtra',
|
||||
];
|
||||
|
||||
yield[
|
||||
'User:Active',
|
||||
'MyExtra',
|
||||
];
|
||||
|
||||
yield[
|
||||
'User:Active',
|
||||
'MySuperExtraGorgeous',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides path of the view / template and name of bundle
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideViewPathAndBundle()
|
||||
{
|
||||
yield[
|
||||
'User',
|
||||
'MyExtraBundle',
|
||||
'@MyExtra/User.html.twig',
|
||||
];
|
||||
|
||||
yield[
|
||||
'User:Active',
|
||||
'MyExtraBundle',
|
||||
'@MyExtra/User/Active.html.twig',
|
||||
];
|
||||
|
||||
yield[
|
||||
'User:Active',
|
||||
'MySuperExtraGorgeousBundle',
|
||||
'@MySuperExtraGorgeous/User/Active.html.twig',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides path of the view / template, name of bundle and extension of the view / template
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideViewPathAndBundleAndExtension()
|
||||
{
|
||||
yield[
|
||||
'User:Active',
|
||||
'MyExtraBundle',
|
||||
'',
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
'User:Active',
|
||||
'MyExtraBundle',
|
||||
'js.twig',
|
||||
'@MyExtra/User/Active.js.twig',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides incorrect name of bundle
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideIncorrectBundleName()
|
||||
{
|
||||
yield[
|
||||
'myExtra',
|
||||
];
|
||||
|
||||
yield[
|
||||
'MyExtra',
|
||||
];
|
||||
|
||||
yield[
|
||||
'MySuperExtraGorgeous',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides full and short name of bundle
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideFullAndShortBundleName()
|
||||
{
|
||||
yield[
|
||||
'MyExtraBundle',
|
||||
'MyExtra',
|
||||
];
|
||||
|
||||
yield[
|
||||
'MySuperExtraGorgeousBundle',
|
||||
'MySuperExtraGorgeous',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ use Meritoo\Common\Utilities\Composer;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Utilities\Composer
|
||||
* @covers \Meritoo\Common\Utilities\Composer
|
||||
*/
|
||||
class ComposerTest extends BaseTestCase
|
||||
{
|
||||
@@ -30,11 +30,40 @@ class ComposerTest extends BaseTestCase
|
||||
*/
|
||||
private $composerJsonPath;
|
||||
|
||||
/**
|
||||
* Provides names and values of existing nodes
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function getExistingNode(): Generator
|
||||
{
|
||||
yield [
|
||||
'name',
|
||||
'test/test',
|
||||
];
|
||||
|
||||
yield [
|
||||
'version',
|
||||
'1.0.2',
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
static::assertHasNoConstructor(Composer::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $nodeName Name of existing node
|
||||
* @param string $nodeValue Value of existing node
|
||||
*
|
||||
* @dataProvider getExistingNode
|
||||
*/
|
||||
public function testGetValueExistingNode(string $nodeName, string $nodeValue): void
|
||||
{
|
||||
self::assertEquals($nodeValue, Composer::getValue($this->composerJsonPath, $nodeName));
|
||||
}
|
||||
|
||||
public function testGetValueNotExistingComposerJson(): void
|
||||
{
|
||||
self::assertNull(Composer::getValue('', ''));
|
||||
@@ -47,35 +76,6 @@ class ComposerTest extends BaseTestCase
|
||||
self::assertNull(Composer::getValue($this->composerJsonPath, 'not_existing_node'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $nodeName Name of existing node
|
||||
* @param string $nodeValue Value of existing node
|
||||
*
|
||||
* @dataProvider getExistingNode
|
||||
*/
|
||||
public function testGetValueExistingNode(string $nodeName, string $nodeValue): void
|
||||
{
|
||||
self::assertEquals($nodeValue, Composer::getValue($this->composerJsonPath, $nodeName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides names and values of existing nodes
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function getExistingNode(): Generator
|
||||
{
|
||||
yield[
|
||||
'name',
|
||||
'test/test',
|
||||
];
|
||||
|
||||
yield[
|
||||
'version',
|
||||
'1.0.2',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
namespace Meritoo\Test\Common\Utilities;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Utilities\CssSelector;
|
||||
|
||||
@@ -18,129 +19,152 @@ use Meritoo\Common\Utilities\CssSelector;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Utilities\CssSelector
|
||||
* @covers \Meritoo\Common\Utilities\CssSelector
|
||||
*/
|
||||
class CssSelectorTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Provides name of form and selector of the form
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideFormNameAndSelector()
|
||||
{
|
||||
yield [
|
||||
'test',
|
||||
'form[name="test"]',
|
||||
];
|
||||
|
||||
yield [
|
||||
'test-123-test-456',
|
||||
'form[name="test-123-test-456"]',
|
||||
];
|
||||
|
||||
yield [
|
||||
'test_something_098_different',
|
||||
'form[name="test_something_098_different"]',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides name of form, ID of field and expected selector of label
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideFormNameFieldIdAndLabelSelector()
|
||||
{
|
||||
yield [
|
||||
'test',
|
||||
'test',
|
||||
'form[name="test"] label[for="test"]',
|
||||
];
|
||||
|
||||
yield [
|
||||
'test-123-test-456',
|
||||
'great-000-field',
|
||||
'form[name="test-123-test-456"] label[for="great-000-field"]',
|
||||
];
|
||||
|
||||
yield [
|
||||
'test_something_098_different',
|
||||
'this-is-the-123789-field',
|
||||
'form[name="test_something_098_different"] label[for="this-is-the-123789-field"]',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides name of form, ID of field and expected selector
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideFormNameFieldIdAndSelector()
|
||||
{
|
||||
yield [
|
||||
'test',
|
||||
'test',
|
||||
'form[name="test"] input#test',
|
||||
];
|
||||
|
||||
yield [
|
||||
'test-123-test-456',
|
||||
'great-000-field',
|
||||
'form[name="test-123-test-456"] input#great-000-field',
|
||||
];
|
||||
|
||||
yield [
|
||||
'test_something_098_different',
|
||||
'this-is-the-123789-field',
|
||||
'form[name="test_something_098_different"] input#this-is-the-123789-field',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides name of form, name of field and expected selector
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideFormNameFieldNameAndSelector()
|
||||
{
|
||||
yield [
|
||||
'test',
|
||||
'test',
|
||||
'form[name="test"] input[name="test"]',
|
||||
];
|
||||
|
||||
yield [
|
||||
'test-123-test-456',
|
||||
'great-000-field',
|
||||
'form[name="test-123-test-456"] input[name="great-000-field"]',
|
||||
];
|
||||
|
||||
yield [
|
||||
'test_something_098_different',
|
||||
'this-is-the-123789-field',
|
||||
'form[name="test_something_098_different"] input[name="this-is-the-123789-field"]',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides name of form, index/position of the field-set and expected selector
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideFormNameFieldSetIndexAndSelector()
|
||||
{
|
||||
yield [
|
||||
'test',
|
||||
0,
|
||||
'form[name="test"] fieldset:nth-of-type(0)',
|
||||
];
|
||||
|
||||
yield [
|
||||
'test-123-test-456',
|
||||
1,
|
||||
'form[name="test-123-test-456"] fieldset:nth-of-type(1)',
|
||||
];
|
||||
|
||||
yield [
|
||||
'test_something_098_different',
|
||||
1245,
|
||||
'form[name="test_something_098_different"] fieldset:nth-of-type(1245)',
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
static::assertHasNoConstructor(CssSelector::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $emptyValue Name of form (value of the "name" attribute)
|
||||
* @dataProvider provideEmptyScalarValue
|
||||
*/
|
||||
public function testGetFormByNameSelectorUsingEmptyName($emptyValue)
|
||||
{
|
||||
static::assertSame('', CssSelector::getFormByNameSelector($emptyValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $formName Name of form (value of the "name" attribute)
|
||||
* @param string $expected Expected selector
|
||||
* @param string $formName Name of form (value of the "name" attribute)
|
||||
* @param int $fieldSetIndex Index/Position of the field-set
|
||||
* @param string $expected Expected selector
|
||||
*
|
||||
* @dataProvider provideFormNameAndSelector
|
||||
* @dataProvider provideFormNameFieldSetIndexAndSelector
|
||||
*/
|
||||
public function testGetFormByNameSelector($formName, $expected)
|
||||
public function testGetFieldSetByIndexSelector($formName, $fieldSetIndex, $expected)
|
||||
{
|
||||
static::assertSame($expected, CssSelector::getFormByNameSelector($formName));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $emptyValue Name of form (value of the "name" attribute)
|
||||
* @dataProvider provideEmptyScalarValue
|
||||
*/
|
||||
public function testGetInputByNameSelectorUsingEmptyFormName($emptyValue)
|
||||
{
|
||||
$fieldName = 'test-test';
|
||||
static::assertSame('', CssSelector::getInputByNameSelector($emptyValue, $fieldName));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $emptyValue Name of field (value of the "name" attribute)
|
||||
* @dataProvider provideEmptyScalarValue
|
||||
*/
|
||||
public function testGetInputByNameSelectorUsingEmptyFieldName($emptyValue)
|
||||
{
|
||||
$formName = 'test-test';
|
||||
static::assertSame('', CssSelector::getInputByNameSelector($formName, $emptyValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $formName Name of form (value of the "name" attribute)
|
||||
* @param string $fieldName Name of field (value of the "name" attribute)
|
||||
* @param string $expected Expected selector
|
||||
*
|
||||
* @dataProvider provideFormNameFieldNameAndSelector
|
||||
*/
|
||||
public function testGetInputByNameSelector($formName, $fieldName, $expected)
|
||||
{
|
||||
static::assertSame($expected, CssSelector::getInputByNameSelector($formName, $fieldName));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $emptyValue Name of form (value of the "name" attribute)
|
||||
* @dataProvider provideEmptyScalarValue
|
||||
*/
|
||||
public function testGetInputByIdSelectorUsingEmptyFormName($emptyValue)
|
||||
{
|
||||
$fieldId = 'test-test';
|
||||
static::assertSame('', CssSelector::getInputByIdSelector($emptyValue, $fieldId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $emptyValue ID of field (value of the "id" attribute)
|
||||
* @dataProvider provideEmptyScalarValue
|
||||
*/
|
||||
public function testGetInputByIdSelectorUsingEmptyFieldName($emptyValue)
|
||||
{
|
||||
$formName = 'test-test';
|
||||
static::assertSame('', CssSelector::getInputByIdSelector($formName, $emptyValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $formName Name of form (value of the "name" attribute)
|
||||
* @param string $fieldId ID of field (value of the "id" attribute)
|
||||
* @param string $expected Expected selector
|
||||
*
|
||||
* @dataProvider provideFormNameFieldIdAndSelector
|
||||
*/
|
||||
public function testGetInputByIdSelector($formName, $fieldId, $expected)
|
||||
{
|
||||
static::assertSame($expected, CssSelector::getInputByIdSelector($formName, $fieldId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $emptyValue Name of form (value of the "name" attribute)
|
||||
* @dataProvider provideEmptyScalarValue
|
||||
*/
|
||||
public function testGetLabelSelectorUsingEmptyFormName($emptyValue)
|
||||
{
|
||||
$fieldId = 'test-test';
|
||||
static::assertSame('', CssSelector::getLabelSelector($emptyValue, $fieldId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $emptyValue ID of field (value of the "id" attribute)
|
||||
* @dataProvider provideEmptyScalarValue
|
||||
*/
|
||||
public function testGetLabelSelectorUsingEmptyFieldId($emptyValue)
|
||||
{
|
||||
$formName = 'test-test';
|
||||
static::assertSame('', CssSelector::getLabelSelector($formName, $emptyValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $formName Name of form (value of the "name" attribute)
|
||||
* @param string $fieldId ID of field (value of the "id" attribute)
|
||||
* @param string $expected Expected selector
|
||||
*
|
||||
* @dataProvider provideFormNameFieldIdAndLabelSelector
|
||||
*/
|
||||
public function testGetLabelSelector($formName, $fieldId, $expected)
|
||||
{
|
||||
static::assertSame($expected, CssSelector::getLabelSelector($formName, $fieldId));
|
||||
static::assertSame($expected, CssSelector::getFieldSetByIndexSelector($formName, $fieldSetIndex));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,141 +183,118 @@ class CssSelectorTest extends BaseTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $formName Name of form (value of the "name" attribute)
|
||||
* @param int $fieldSetIndex Index/Position of the field-set
|
||||
* @param string $expected Expected selector
|
||||
* @param string $formName Name of form (value of the "name" attribute)
|
||||
* @param string $expected Expected selector
|
||||
*
|
||||
* @dataProvider provideFormNameFieldSetIndexAndSelector
|
||||
* @dataProvider provideFormNameAndSelector
|
||||
*/
|
||||
public function testGetFieldSetByIndexSelector($formName, $fieldSetIndex, $expected)
|
||||
public function testGetFormByNameSelector($formName, $expected)
|
||||
{
|
||||
static::assertSame($expected, CssSelector::getFieldSetByIndexSelector($formName, $fieldSetIndex));
|
||||
static::assertSame($expected, CssSelector::getFormByNameSelector($formName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides name of form and selector of the form
|
||||
*
|
||||
* @return \Generator
|
||||
* @param string $emptyValue Name of form (value of the "name" attribute)
|
||||
* @dataProvider provideEmptyScalarValue
|
||||
*/
|
||||
public function provideFormNameAndSelector()
|
||||
public function testGetFormByNameSelectorUsingEmptyName($emptyValue)
|
||||
{
|
||||
yield[
|
||||
'test',
|
||||
'form[name="test"]',
|
||||
];
|
||||
|
||||
yield[
|
||||
'test-123-test-456',
|
||||
'form[name="test-123-test-456"]',
|
||||
];
|
||||
|
||||
yield[
|
||||
'test_something_098_different',
|
||||
'form[name="test_something_098_different"]',
|
||||
];
|
||||
static::assertSame('', CssSelector::getFormByNameSelector($emptyValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides name of form, name of field and expected selector
|
||||
* @param string $formName Name of form (value of the "name" attribute)
|
||||
* @param string $fieldId ID of field (value of the "id" attribute)
|
||||
* @param string $expected Expected selector
|
||||
*
|
||||
* @return \Generator
|
||||
* @dataProvider provideFormNameFieldIdAndSelector
|
||||
*/
|
||||
public function provideFormNameFieldNameAndSelector()
|
||||
public function testGetInputByIdSelector($formName, $fieldId, $expected)
|
||||
{
|
||||
yield[
|
||||
'test',
|
||||
'test',
|
||||
'form[name="test"] input[name="test"]',
|
||||
];
|
||||
|
||||
yield[
|
||||
'test-123-test-456',
|
||||
'great-000-field',
|
||||
'form[name="test-123-test-456"] input[name="great-000-field"]',
|
||||
];
|
||||
|
||||
yield[
|
||||
'test_something_098_different',
|
||||
'this-is-the-123789-field',
|
||||
'form[name="test_something_098_different"] input[name="this-is-the-123789-field"]',
|
||||
];
|
||||
static::assertSame($expected, CssSelector::getInputByIdSelector($formName, $fieldId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides name of form, ID of field and expected selector of label
|
||||
*
|
||||
* @return \Generator
|
||||
* @param string $emptyValue ID of field (value of the "id" attribute)
|
||||
* @dataProvider provideEmptyScalarValue
|
||||
*/
|
||||
public function provideFormNameFieldIdAndLabelSelector()
|
||||
public function testGetInputByIdSelectorUsingEmptyFieldName($emptyValue)
|
||||
{
|
||||
yield[
|
||||
'test',
|
||||
'test',
|
||||
'form[name="test"] label[for="test"]',
|
||||
];
|
||||
|
||||
yield[
|
||||
'test-123-test-456',
|
||||
'great-000-field',
|
||||
'form[name="test-123-test-456"] label[for="great-000-field"]',
|
||||
];
|
||||
|
||||
yield[
|
||||
'test_something_098_different',
|
||||
'this-is-the-123789-field',
|
||||
'form[name="test_something_098_different"] label[for="this-is-the-123789-field"]',
|
||||
];
|
||||
$formName = 'test-test';
|
||||
static::assertSame('', CssSelector::getInputByIdSelector($formName, $emptyValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides name of form, index/position of the field-set and expected selector
|
||||
*
|
||||
* @return \Generator
|
||||
* @param string $emptyValue Name of form (value of the "name" attribute)
|
||||
* @dataProvider provideEmptyScalarValue
|
||||
*/
|
||||
public function provideFormNameFieldSetIndexAndSelector()
|
||||
public function testGetInputByIdSelectorUsingEmptyFormName($emptyValue)
|
||||
{
|
||||
yield[
|
||||
'test',
|
||||
0,
|
||||
'form[name="test"] fieldset:nth-of-type(0)',
|
||||
];
|
||||
|
||||
yield[
|
||||
'test-123-test-456',
|
||||
1,
|
||||
'form[name="test-123-test-456"] fieldset:nth-of-type(1)',
|
||||
];
|
||||
|
||||
yield[
|
||||
'test_something_098_different',
|
||||
1245,
|
||||
'form[name="test_something_098_different"] fieldset:nth-of-type(1245)',
|
||||
];
|
||||
$fieldId = 'test-test';
|
||||
static::assertSame('', CssSelector::getInputByIdSelector($emptyValue, $fieldId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides name of form, ID of field and expected selector
|
||||
* @param string $formName Name of form (value of the "name" attribute)
|
||||
* @param string $fieldName Name of field (value of the "name" attribute)
|
||||
* @param string $expected Expected selector
|
||||
*
|
||||
* @return \Generator
|
||||
* @dataProvider provideFormNameFieldNameAndSelector
|
||||
*/
|
||||
public function provideFormNameFieldIdAndSelector()
|
||||
public function testGetInputByNameSelector($formName, $fieldName, $expected)
|
||||
{
|
||||
yield[
|
||||
'test',
|
||||
'test',
|
||||
'form[name="test"] input#test',
|
||||
];
|
||||
static::assertSame($expected, CssSelector::getInputByNameSelector($formName, $fieldName));
|
||||
}
|
||||
|
||||
yield[
|
||||
'test-123-test-456',
|
||||
'great-000-field',
|
||||
'form[name="test-123-test-456"] input#great-000-field',
|
||||
];
|
||||
/**
|
||||
* @param string $emptyValue Name of field (value of the "name" attribute)
|
||||
* @dataProvider provideEmptyScalarValue
|
||||
*/
|
||||
public function testGetInputByNameSelectorUsingEmptyFieldName($emptyValue)
|
||||
{
|
||||
$formName = 'test-test';
|
||||
static::assertSame('', CssSelector::getInputByNameSelector($formName, $emptyValue));
|
||||
}
|
||||
|
||||
yield[
|
||||
'test_something_098_different',
|
||||
'this-is-the-123789-field',
|
||||
'form[name="test_something_098_different"] input#this-is-the-123789-field',
|
||||
];
|
||||
/**
|
||||
* @param string $emptyValue Name of form (value of the "name" attribute)
|
||||
* @dataProvider provideEmptyScalarValue
|
||||
*/
|
||||
public function testGetInputByNameSelectorUsingEmptyFormName($emptyValue)
|
||||
{
|
||||
$fieldName = 'test-test';
|
||||
static::assertSame('', CssSelector::getInputByNameSelector($emptyValue, $fieldName));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $formName Name of form (value of the "name" attribute)
|
||||
* @param string $fieldId ID of field (value of the "id" attribute)
|
||||
* @param string $expected Expected selector
|
||||
*
|
||||
* @dataProvider provideFormNameFieldIdAndLabelSelector
|
||||
*/
|
||||
public function testGetLabelSelector($formName, $fieldId, $expected)
|
||||
{
|
||||
static::assertSame($expected, CssSelector::getLabelSelector($formName, $fieldId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $emptyValue ID of field (value of the "id" attribute)
|
||||
* @dataProvider provideEmptyScalarValue
|
||||
*/
|
||||
public function testGetLabelSelectorUsingEmptyFieldId($emptyValue)
|
||||
{
|
||||
$formName = 'test-test';
|
||||
static::assertSame('', CssSelector::getLabelSelector($formName, $emptyValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $emptyValue Name of form (value of the "name" attribute)
|
||||
* @dataProvider provideEmptyScalarValue
|
||||
*/
|
||||
public function testGetLabelSelectorUsingEmptyFormName($emptyValue)
|
||||
{
|
||||
$fieldId = 'test-test';
|
||||
static::assertSame('', CssSelector::getLabelSelector($emptyValue, $fieldId));
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -18,7 +18,7 @@ use Meritoo\Common\Utilities\GeneratorUtility;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Utilities\GeneratorUtility
|
||||
* @covers \Meritoo\Common\Utilities\GeneratorUtility
|
||||
*/
|
||||
class GeneratorUtilityTest extends BaseTestCase
|
||||
{
|
||||
|
||||
@@ -20,10 +20,138 @@ use ReflectionException;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Utilities\Locale
|
||||
* @covers \Meritoo\Common\Utilities\Locale
|
||||
*/
|
||||
class LocaleTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Provides category
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideCategoryLanguageCodeAndExpectedLocale()
|
||||
{
|
||||
yield [
|
||||
LC_ALL,
|
||||
'fr',
|
||||
'',
|
||||
'fr_FR.UTF-8',
|
||||
];
|
||||
|
||||
yield [
|
||||
LC_COLLATE,
|
||||
'fr',
|
||||
'FR',
|
||||
'fr_FR.UTF-8',
|
||||
];
|
||||
|
||||
yield [
|
||||
LC_CTYPE,
|
||||
'en',
|
||||
'US',
|
||||
'en_US.UTF-8',
|
||||
];
|
||||
|
||||
yield [
|
||||
LC_NUMERIC,
|
||||
'en',
|
||||
'GB',
|
||||
'en_GB.UTF-8',
|
||||
];
|
||||
|
||||
yield [
|
||||
LC_MONETARY,
|
||||
'es',
|
||||
'',
|
||||
'es_ES.UTF-8',
|
||||
];
|
||||
|
||||
yield [
|
||||
LC_MONETARY,
|
||||
'es',
|
||||
'ES',
|
||||
'es_ES.UTF-8',
|
||||
];
|
||||
|
||||
yield [
|
||||
LC_TIME,
|
||||
'it',
|
||||
'',
|
||||
'it_IT.UTF-8',
|
||||
];
|
||||
|
||||
yield [
|
||||
LC_TIME,
|
||||
'it',
|
||||
'IT',
|
||||
'it_IT.UTF-8',
|
||||
];
|
||||
|
||||
yield [
|
||||
LC_TIME,
|
||||
'it',
|
||||
'it',
|
||||
'it_IT.UTF-8',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides language, encoding and country code
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideLanguageEncodingAndCountryCode()
|
||||
{
|
||||
yield [
|
||||
'fr',
|
||||
'',
|
||||
'',
|
||||
'fr_FR',
|
||||
];
|
||||
|
||||
yield [
|
||||
'fr',
|
||||
'',
|
||||
'UTF-8',
|
||||
'fr_FR.UTF-8',
|
||||
];
|
||||
|
||||
yield [
|
||||
'fr',
|
||||
'FR',
|
||||
'',
|
||||
'fr_FR',
|
||||
];
|
||||
|
||||
yield [
|
||||
'fr',
|
||||
'FR',
|
||||
'UTF-8',
|
||||
'fr_FR.UTF-8',
|
||||
];
|
||||
|
||||
yield [
|
||||
'en',
|
||||
'US',
|
||||
'',
|
||||
'en_US',
|
||||
];
|
||||
|
||||
yield [
|
||||
'en',
|
||||
'US',
|
||||
'UTF-8',
|
||||
'en_US.UTF-8',
|
||||
];
|
||||
|
||||
yield [
|
||||
'en',
|
||||
'US',
|
||||
'ISO-8859-1',
|
||||
'en_US.ISO-8859-1',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
@@ -32,56 +160,6 @@ class LocaleTest extends BaseTestCase
|
||||
static::assertHasNoConstructor(Locale::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $languageCode Empty value, e.g. ""
|
||||
* @dataProvider provideEmptyValue
|
||||
*/
|
||||
public function testGetLongFormEmptyLanguageCode($languageCode)
|
||||
{
|
||||
self::assertEquals('', Locale::getLongForm($languageCode));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $languageCode Language code, in ISO 639-1 format. Short form of the locale, e.g. "fr".
|
||||
* @param string $countryCode Country code, in ISO 3166-1 alpha-2 format, e.g. "FR"
|
||||
* @param string $encoding Encoding of the final locale
|
||||
* @param string $expected Expected long form of the locale
|
||||
*
|
||||
* @dataProvider provideLanguageEncodingAndCountryCode
|
||||
*/
|
||||
public function testGetLongForm($languageCode, $countryCode, $encoding, $expected)
|
||||
{
|
||||
self::assertEquals($expected, Locale::getLongForm($languageCode, $countryCode, $encoding));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $emptyValue Empty value, e.g. ""
|
||||
* @dataProvider provideEmptyValue
|
||||
*/
|
||||
public function testSetLocaleEmptyCategoryAndLanguageCode($emptyValue)
|
||||
{
|
||||
self::assertFalse(Locale::setLocale($emptyValue, $emptyValue));
|
||||
}
|
||||
|
||||
public function testSetLocaleIncorrectCategory()
|
||||
{
|
||||
self::assertFalse(Locale::setLocale(-1, 'en'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $category Named constant specifying the category of the functions affected by the locale
|
||||
* setting. It's the same constant as required by setlocale() function.
|
||||
* @param string $languageCode Language code, in ISO 639-1 format. Short form of the locale, e.g. "fr".
|
||||
* @param string $countryCode Country code, in ISO 3166-1 alpha-2 format, e.g. "FR"
|
||||
* @param string $expectedLocale Expected locale
|
||||
*
|
||||
* @dataProvider provideCategoryLanguageCodeAndExpectedLocale
|
||||
*/
|
||||
public function testSetLocale($category, $languageCode, $countryCode, $expectedLocale)
|
||||
{
|
||||
self::assertEquals($expectedLocale, Locale::setLocale($category, $languageCode, $countryCode));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $category Named constant specifying the category of the functions affected by the locale
|
||||
* setting. It's the same constant as required by setlocale() function.
|
||||
@@ -98,130 +176,52 @@ class LocaleTest extends BaseTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides language, encoding and country code
|
||||
* @param string $languageCode Language code, in ISO 639-1 format. Short form of the locale, e.g. "fr".
|
||||
* @param string $countryCode Country code, in ISO 3166-1 alpha-2 format, e.g. "FR"
|
||||
* @param string $encoding Encoding of the final locale
|
||||
* @param string $expected Expected long form of the locale
|
||||
*
|
||||
* @return Generator
|
||||
* @dataProvider provideLanguageEncodingAndCountryCode
|
||||
*/
|
||||
public function provideLanguageEncodingAndCountryCode()
|
||||
public function testGetLongForm($languageCode, $countryCode, $encoding, $expected)
|
||||
{
|
||||
yield[
|
||||
'fr',
|
||||
'',
|
||||
'',
|
||||
'fr_FR',
|
||||
];
|
||||
|
||||
yield[
|
||||
'fr',
|
||||
'',
|
||||
'UTF-8',
|
||||
'fr_FR.UTF-8',
|
||||
];
|
||||
|
||||
yield[
|
||||
'fr',
|
||||
'FR',
|
||||
'',
|
||||
'fr_FR',
|
||||
];
|
||||
|
||||
yield[
|
||||
'fr',
|
||||
'FR',
|
||||
'UTF-8',
|
||||
'fr_FR.UTF-8',
|
||||
];
|
||||
|
||||
yield[
|
||||
'en',
|
||||
'US',
|
||||
'',
|
||||
'en_US',
|
||||
];
|
||||
|
||||
yield[
|
||||
'en',
|
||||
'US',
|
||||
'UTF-8',
|
||||
'en_US.UTF-8',
|
||||
];
|
||||
|
||||
yield[
|
||||
'en',
|
||||
'US',
|
||||
'ISO-8859-1',
|
||||
'en_US.ISO-8859-1',
|
||||
];
|
||||
self::assertEquals($expected, Locale::getLongForm($languageCode, $countryCode, $encoding));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides category
|
||||
*
|
||||
* @return Generator
|
||||
* @param mixed $languageCode Empty value, e.g. ""
|
||||
* @dataProvider provideEmptyValue
|
||||
*/
|
||||
public function provideCategoryLanguageCodeAndExpectedLocale()
|
||||
public function testGetLongFormEmptyLanguageCode($languageCode)
|
||||
{
|
||||
yield[
|
||||
LC_ALL,
|
||||
'fr',
|
||||
'',
|
||||
'fr_FR.UTF-8',
|
||||
];
|
||||
self::assertEquals('', Locale::getLongForm($languageCode));
|
||||
}
|
||||
|
||||
yield[
|
||||
LC_COLLATE,
|
||||
'fr',
|
||||
'FR',
|
||||
'fr_FR.UTF-8',
|
||||
];
|
||||
/**
|
||||
* @param int $category Named constant specifying the category of the functions affected by the locale
|
||||
* setting. It's the same constant as required by setlocale() function.
|
||||
* @param string $languageCode Language code, in ISO 639-1 format. Short form of the locale, e.g. "fr".
|
||||
* @param string $countryCode Country code, in ISO 3166-1 alpha-2 format, e.g. "FR"
|
||||
* @param string $expectedLocale Expected locale
|
||||
*
|
||||
* @dataProvider provideCategoryLanguageCodeAndExpectedLocale
|
||||
*/
|
||||
public function testSetLocale($category, $languageCode, $countryCode, $expectedLocale)
|
||||
{
|
||||
self::assertEquals($expectedLocale, Locale::setLocale($category, $languageCode, $countryCode));
|
||||
}
|
||||
|
||||
yield[
|
||||
LC_CTYPE,
|
||||
'en',
|
||||
'US',
|
||||
'en_US.UTF-8',
|
||||
];
|
||||
/**
|
||||
* @param mixed $emptyValue Empty value, e.g. ""
|
||||
* @dataProvider provideEmptyValue
|
||||
*/
|
||||
public function testSetLocaleEmptyCategoryAndLanguageCode($emptyValue)
|
||||
{
|
||||
self::assertFalse(Locale::setLocale($emptyValue, $emptyValue));
|
||||
}
|
||||
|
||||
yield[
|
||||
LC_NUMERIC,
|
||||
'en',
|
||||
'GB',
|
||||
'en_GB.UTF-8',
|
||||
];
|
||||
|
||||
yield[
|
||||
LC_MONETARY,
|
||||
'es',
|
||||
'',
|
||||
'es_ES.UTF-8',
|
||||
];
|
||||
|
||||
yield[
|
||||
LC_MONETARY,
|
||||
'es',
|
||||
'ES',
|
||||
'es_ES.UTF-8',
|
||||
];
|
||||
|
||||
yield[
|
||||
LC_TIME,
|
||||
'it',
|
||||
'',
|
||||
'it_IT.UTF-8',
|
||||
];
|
||||
|
||||
yield[
|
||||
LC_TIME,
|
||||
'it',
|
||||
'IT',
|
||||
'it_IT.UTF-8',
|
||||
];
|
||||
|
||||
yield[
|
||||
LC_TIME,
|
||||
'it',
|
||||
'it',
|
||||
'it_IT.UTF-8',
|
||||
];
|
||||
public function testSetLocaleIncorrectCategory()
|
||||
{
|
||||
self::assertFalse(Locale::setLocale(-1, 'en'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,15 +19,309 @@ use Meritoo\Common\Utilities\MimeTypes;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Utilities\MimeTypes
|
||||
* @covers \Meritoo\Common\Utilities\MimeTypes
|
||||
*/
|
||||
class MimeTypesTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Provides real file path to get information if the file is an image
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideExistingFilePathToCheckIsImagePath()
|
||||
{
|
||||
yield [
|
||||
$this->getFilePathForTesting('minion.jpg'),
|
||||
true,
|
||||
];
|
||||
|
||||
yield [
|
||||
$this->getFilePathForTesting('lorem-ipsum.txt'),
|
||||
false,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides real file path to get mime type
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideFilePathToGetMimeTypeOfRealFile()
|
||||
{
|
||||
yield [
|
||||
$this->getFilePathForTesting('minion.jpg'),
|
||||
'image/jpeg',
|
||||
];
|
||||
|
||||
yield [
|
||||
$this->getFilePathForTesting('lorem-ipsum.txt'),
|
||||
'text/plain',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides mime type of image
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideImageMimeType()
|
||||
{
|
||||
yield ['image/bmp'];
|
||||
yield ['image/jpeg'];
|
||||
yield ['image/png'];
|
||||
yield ['image/tiff'];
|
||||
yield ['image/vnd.microsoft.icon'];
|
||||
yield ['image/x-rgb'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides existing mime type used to get multiple, more than one extension
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideMimeTypeToGetMultipleExtension()
|
||||
{
|
||||
yield [
|
||||
'application/postscript',
|
||||
[
|
||||
'ai',
|
||||
'eps',
|
||||
'ps',
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
'audio/midi',
|
||||
[
|
||||
'mid',
|
||||
'midi',
|
||||
'kar',
|
||||
'rmi',
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
'image/jpeg',
|
||||
[
|
||||
'jpeg',
|
||||
'jpe',
|
||||
'jpg',
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
'text/html',
|
||||
[
|
||||
'html',
|
||||
'htm',
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
'text/plain',
|
||||
[
|
||||
'txt',
|
||||
'text',
|
||||
'conf',
|
||||
'def',
|
||||
'list',
|
||||
'log',
|
||||
'in',
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
'video/mp4',
|
||||
[
|
||||
'mp4',
|
||||
'mp4v',
|
||||
'mpg4',
|
||||
'm4v',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides existing mime type used to get single, one extension
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideMimeTypeToGetSingleExtension()
|
||||
{
|
||||
yield [
|
||||
'application/x-7z-compressed',
|
||||
'7z',
|
||||
];
|
||||
|
||||
yield [
|
||||
'application/json',
|
||||
'json',
|
||||
];
|
||||
|
||||
yield [
|
||||
'application/zip',
|
||||
'zip',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides mime types used to get extensions
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideMimesTypesToGetExtensions()
|
||||
{
|
||||
yield [
|
||||
[
|
||||
'application/x-7z-compressed',
|
||||
'application/json',
|
||||
],
|
||||
[
|
||||
'application/x-7z-compressed' => '7z',
|
||||
'application/json' => 'json',
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
[
|
||||
'application/mathematica',
|
||||
'application/xml',
|
||||
'audio/mp4',
|
||||
'video/mp4',
|
||||
],
|
||||
[
|
||||
'application/mathematica' => [
|
||||
'ma',
|
||||
'nb',
|
||||
'mb',
|
||||
],
|
||||
'application/xml' => [
|
||||
'xml',
|
||||
'xsl',
|
||||
],
|
||||
'audio/mp4' => 'mp4a',
|
||||
'video/mp4' => [
|
||||
'mp4',
|
||||
'mp4v',
|
||||
'mpg4',
|
||||
'm4v',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides mime types used to get extensions as upper case
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideMimesTypesToGetExtensionsUpperCase()
|
||||
{
|
||||
yield [
|
||||
[
|
||||
'application/x-7z-compressed',
|
||||
'application/json',
|
||||
],
|
||||
[
|
||||
'application/x-7z-compressed' => '7Z',
|
||||
'application/json' => 'JSON',
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
[
|
||||
'application/xml',
|
||||
'audio/mp4',
|
||||
'text/html',
|
||||
'video/mp4',
|
||||
],
|
||||
[
|
||||
'application/xml' => [
|
||||
'XML',
|
||||
'XSL',
|
||||
],
|
||||
'audio/mp4' => 'MP4A',
|
||||
'text/html' => [
|
||||
'HTML',
|
||||
'HTM',
|
||||
],
|
||||
'video/mp4' => [
|
||||
'MP4',
|
||||
'MP4V',
|
||||
'MPG4',
|
||||
'M4V',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides mime type of non-image
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideNonImageMimeType()
|
||||
{
|
||||
yield ['application/rtf'];
|
||||
yield ['audio/mp4'];
|
||||
yield ['text/plain'];
|
||||
yield ['text/html'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides not existing mime type
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideNotExistingMimeType()
|
||||
{
|
||||
yield ['lorem/ipsum'];
|
||||
yield ['dolor'];
|
||||
yield ['x/y/z'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides not existing mime types
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideNotExistingMimeTypes()
|
||||
{
|
||||
yield [
|
||||
[],
|
||||
];
|
||||
|
||||
yield [
|
||||
[
|
||||
'',
|
||||
null,
|
||||
false,
|
||||
0,
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
[
|
||||
'lorem/ipsum',
|
||||
'dolor/sit',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
static::assertHasNoConstructor(MimeTypes::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $mimeType The mime type, e.g. "video/mpeg"
|
||||
* @dataProvider provideBooleanValue
|
||||
*/
|
||||
public function testGetExtensionBooleanMimeType($mimeType)
|
||||
{
|
||||
self::assertEquals('', MimeTypes::getExtension($mimeType));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $mimeType Empty value, e.g. ""
|
||||
* @dataProvider provideEmptyValue
|
||||
@@ -38,12 +332,14 @@ class MimeTypesTest extends BaseTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $mimeType The mime type, e.g. "video/mpeg"
|
||||
* @dataProvider provideBooleanValue
|
||||
* @param string $mimeType The mime type, e.g. "video/mpeg"
|
||||
* @param array $extensions Expected extensions
|
||||
*
|
||||
* @dataProvider provideMimeTypeToGetMultipleExtension
|
||||
*/
|
||||
public function testGetExtensionBooleanMimeType($mimeType)
|
||||
public function testGetExtensionMultiple($mimeType, $extensions)
|
||||
{
|
||||
self::assertEquals('', MimeTypes::getExtension($mimeType));
|
||||
self::assertEquals($extensions, MimeTypes::getExtension($mimeType));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,14 +363,14 @@ class MimeTypesTest extends BaseTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $mimeType The mime type, e.g. "video/mpeg"
|
||||
* @param array $extensions Expected extensions
|
||||
* @param array $mimesTypes The mimes types, e.g. ['video/mpeg', 'image/jpeg']
|
||||
* @param array $extensions Expected extensions
|
||||
*
|
||||
* @dataProvider provideMimeTypeToGetMultipleExtension
|
||||
* @dataProvider provideMimesTypesToGetExtensions
|
||||
*/
|
||||
public function testGetExtensionMultiple($mimeType, $extensions)
|
||||
public function testGetExtensions($mimesTypes, $extensions)
|
||||
{
|
||||
self::assertEquals($extensions, MimeTypes::getExtension($mimeType));
|
||||
self::assertEquals($extensions, MimeTypes::getExtensions($mimesTypes));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,17 +382,6 @@ class MimeTypesTest extends BaseTestCase
|
||||
self::assertEquals([], MimeTypes::getExtensions($mimesTypes));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $mimesTypes The mimes types, e.g. ['video/mpeg', 'image/jpeg']
|
||||
* @param array $extensions Expected extensions
|
||||
*
|
||||
* @dataProvider provideMimesTypesToGetExtensions
|
||||
*/
|
||||
public function testGetExtensions($mimesTypes, $extensions)
|
||||
{
|
||||
self::assertEquals($extensions, MimeTypes::getExtensions($mimesTypes));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $mimesTypes The mimes types, e.g. ['video/mpeg', 'image/jpeg']
|
||||
* @param array $extensions Expected extensions
|
||||
@@ -138,12 +423,12 @@ class MimeTypesTest extends BaseTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $mimeType Not existing mime type, e.g. "lorem/ipsum"
|
||||
* @dataProvider provideNotExistingMimeType
|
||||
* @param string $mimeType Mime type of image, e.g. "image/jpeg"
|
||||
* @dataProvider provideImageMimeType
|
||||
*/
|
||||
public function testIsImageNotExistingMimeType($mimeType)
|
||||
public function testIsImageImageMimeType($mimeType)
|
||||
{
|
||||
self::assertFalse(MimeTypes::isImage($mimeType));
|
||||
self::assertTrue(MimeTypes::isImage($mimeType));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,6 +440,15 @@ class MimeTypesTest extends BaseTestCase
|
||||
self::assertFalse(MimeTypes::isImage($mimeType));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $mimeType Not existing mime type, e.g. "lorem/ipsum"
|
||||
* @dataProvider provideNotExistingMimeType
|
||||
*/
|
||||
public function testIsImageNotExistingMimeType($mimeType)
|
||||
{
|
||||
self::assertFalse(MimeTypes::isImage($mimeType));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $path Empty value, e.g. ""
|
||||
* @dataProvider provideEmptyValue
|
||||
@@ -164,15 +458,6 @@ class MimeTypesTest extends BaseTestCase
|
||||
self::assertFalse(MimeTypes::isImagePath($path));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $path Path of not existing file, e.g. "lorem/ipsum.jpg"
|
||||
* @dataProvider provideNotExistingFilePath
|
||||
*/
|
||||
public function testIsImagePathNotExistingPath($path)
|
||||
{
|
||||
self::assertFalse(MimeTypes::isImagePath($path));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path Path of the file to check
|
||||
* @param bool $isImage Expected information if the file is an image
|
||||
@@ -185,296 +470,11 @@ class MimeTypesTest extends BaseTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $mimeType Mime type of image, e.g. "image/jpeg"
|
||||
* @dataProvider provideImageMimeType
|
||||
* @param mixed $path Path of not existing file, e.g. "lorem/ipsum.jpg"
|
||||
* @dataProvider provideNotExistingFilePath
|
||||
*/
|
||||
public function testIsImageImageMimeType($mimeType)
|
||||
public function testIsImagePathNotExistingPath($path)
|
||||
{
|
||||
self::assertTrue(MimeTypes::isImage($mimeType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides not existing mime type
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideNotExistingMimeType()
|
||||
{
|
||||
yield['lorem/ipsum'];
|
||||
yield['dolor'];
|
||||
yield['x/y/z'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides mime type of non-image
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideNonImageMimeType()
|
||||
{
|
||||
yield['application/rtf'];
|
||||
yield['audio/mp4'];
|
||||
yield['text/plain'];
|
||||
yield['text/html'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides mime type of image
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideImageMimeType()
|
||||
{
|
||||
yield['image/bmp'];
|
||||
yield['image/jpeg'];
|
||||
yield['image/png'];
|
||||
yield['image/tiff'];
|
||||
yield['image/vnd.microsoft.icon'];
|
||||
yield['image/x-rgb'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides existing mime type used to get single, one extension
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideMimeTypeToGetSingleExtension()
|
||||
{
|
||||
yield[
|
||||
'application/x-7z-compressed',
|
||||
'7z',
|
||||
];
|
||||
|
||||
yield[
|
||||
'application/json',
|
||||
'json',
|
||||
];
|
||||
|
||||
yield[
|
||||
'application/zip',
|
||||
'zip',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides existing mime type used to get multiple, more than one extension
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideMimeTypeToGetMultipleExtension()
|
||||
{
|
||||
yield[
|
||||
'application/postscript',
|
||||
[
|
||||
'ai',
|
||||
'eps',
|
||||
'ps',
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
'audio/midi',
|
||||
[
|
||||
'mid',
|
||||
'midi',
|
||||
'kar',
|
||||
'rmi',
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
'image/jpeg',
|
||||
[
|
||||
'jpeg',
|
||||
'jpe',
|
||||
'jpg',
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
'text/html',
|
||||
[
|
||||
'html',
|
||||
'htm',
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
'text/plain',
|
||||
[
|
||||
'txt',
|
||||
'text',
|
||||
'conf',
|
||||
'def',
|
||||
'list',
|
||||
'log',
|
||||
'in',
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
'video/mp4',
|
||||
[
|
||||
'mp4',
|
||||
'mp4v',
|
||||
'mpg4',
|
||||
'm4v',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides not existing mime types
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideNotExistingMimeTypes()
|
||||
{
|
||||
yield[
|
||||
[],
|
||||
];
|
||||
|
||||
yield[
|
||||
[
|
||||
'',
|
||||
null,
|
||||
false,
|
||||
0,
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
[
|
||||
'lorem/ipsum',
|
||||
'dolor/sit',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides mime types used to get extensions
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideMimesTypesToGetExtensions()
|
||||
{
|
||||
yield[
|
||||
[
|
||||
'application/x-7z-compressed',
|
||||
'application/json',
|
||||
],
|
||||
[
|
||||
'application/x-7z-compressed' => '7z',
|
||||
'application/json' => 'json',
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
[
|
||||
'application/mathematica',
|
||||
'application/xml',
|
||||
'audio/mp4',
|
||||
'video/mp4',
|
||||
],
|
||||
[
|
||||
'application/mathematica' => [
|
||||
'ma',
|
||||
'nb',
|
||||
'mb',
|
||||
],
|
||||
'application/xml' => [
|
||||
'xml',
|
||||
'xsl',
|
||||
],
|
||||
'audio/mp4' => 'mp4a',
|
||||
'video/mp4' => [
|
||||
'mp4',
|
||||
'mp4v',
|
||||
'mpg4',
|
||||
'm4v',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides mime types used to get extensions as upper case
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideMimesTypesToGetExtensionsUpperCase()
|
||||
{
|
||||
yield[
|
||||
[
|
||||
'application/x-7z-compressed',
|
||||
'application/json',
|
||||
],
|
||||
[
|
||||
'application/x-7z-compressed' => '7Z',
|
||||
'application/json' => 'JSON',
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
[
|
||||
'application/xml',
|
||||
'audio/mp4',
|
||||
'text/html',
|
||||
'video/mp4',
|
||||
],
|
||||
[
|
||||
'application/xml' => [
|
||||
'XML',
|
||||
'XSL',
|
||||
],
|
||||
'audio/mp4' => 'MP4A',
|
||||
'text/html' => [
|
||||
'HTML',
|
||||
'HTM',
|
||||
],
|
||||
'video/mp4' => [
|
||||
'MP4',
|
||||
'MP4V',
|
||||
'MPG4',
|
||||
'M4V',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides real file path to get mime type
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideFilePathToGetMimeTypeOfRealFile()
|
||||
{
|
||||
yield[
|
||||
$this->getFilePathForTesting('minion.jpg'),
|
||||
'image/jpeg',
|
||||
];
|
||||
|
||||
yield[
|
||||
$this->getFilePathForTesting('lorem-ipsum.txt'),
|
||||
'text/plain',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides real file path to get information if the file is an image
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideExistingFilePathToCheckIsImagePath()
|
||||
{
|
||||
yield[
|
||||
$this->getFilePathForTesting('minion.jpg'),
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
$this->getFilePathForTesting('lorem-ipsum.txt'),
|
||||
false,
|
||||
];
|
||||
self::assertFalse(MimeTypes::isImagePath($path));
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -17,6 +17,7 @@ use Doctrine\ORM\QueryBuilder;
|
||||
use Generator;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Utilities\QueryBuilderUtility;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Test case of the useful methods for query builder (the Doctrine's QueryBuilder class)
|
||||
@@ -25,24 +26,260 @@ use Meritoo\Common\Utilities\QueryBuilderUtility;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Utilities\QueryBuilderUtility
|
||||
* @covers \Meritoo\Common\Utilities\QueryBuilderUtility
|
||||
*/
|
||||
class QueryBuilderUtilityTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Provides query builder and criteria used in WHERE clause
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideQueryBuilderAndCriteria()
|
||||
{
|
||||
$entityManager = $this
|
||||
->getMockBuilder(EntityManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['getExpressionBuilder'])
|
||||
->getMock();
|
||||
|
||||
$entityManager
|
||||
->expects(static::any())
|
||||
->method('getExpressionBuilder')
|
||||
->willReturn(new Expr())
|
||||
;
|
||||
|
||||
yield [
|
||||
(new QueryBuilder($entityManager))->from('lorem_ipsum', 'lm'),
|
||||
[
|
||||
'lorem' => 11,
|
||||
'ipsum' => 22,
|
||||
'dolor' => null,
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
(new QueryBuilder($entityManager))->from('lorem_ipsum', 'lm'),
|
||||
[
|
||||
'lorem' => [
|
||||
11,
|
||||
'>=',
|
||||
],
|
||||
'ipsum' => [
|
||||
22,
|
||||
'<',
|
||||
],
|
||||
'dolor' => null,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides query builder and parameters to add to given query builder
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideQueryBuilderAndParameters()
|
||||
{
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
|
||||
yield [
|
||||
new QueryBuilder($entityManager),
|
||||
[],
|
||||
];
|
||||
|
||||
yield [
|
||||
new QueryBuilder($entityManager),
|
||||
new ArrayCollection(),
|
||||
];
|
||||
|
||||
yield [
|
||||
new QueryBuilder($entityManager),
|
||||
[
|
||||
'lorem' => 11,
|
||||
'ipsum' => 22,
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
new QueryBuilder($entityManager),
|
||||
new ArrayCollection([
|
||||
'lorem' => 11,
|
||||
'ipsum' => 22,
|
||||
]),
|
||||
];
|
||||
|
||||
yield [
|
||||
new QueryBuilder($entityManager),
|
||||
[
|
||||
new Parameter('lorem', 11),
|
||||
new Parameter('ipsum', 22),
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
new QueryBuilder($entityManager),
|
||||
new ArrayCollection([
|
||||
new Parameter('lorem', 11),
|
||||
new Parameter('ipsum', 22),
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides query builder, name of property and expected alias of given property
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideQueryBuilderAndPropertyAlias()
|
||||
{
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
|
||||
yield [
|
||||
new QueryBuilder($entityManager),
|
||||
'',
|
||||
null,
|
||||
];
|
||||
|
||||
yield [
|
||||
new QueryBuilder($entityManager),
|
||||
'lorem',
|
||||
null,
|
||||
];
|
||||
|
||||
yield [
|
||||
(new QueryBuilder($entityManager))->from('lorem_ipsum', 'lm'),
|
||||
'lm',
|
||||
null,
|
||||
];
|
||||
|
||||
yield [
|
||||
(new QueryBuilder($entityManager))
|
||||
->from('lorem', 'l')
|
||||
->leftJoin('l.ipsum', 'i'),
|
||||
'ipsum',
|
||||
'i',
|
||||
];
|
||||
|
||||
yield [
|
||||
(new QueryBuilder($entityManager))
|
||||
->from('lorem', 'l')
|
||||
->leftJoin('l.ipsum', 'i')
|
||||
->innerJoin('i.dolor', 'd'),
|
||||
'ipsum1',
|
||||
null,
|
||||
];
|
||||
|
||||
yield [
|
||||
(new QueryBuilder($entityManager))
|
||||
->from('lorem', 'l')
|
||||
->leftJoin('l.ipsum', 'i')
|
||||
->innerJoin('i.dolor', 'd'),
|
||||
'ipsum',
|
||||
'i',
|
||||
];
|
||||
|
||||
yield [
|
||||
(new QueryBuilder($entityManager))
|
||||
->from('lorem', 'l')
|
||||
->leftJoin('l.ipsum', 'i')
|
||||
->innerJoin('i.dolor', 'd'),
|
||||
'dolor',
|
||||
'd',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides query builder to retrieve root alias and expected root alias
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideQueryBuilderAndRootAlias()
|
||||
{
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
|
||||
yield [
|
||||
new QueryBuilder($entityManager),
|
||||
null,
|
||||
];
|
||||
|
||||
yield [
|
||||
(new QueryBuilder($entityManager))->from('lorem_ipsum', 'lm'),
|
||||
'lm',
|
||||
];
|
||||
|
||||
yield [
|
||||
(new QueryBuilder($entityManager))
|
||||
->from('lorem', 'l')
|
||||
->leftJoin('l.ipsum', 'i'),
|
||||
'l',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param QueryBuilder $queryBuilder The query builder
|
||||
* @param array|ArrayCollection $parameters Parameters to add. Collection of Doctrine\ORM\Query\Parameter
|
||||
* instances or an array with key-value pairs.
|
||||
*
|
||||
* @dataProvider provideQueryBuilderAndParameters
|
||||
*/
|
||||
public function testAddParameters(QueryBuilder $queryBuilder, $parameters)
|
||||
{
|
||||
$newQueryBuilder = QueryBuilderUtility::addParameters($queryBuilder, $parameters);
|
||||
|
||||
static::assertSame($queryBuilder, $newQueryBuilder);
|
||||
static::assertCount(count($parameters), $newQueryBuilder->getParameters());
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
static::assertHasNoConstructor(QueryBuilderUtility::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param QueryBuilder $queryBuilder The query builder to retrieve root alias
|
||||
* @param null|string $rootAlias Expected root alias of given query builder
|
||||
*
|
||||
* @dataProvider provideQueryBuilderAndRootAlias
|
||||
*/
|
||||
public function testGetRootAlias(QueryBuilder $queryBuilder, $rootAlias)
|
||||
public function testDeleteEntities()
|
||||
{
|
||||
static::assertSame($rootAlias, QueryBuilderUtility::getRootAlias($queryBuilder));
|
||||
$methods = [
|
||||
'remove',
|
||||
'flush',
|
||||
];
|
||||
|
||||
$entityManager = $this
|
||||
->getMockBuilder(EntityManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods($methods)
|
||||
->getMock();
|
||||
|
||||
$entities1 = [];
|
||||
|
||||
$entities2 = [
|
||||
new stdClass(),
|
||||
];
|
||||
|
||||
static::assertFalse(QueryBuilderUtility::deleteEntities($entityManager, $entities1));
|
||||
static::assertTrue(QueryBuilderUtility::deleteEntities($entityManager, $entities2));
|
||||
}
|
||||
|
||||
public function testDeleteEntitiesWithoutFlush()
|
||||
{
|
||||
$methods = [
|
||||
'remove',
|
||||
'flush',
|
||||
];
|
||||
|
||||
$entityManager = $this
|
||||
->getMockBuilder(EntityManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods($methods)
|
||||
->getMock();
|
||||
|
||||
$entities1 = [];
|
||||
|
||||
$entities2 = [
|
||||
new stdClass(),
|
||||
];
|
||||
|
||||
static::assertFalse(QueryBuilderUtility::deleteEntities($entityManager, $entities1, false));
|
||||
static::assertTrue(QueryBuilderUtility::deleteEntities($entityManager, $entities2, false));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,31 +294,15 @@ class QueryBuilderUtilityTest extends BaseTestCase
|
||||
static::assertSame($propertyAlias, QueryBuilderUtility::getJoinedPropertyAlias($queryBuilder, $propertyName));
|
||||
}
|
||||
|
||||
public function testSetCriteriaWithoutCriteria()
|
||||
/**
|
||||
* @param QueryBuilder $queryBuilder The query builder to retrieve root alias
|
||||
* @param null|string $rootAlias Expected root alias of given query builder
|
||||
*
|
||||
* @dataProvider provideQueryBuilderAndRootAlias
|
||||
*/
|
||||
public function testGetRootAlias(QueryBuilder $queryBuilder, $rootAlias)
|
||||
{
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$queryBuilder = new QueryBuilder($entityManager);
|
||||
$newQueryBuilder = QueryBuilderUtility::setCriteria($queryBuilder);
|
||||
|
||||
static::assertSame($queryBuilder, $newQueryBuilder);
|
||||
static::assertCount(0, $newQueryBuilder->getParameters());
|
||||
static::assertNull($newQueryBuilder->getDQLPart('where'));
|
||||
}
|
||||
|
||||
public function testSetCriteriaWithoutAlias()
|
||||
{
|
||||
$criteria = [
|
||||
'lorem' => 11,
|
||||
'ipsum' => 22,
|
||||
];
|
||||
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$queryBuilder = new QueryBuilder($entityManager);
|
||||
$newQueryBuilder = QueryBuilderUtility::setCriteria($queryBuilder, $criteria);
|
||||
|
||||
static::assertSame($queryBuilder, $newQueryBuilder);
|
||||
static::assertCount(count($criteria), $newQueryBuilder->getParameters());
|
||||
static::assertNotNull($newQueryBuilder->getDQLPart('where'));
|
||||
static::assertSame($rootAlias, QueryBuilderUtility::getRootAlias($queryBuilder));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,253 +329,30 @@ class QueryBuilderUtilityTest extends BaseTestCase
|
||||
static::assertNotNull($newQueryBuilder->getDQLPart('where'));
|
||||
}
|
||||
|
||||
public function testDeleteEntitiesWithoutFlush()
|
||||
public function testSetCriteriaWithoutAlias()
|
||||
{
|
||||
$methods = [
|
||||
'remove',
|
||||
'flush',
|
||||
$criteria = [
|
||||
'lorem' => 11,
|
||||
'ipsum' => 22,
|
||||
];
|
||||
|
||||
$entityManager = $this
|
||||
->getMockBuilder(EntityManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods($methods)
|
||||
->getMock()
|
||||
;
|
||||
|
||||
$entities1 = [];
|
||||
|
||||
$entities2 = [
|
||||
new \stdClass(),
|
||||
];
|
||||
|
||||
static::assertFalse(QueryBuilderUtility::deleteEntities($entityManager, $entities1, false));
|
||||
static::assertTrue(QueryBuilderUtility::deleteEntities($entityManager, $entities2, false));
|
||||
}
|
||||
|
||||
public function testDeleteEntities()
|
||||
{
|
||||
$methods = [
|
||||
'remove',
|
||||
'flush',
|
||||
];
|
||||
|
||||
$entityManager = $this
|
||||
->getMockBuilder(EntityManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods($methods)
|
||||
->getMock()
|
||||
;
|
||||
|
||||
$entities1 = [];
|
||||
|
||||
$entities2 = [
|
||||
new \stdClass(),
|
||||
];
|
||||
|
||||
static::assertFalse(QueryBuilderUtility::deleteEntities($entityManager, $entities1));
|
||||
static::assertTrue(QueryBuilderUtility::deleteEntities($entityManager, $entities2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param QueryBuilder $queryBuilder The query builder
|
||||
* @param array|ArrayCollection $parameters Parameters to add. Collection of Doctrine\ORM\Query\Parameter
|
||||
* instances or an array with key-value pairs.
|
||||
*
|
||||
* @dataProvider provideQueryBuilderAndParameters
|
||||
*/
|
||||
public function testAddParameters(QueryBuilder $queryBuilder, $parameters)
|
||||
{
|
||||
$newQueryBuilder = QueryBuilderUtility::addParameters($queryBuilder, $parameters);
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$queryBuilder = new QueryBuilder($entityManager);
|
||||
$newQueryBuilder = QueryBuilderUtility::setCriteria($queryBuilder, $criteria);
|
||||
|
||||
static::assertSame($queryBuilder, $newQueryBuilder);
|
||||
static::assertCount(count($parameters), $newQueryBuilder->getParameters());
|
||||
static::assertCount(count($criteria), $newQueryBuilder->getParameters());
|
||||
static::assertNotNull($newQueryBuilder->getDQLPart('where'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides query builder to retrieve root alias and expected root alias
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideQueryBuilderAndRootAlias()
|
||||
public function testSetCriteriaWithoutCriteria()
|
||||
{
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$queryBuilder = new QueryBuilder($entityManager);
|
||||
$newQueryBuilder = QueryBuilderUtility::setCriteria($queryBuilder);
|
||||
|
||||
yield[
|
||||
new QueryBuilder($entityManager),
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
(new QueryBuilder($entityManager))->from('lorem_ipsum', 'lm'),
|
||||
'lm',
|
||||
];
|
||||
|
||||
yield[
|
||||
(new QueryBuilder($entityManager))
|
||||
->from('lorem', 'l')
|
||||
->leftJoin('l.ipsum', 'i'),
|
||||
'l',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides query builder, name of property and expected alias of given property
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideQueryBuilderAndPropertyAlias()
|
||||
{
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
|
||||
yield[
|
||||
new QueryBuilder($entityManager),
|
||||
'',
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
new QueryBuilder($entityManager),
|
||||
'lorem',
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
(new QueryBuilder($entityManager))->from('lorem_ipsum', 'lm'),
|
||||
'lm',
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
(new QueryBuilder($entityManager))
|
||||
->from('lorem', 'l')
|
||||
->leftJoin('l.ipsum', 'i'),
|
||||
'ipsum',
|
||||
'i',
|
||||
];
|
||||
|
||||
yield[
|
||||
(new QueryBuilder($entityManager))
|
||||
->from('lorem', 'l')
|
||||
->leftJoin('l.ipsum', 'i')
|
||||
->innerJoin('i.dolor', 'd'),
|
||||
'ipsum1',
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
(new QueryBuilder($entityManager))
|
||||
->from('lorem', 'l')
|
||||
->leftJoin('l.ipsum', 'i')
|
||||
->innerJoin('i.dolor', 'd'),
|
||||
'ipsum',
|
||||
'i',
|
||||
];
|
||||
|
||||
yield[
|
||||
(new QueryBuilder($entityManager))
|
||||
->from('lorem', 'l')
|
||||
->leftJoin('l.ipsum', 'i')
|
||||
->innerJoin('i.dolor', 'd'),
|
||||
'dolor',
|
||||
'd',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides query builder and criteria used in WHERE clause
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideQueryBuilderAndCriteria()
|
||||
{
|
||||
$entityManager = $this
|
||||
->getMockBuilder(EntityManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['getExpressionBuilder'])
|
||||
->getMock()
|
||||
;
|
||||
|
||||
$entityManager
|
||||
->expects(static::any())
|
||||
->method('getExpressionBuilder')
|
||||
->willReturn(new Expr())
|
||||
;
|
||||
|
||||
yield[
|
||||
(new QueryBuilder($entityManager))->from('lorem_ipsum', 'lm'),
|
||||
[
|
||||
'lorem' => 11,
|
||||
'ipsum' => 22,
|
||||
'dolor' => null,
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
(new QueryBuilder($entityManager))->from('lorem_ipsum', 'lm'),
|
||||
[
|
||||
'lorem' => [
|
||||
11,
|
||||
'>=',
|
||||
],
|
||||
'ipsum' => [
|
||||
22,
|
||||
'<',
|
||||
],
|
||||
'dolor' => null,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides query builder and parameters to add to given query builder
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideQueryBuilderAndParameters()
|
||||
{
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
|
||||
yield[
|
||||
new QueryBuilder($entityManager),
|
||||
[],
|
||||
];
|
||||
|
||||
yield[
|
||||
new QueryBuilder($entityManager),
|
||||
new ArrayCollection(),
|
||||
];
|
||||
|
||||
yield[
|
||||
new QueryBuilder($entityManager),
|
||||
[
|
||||
'lorem' => 11,
|
||||
'ipsum' => 22,
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
new QueryBuilder($entityManager),
|
||||
new ArrayCollection([
|
||||
'lorem' => 11,
|
||||
'ipsum' => 22,
|
||||
]),
|
||||
];
|
||||
|
||||
yield[
|
||||
new QueryBuilder($entityManager),
|
||||
[
|
||||
new Parameter('lorem', 11),
|
||||
new Parameter('ipsum', 22),
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
new QueryBuilder($entityManager),
|
||||
new ArrayCollection([
|
||||
new Parameter('lorem', 11),
|
||||
new Parameter('ipsum', 22),
|
||||
]),
|
||||
];
|
||||
static::assertSame($queryBuilder, $newQueryBuilder);
|
||||
static::assertCount(0, $newQueryBuilder->getParameters());
|
||||
static::assertNull($newQueryBuilder->getDQLPart('where'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,13 +24,13 @@ class A
|
||||
|
||||
private $count = 1;
|
||||
|
||||
protected function lorem()
|
||||
{
|
||||
return 'ipsum';
|
||||
}
|
||||
|
||||
protected function getCount()
|
||||
{
|
||||
return $this->count;
|
||||
}
|
||||
|
||||
protected function lorem()
|
||||
{
|
||||
return 'ipsum';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,13 @@ namespace Meritoo\Test\Common\Utilities\Reflection;
|
||||
*/
|
||||
class C extends B
|
||||
{
|
||||
public function getPositive()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getNegative()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getPositive()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -23,9 +23,174 @@ use Meritoo\Common\Utilities\Uri;
|
||||
*/
|
||||
class UriTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
/**
|
||||
* Provides data used to build secured url
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideDataForSecuredUrl()
|
||||
{
|
||||
static::assertHasNoConstructor(Uri::class);
|
||||
yield [
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
];
|
||||
|
||||
yield [
|
||||
'/',
|
||||
'',
|
||||
'',
|
||||
'http://lorem.com/',
|
||||
];
|
||||
|
||||
yield [
|
||||
'contact',
|
||||
'',
|
||||
'',
|
||||
'http://lorem.com/contact',
|
||||
];
|
||||
|
||||
yield [
|
||||
'contact',
|
||||
'john',
|
||||
'',
|
||||
'http://lorem.com/contact',
|
||||
];
|
||||
|
||||
yield [
|
||||
'contact',
|
||||
'',
|
||||
'pass123',
|
||||
'http://lorem.com/contact',
|
||||
];
|
||||
|
||||
yield [
|
||||
'contact',
|
||||
'john',
|
||||
'pass123',
|
||||
'http://john:pass123@lorem.com/contact',
|
||||
];
|
||||
}
|
||||
|
||||
public function provideRootUrlAndUrlParts(): ?Generator
|
||||
{
|
||||
yield [
|
||||
'',
|
||||
'',
|
||||
];
|
||||
|
||||
yield [
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
];
|
||||
|
||||
yield [
|
||||
'http://my.example',
|
||||
'http://my.example',
|
||||
'',
|
||||
];
|
||||
|
||||
yield [
|
||||
'http://my.example',
|
||||
'http://my.example',
|
||||
'',
|
||||
'',
|
||||
];
|
||||
|
||||
yield [
|
||||
'http://my.example//test/12/test/',
|
||||
'http://my.example',
|
||||
'',
|
||||
'test',
|
||||
'12/test',
|
||||
'',
|
||||
];
|
||||
|
||||
yield [
|
||||
'http://my.example//test/12/test',
|
||||
'http://my.example',
|
||||
'',
|
||||
'test/',
|
||||
'12/test/',
|
||||
];
|
||||
|
||||
yield [
|
||||
'http://my.example/test/12/test/',
|
||||
'http://my.example',
|
||||
'/test/',
|
||||
'/12/test',
|
||||
'',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides url to replenish protocol
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideUrlToReplenishProtocol()
|
||||
{
|
||||
yield [
|
||||
'http://test',
|
||||
'test',
|
||||
'',
|
||||
];
|
||||
|
||||
yield [
|
||||
'ftp://lorem.ipsum',
|
||||
'lorem.ipsum',
|
||||
'ftp',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides url used to verify if it's external, from another server / domain
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideUrlToVerifyIfIsExternal()
|
||||
{
|
||||
yield [
|
||||
'',
|
||||
false,
|
||||
];
|
||||
|
||||
yield [
|
||||
'/',
|
||||
false,
|
||||
];
|
||||
|
||||
yield [
|
||||
'http://something.different/first-page',
|
||||
true,
|
||||
];
|
||||
|
||||
yield [
|
||||
'something.different/first-page',
|
||||
true,
|
||||
];
|
||||
|
||||
yield [
|
||||
'http://lorem.com',
|
||||
false,
|
||||
];
|
||||
|
||||
yield [
|
||||
'http://lorem.com/contact',
|
||||
false,
|
||||
];
|
||||
|
||||
yield [
|
||||
'lorem.com',
|
||||
false,
|
||||
];
|
||||
|
||||
yield [
|
||||
'lorem.com/contact',
|
||||
false,
|
||||
];
|
||||
}
|
||||
|
||||
public function testAddProtocolToUrl()
|
||||
@@ -45,61 +210,20 @@ class UriTest extends BaseTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $url Empty value, e.g. ""
|
||||
* @dataProvider provideEmptyValue
|
||||
*/
|
||||
public function testReplenishProtocolEmptyUrl($url)
|
||||
{
|
||||
self::assertEquals('', Uri::replenishProtocol($url));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $expected Expected result
|
||||
* @param string $url The url to check and replenish
|
||||
* @param string $protocol (optional) The protocol which is replenished. If is empty, protocol of current request
|
||||
* is used.
|
||||
* @param string $expected
|
||||
* @param string $rootUrl
|
||||
* @param string ...$urlParts
|
||||
*
|
||||
* @dataProvider provideUrlToReplenishProtocol
|
||||
* @dataProvider provideRootUrlAndUrlParts
|
||||
*/
|
||||
public function testReplenishProtocol($expected, $url, $protocol = '')
|
||||
public function testBuildUrl(string $expected, string $rootUrl, string ...$urlParts): void
|
||||
{
|
||||
/*
|
||||
* Required to get protocol when it's not provided and to void test failure:
|
||||
*
|
||||
* Failed asserting that two strings are identical.
|
||||
* Expected :'://test'
|
||||
* Actual :'http://test'
|
||||
*/
|
||||
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
|
||||
|
||||
self::assertSame($expected, Uri::replenishProtocol($url, $protocol));
|
||||
static::assertSame($expected, Uri::buildUrl($rootUrl, ...$urlParts));
|
||||
}
|
||||
|
||||
public function testGetServerNameOrIpWithoutProtocol()
|
||||
public function testConstructor()
|
||||
{
|
||||
$_SERVER['HTTP_HOST'] = '';
|
||||
self::assertEquals('', Uri::getServerNameOrIp());
|
||||
|
||||
$host = 'lorem.com';
|
||||
$_SERVER['HTTP_HOST'] = $host;
|
||||
|
||||
self::assertEquals($host, Uri::getServerNameOrIp());
|
||||
}
|
||||
|
||||
public function testGetServerNameOrIpWithProtocol()
|
||||
{
|
||||
$_SERVER['HTTP_HOST'] = '';
|
||||
$_SERVER['SERVER_PROTOCOL'] = '';
|
||||
|
||||
self::assertEquals('', Uri::getServerNameOrIp(true));
|
||||
|
||||
$host = 'lorem.com';
|
||||
$protocol = 'HTTP/1.1';
|
||||
|
||||
$_SERVER['HTTP_HOST'] = $host;
|
||||
$_SERVER['SERVER_PROTOCOL'] = $protocol;
|
||||
|
||||
self::assertEquals(sprintf('http://%s', $host), Uri::getServerNameOrIp(true));
|
||||
static::assertHasNoConstructor(Uri::class);
|
||||
}
|
||||
|
||||
public function testGetFullUriWithHost()
|
||||
@@ -157,6 +281,49 @@ class UriTest extends BaseTestCase
|
||||
self::assertEquals($refererUrl, Uri::getRefererUri());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url A path / url to some resource, e.g. page, image, css file
|
||||
* @param string $user User name used to log in
|
||||
* @param string $password User password used to log in
|
||||
* @param string $expectedUrl Expected, secured url
|
||||
*
|
||||
* @dataProvider provideDataForSecuredUrl
|
||||
*/
|
||||
public function testGetSecuredUrl($url, $user, $password, $expectedUrl)
|
||||
{
|
||||
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
|
||||
$_SERVER['HTTP_HOST'] = 'lorem.com';
|
||||
|
||||
self::assertEquals($expectedUrl, Uri::getSecuredUrl($url, $user, $password));
|
||||
}
|
||||
|
||||
public function testGetServerNameOrIpWithProtocol()
|
||||
{
|
||||
$_SERVER['HTTP_HOST'] = '';
|
||||
$_SERVER['SERVER_PROTOCOL'] = '';
|
||||
|
||||
self::assertEquals('', Uri::getServerNameOrIp(true));
|
||||
|
||||
$host = 'lorem.com';
|
||||
$protocol = 'HTTP/1.1';
|
||||
|
||||
$_SERVER['HTTP_HOST'] = $host;
|
||||
$_SERVER['SERVER_PROTOCOL'] = $protocol;
|
||||
|
||||
self::assertEquals(sprintf('http://%s', $host), Uri::getServerNameOrIp(true));
|
||||
}
|
||||
|
||||
public function testGetServerNameOrIpWithoutProtocol()
|
||||
{
|
||||
$_SERVER['HTTP_HOST'] = '';
|
||||
self::assertEquals('', Uri::getServerNameOrIp());
|
||||
|
||||
$host = 'lorem.com';
|
||||
$_SERVER['HTTP_HOST'] = $host;
|
||||
|
||||
self::assertEquals($host, Uri::getServerNameOrIp());
|
||||
}
|
||||
|
||||
public function testGetUserAddressIp()
|
||||
{
|
||||
$_SERVER['REMOTE_ADDR'] = '';
|
||||
@@ -168,58 +335,49 @@ class UriTest extends BaseTestCase
|
||||
self::assertEquals($userAddressIp, Uri::getUserAddressIp());
|
||||
}
|
||||
|
||||
public function testGetUserOperatingSystemName()
|
||||
{
|
||||
$_SERVER['HTTP_USER_AGENT'] = '';
|
||||
self::assertEquals('', Uri::getUserOperatingSystemName());
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/600.2.5 (KHTML, like'
|
||||
.' Gecko) Version/8.0.2 Safari/600.2.5';
|
||||
|
||||
self::assertEquals('Mac OS', Uri::getUserOperatingSystemName());
|
||||
}
|
||||
|
||||
public function testGetUserWebBrowserInfo()
|
||||
{
|
||||
$_SERVER['HTTP_USER_AGENT'] = '';
|
||||
self::assertEquals('', Uri::getUserWebBrowserInfo());
|
||||
|
||||
$browserInfo = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/600.2.5 (KHTML, like Gecko)'
|
||||
. ' Version/8.0.2 Safari/600.2.5';
|
||||
.' Version/8.0.2 Safari/600.2.5';
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = $browserInfo;
|
||||
self::assertEquals($browserInfo, Uri::getUserWebBrowserInfo());
|
||||
}
|
||||
|
||||
public function testGetUserWebBrowserNameWithoutVersion()
|
||||
{
|
||||
$_SERVER['HTTP_USER_AGENT'] = '';
|
||||
self::assertEquals('', Uri::getUserWebBrowserName());
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/600.2.5 (KHTML, like'
|
||||
. ' Gecko) Version/8.0.2 Safari/600.2.5';
|
||||
|
||||
self::assertEquals('Apple Safari', Uri::getUserWebBrowserName());
|
||||
}
|
||||
|
||||
public function testGetUserWebBrowserNameWithVersion()
|
||||
{
|
||||
$_SERVER['HTTP_USER_AGENT'] = '';
|
||||
self::assertEquals('', Uri::getUserWebBrowserName(true));
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/600.2.5 (KHTML, like'
|
||||
. ' Gecko) Version/8.0.2 Safari/600.2.5';
|
||||
.' Gecko) Version/8.0.2 Safari/600.2.5';
|
||||
|
||||
self::assertEquals('Apple Safari 600.2.5', Uri::getUserWebBrowserName(true));
|
||||
}
|
||||
|
||||
public function testGetUserOperatingSystemName()
|
||||
public function testGetUserWebBrowserNameWithoutVersion()
|
||||
{
|
||||
$_SERVER['HTTP_USER_AGENT'] = '';
|
||||
self::assertEquals('', Uri::getUserOperatingSystemName());
|
||||
self::assertEquals('', Uri::getUserWebBrowserName());
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/600.2.5 (KHTML, like'
|
||||
. ' Gecko) Version/8.0.2 Safari/600.2.5';
|
||||
.' Gecko) Version/8.0.2 Safari/600.2.5';
|
||||
|
||||
self::assertEquals('Mac OS', Uri::getUserOperatingSystemName());
|
||||
}
|
||||
|
||||
public function testIsServerLocalhost()
|
||||
{
|
||||
$_SERVER['HTTP_HOST'] = '';
|
||||
self::assertFalse(Uri::isServerLocalhost());
|
||||
|
||||
$_SERVER['HTTP_HOST'] = '127.0.0.1';
|
||||
self::assertTrue(Uri::isServerLocalhost());
|
||||
self::assertEquals('Apple Safari', Uri::getUserWebBrowserName());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -239,201 +397,43 @@ class UriTest extends BaseTestCase
|
||||
self::assertEquals($expected, Uri::isExternalUrl($url));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url A path / url to some resource, e.g. page, image, css file
|
||||
* @param string $user User name used to log in
|
||||
* @param string $password User password used to log in
|
||||
* @param string $expectedUrl Expected, secured url
|
||||
*
|
||||
* @dataProvider provideDataForSecuredUrl
|
||||
*/
|
||||
public function testGetSecuredUrl($url, $user, $password, $expectedUrl)
|
||||
public function testIsServerLocalhost()
|
||||
{
|
||||
$_SERVER['HTTP_HOST'] = '';
|
||||
self::assertFalse(Uri::isServerLocalhost());
|
||||
|
||||
$_SERVER['HTTP_HOST'] = '127.0.0.1';
|
||||
self::assertTrue(Uri::isServerLocalhost());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $expected Expected result
|
||||
* @param string $url The url to check and replenish
|
||||
* @param string $protocol (optional) The protocol which is replenished. If is empty, protocol of current request
|
||||
* is used.
|
||||
*
|
||||
* @dataProvider provideUrlToReplenishProtocol
|
||||
*/
|
||||
public function testReplenishProtocol($expected, $url, $protocol = '')
|
||||
{
|
||||
/*
|
||||
* Required to get protocol when it's not provided and to void test failure:
|
||||
*
|
||||
* Failed asserting that two strings are identical.
|
||||
* Expected :'://test'
|
||||
* Actual :'http://test'
|
||||
*/
|
||||
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
|
||||
$_SERVER['HTTP_HOST'] = 'lorem.com';
|
||||
|
||||
self::assertEquals($expectedUrl, Uri::getSecuredUrl($url, $user, $password));
|
||||
self::assertSame($expected, Uri::replenishProtocol($url, $protocol));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $expected
|
||||
* @param string $rootUrl
|
||||
* @param string ...$urlParts
|
||||
*
|
||||
* @dataProvider provideRootUrlAndUrlParts
|
||||
* @param mixed $url Empty value, e.g. ""
|
||||
* @dataProvider provideEmptyValue
|
||||
*/
|
||||
public function testBuildUrl(string $expected, string $rootUrl, string ...$urlParts): void
|
||||
public function testReplenishProtocolEmptyUrl($url)
|
||||
{
|
||||
static::assertSame($expected, Uri::buildUrl($rootUrl, ...$urlParts));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides url to replenish protocol
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideUrlToReplenishProtocol()
|
||||
{
|
||||
yield[
|
||||
'http://test',
|
||||
'test',
|
||||
'',
|
||||
];
|
||||
|
||||
yield[
|
||||
'ftp://lorem.ipsum',
|
||||
'lorem.ipsum',
|
||||
'ftp',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides url used to verify if it's external, from another server / domain
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideUrlToVerifyIfIsExternal()
|
||||
{
|
||||
yield[
|
||||
'',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'/',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'http://something.different/first-page',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'something.different/first-page',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'http://lorem.com',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'http://lorem.com/contact',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'lorem.com',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'lorem.com/contact',
|
||||
false,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides data used to build secured url
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideDataForSecuredUrl()
|
||||
{
|
||||
yield[
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
];
|
||||
|
||||
yield[
|
||||
'/',
|
||||
'',
|
||||
'',
|
||||
'http://lorem.com/',
|
||||
];
|
||||
|
||||
yield[
|
||||
'contact',
|
||||
'',
|
||||
'',
|
||||
'http://lorem.com/contact',
|
||||
];
|
||||
|
||||
yield[
|
||||
'contact',
|
||||
'john',
|
||||
'',
|
||||
'http://lorem.com/contact',
|
||||
];
|
||||
|
||||
yield[
|
||||
'contact',
|
||||
'',
|
||||
'pass123',
|
||||
'http://lorem.com/contact',
|
||||
];
|
||||
|
||||
yield[
|
||||
'contact',
|
||||
'john',
|
||||
'pass123',
|
||||
'http://john:pass123@lorem.com/contact',
|
||||
];
|
||||
}
|
||||
|
||||
public function provideRootUrlAndUrlParts(): ?Generator
|
||||
{
|
||||
yield[
|
||||
'',
|
||||
'',
|
||||
];
|
||||
|
||||
yield[
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
];
|
||||
|
||||
yield[
|
||||
'http://my.example',
|
||||
'http://my.example',
|
||||
'',
|
||||
];
|
||||
|
||||
yield[
|
||||
'http://my.example',
|
||||
'http://my.example',
|
||||
'',
|
||||
'',
|
||||
];
|
||||
|
||||
yield[
|
||||
'http://my.example//test/12/test/',
|
||||
'http://my.example',
|
||||
'',
|
||||
'test',
|
||||
'12/test',
|
||||
'',
|
||||
];
|
||||
|
||||
yield[
|
||||
'http://my.example//test/12/test',
|
||||
'http://my.example',
|
||||
'',
|
||||
'test/',
|
||||
'12/test/',
|
||||
];
|
||||
|
||||
yield[
|
||||
'http://my.example/test/12/test/',
|
||||
'http://my.example',
|
||||
'/test/',
|
||||
'/12/test',
|
||||
'',
|
||||
];
|
||||
self::assertEquals('', Uri::replenishProtocol($url));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ use SimpleXMLElement;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Utilities\Xml
|
||||
* @covers \Meritoo\Common\Utilities\Xml
|
||||
*/
|
||||
class XmlTest extends BaseTestCase
|
||||
{
|
||||
@@ -38,14 +38,14 @@ class XmlTest extends BaseTestCase
|
||||
$element2 = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><employees />');
|
||||
|
||||
$merged = Xml::mergeNodes($element1, $element2);
|
||||
self::assertEquals('', (string)$merged);
|
||||
self::assertEquals('', (string) $merged);
|
||||
|
||||
// XMLs with data
|
||||
$element1 = new SimpleXMLElement($this->simpleXml);
|
||||
$element2 = new SimpleXMLElement($this->advancedXml);
|
||||
|
||||
$merged = Xml::mergeNodes($element1, $element2);
|
||||
self::assertEquals('John', (string)$merged->author[0]->first_name);
|
||||
self::assertEquals('John', (string) $merged->author[0]->first_name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,7 +19,7 @@ use Meritoo\Common\ValueObject\Address;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\ValueObject\Address
|
||||
* @covers \Meritoo\Common\ValueObject\Address
|
||||
*/
|
||||
class AddressTest extends BaseTestCase
|
||||
{
|
||||
@@ -48,13 +48,6 @@ class AddressTest extends BaseTestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetFlatNumber()
|
||||
{
|
||||
static::assertSame('200', $this->address->getFlatNumber());
|
||||
static::assertSame('', $this->addressWithoutFlat->getFlatNumber());
|
||||
static::assertSame('300', $this->addressWithoutStreet->getFlatNumber());
|
||||
}
|
||||
|
||||
public function testGetBuildingNumber()
|
||||
{
|
||||
static::assertSame('10', $this->address->getBuildingNumber());
|
||||
@@ -62,11 +55,18 @@ class AddressTest extends BaseTestCase
|
||||
static::assertSame('1', $this->addressWithoutStreet->getBuildingNumber());
|
||||
}
|
||||
|
||||
public function testGetStreet()
|
||||
public function testGetCity()
|
||||
{
|
||||
static::assertSame('4th Avenue', $this->address->getStreet());
|
||||
static::assertSame('Green Street', $this->addressWithoutFlat->getStreet());
|
||||
static::assertSame('', $this->addressWithoutStreet->getStreet());
|
||||
static::assertSame('New York', $this->address->getCity());
|
||||
static::assertSame('San Francisco', $this->addressWithoutFlat->getCity());
|
||||
static::assertSame('Saint Louis', $this->addressWithoutStreet->getCity());
|
||||
}
|
||||
|
||||
public function testGetFlatNumber()
|
||||
{
|
||||
static::assertSame('200', $this->address->getFlatNumber());
|
||||
static::assertSame('', $this->addressWithoutFlat->getFlatNumber());
|
||||
static::assertSame('300', $this->addressWithoutStreet->getFlatNumber());
|
||||
}
|
||||
|
||||
public function testGetFullStreet()
|
||||
@@ -76,11 +76,11 @@ class AddressTest extends BaseTestCase
|
||||
static::assertSame('', $this->addressWithoutStreet->getFullStreet());
|
||||
}
|
||||
|
||||
public function testGetCity()
|
||||
public function testGetStreet()
|
||||
{
|
||||
static::assertSame('New York', $this->address->getCity());
|
||||
static::assertSame('San Francisco', $this->addressWithoutFlat->getCity());
|
||||
static::assertSame('Saint Louis', $this->addressWithoutStreet->getCity());
|
||||
static::assertSame('4th Avenue', $this->address->getStreet());
|
||||
static::assertSame('Green Street', $this->addressWithoutFlat->getStreet());
|
||||
static::assertSame('', $this->addressWithoutStreet->getStreet());
|
||||
}
|
||||
|
||||
public function testGetZipCode()
|
||||
@@ -92,9 +92,9 @@ class AddressTest extends BaseTestCase
|
||||
|
||||
public function testToString()
|
||||
{
|
||||
static::assertSame('4th Avenue 10/200, 00123, New York', (string)$this->address);
|
||||
static::assertSame('Green Street 22, 00456, San Francisco', (string)$this->addressWithoutFlat);
|
||||
static::assertSame('00111, Saint Louis', (string)$this->addressWithoutStreet);
|
||||
static::assertSame('4th Avenue 10/200, 00123, New York', (string) $this->address);
|
||||
static::assertSame('Green Street 22, 00456, San Francisco', (string) $this->addressWithoutFlat);
|
||||
static::assertSame('00111, Saint Louis', (string) $this->addressWithoutStreet);
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
|
||||
@@ -19,7 +19,7 @@ use Meritoo\Common\ValueObject\BankAccount;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\ValueObject\BankAccount
|
||||
* @covers \Meritoo\Common\ValueObject\BankAccount
|
||||
*/
|
||||
class BankAccountTest extends BaseTestCase
|
||||
{
|
||||
@@ -57,8 +57,8 @@ class BankAccountTest extends BaseTestCase
|
||||
|
||||
public function testToString()
|
||||
{
|
||||
static::assertSame('', (string)$this->emptyBankAccount);
|
||||
static::assertSame('Bank of America, 1234567890', (string)$this->bankAccount);
|
||||
static::assertSame('', (string) $this->emptyBankAccount);
|
||||
static::assertSame('Bank of America, 1234567890', (string) $this->bankAccount);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,7 +21,7 @@ use Meritoo\Common\ValueObject\Company;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\ValueObject\Company
|
||||
* @covers \Meritoo\Common\ValueObject\Company
|
||||
*/
|
||||
class CompanyTest extends BaseTestCase
|
||||
{
|
||||
@@ -45,12 +45,6 @@ class CompanyTest extends BaseTestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetName()
|
||||
{
|
||||
static::assertSame('Test 1', $this->company->getName());
|
||||
static::assertSame('Test 2', $this->companyWithoutBankAccount->getName());
|
||||
}
|
||||
|
||||
public function testGetAddress()
|
||||
{
|
||||
static::assertEquals(
|
||||
@@ -74,10 +68,16 @@ class CompanyTest extends BaseTestCase
|
||||
static::assertNull($this->companyWithoutBankAccount->getBankAccount());
|
||||
}
|
||||
|
||||
public function testGetName()
|
||||
{
|
||||
static::assertSame('Test 1', $this->company->getName());
|
||||
static::assertSame('Test 2', $this->companyWithoutBankAccount->getName());
|
||||
}
|
||||
|
||||
public function testToString()
|
||||
{
|
||||
static::assertSame('Test 1, 4th Avenue 10/200, 00123, New York, Bank 1, 12345', (string)$this->company);
|
||||
static::assertSame('Test 2, Green Street 22, 00456, San Francisco', (string)$this->companyWithoutBankAccount);
|
||||
static::assertSame('Test 1, 4th Avenue 10/200, 00123, New York, Bank 1, 12345', (string) $this->company);
|
||||
static::assertSame('Test 2, Green Street 22, 00456, San Francisco', (string) $this->companyWithoutBankAccount);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
namespace Meritoo\Test\Common\ValueObject;
|
||||
|
||||
use DateTime;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\Common\ValueObject\Human;
|
||||
@@ -19,10 +20,37 @@ use Meritoo\Common\ValueObject\Human;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\ValueObject\Human
|
||||
* @covers \Meritoo\Common\ValueObject\Human
|
||||
*/
|
||||
class HumanTest extends BaseTestCase
|
||||
{
|
||||
public function provideHuman()
|
||||
{
|
||||
yield [
|
||||
'Without any data (an empty human)',
|
||||
new Human('', ''),
|
||||
'',
|
||||
];
|
||||
|
||||
yield [
|
||||
'With first and last name only',
|
||||
new Human('John', 'Scott'),
|
||||
'John Scott',
|
||||
];
|
||||
|
||||
yield [
|
||||
'With first name, last name and email',
|
||||
new Human('John', 'Scott', 'john@scott.com'),
|
||||
'John Scott <john@scott.com>',
|
||||
];
|
||||
|
||||
yield [
|
||||
'With whole/complete data',
|
||||
new Human('John', 'Scott', 'john@scott.com', new DateTime('2001-01-01')),
|
||||
'John Scott <john@scott.com>',
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -33,52 +61,13 @@ class HumanTest extends BaseTestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description Description of test
|
||||
* @param Human $human Human to verify
|
||||
* @param string $expected Expected string
|
||||
*
|
||||
* @dataProvider provideHuman
|
||||
*/
|
||||
public function testToString($description, Human $human, $expected)
|
||||
{
|
||||
static::assertSame($expected, (string)$human, $description);
|
||||
}
|
||||
|
||||
public function testGetFirstName()
|
||||
{
|
||||
$empty = new Human('', '');
|
||||
static::assertSame('', $empty->getFirstName());
|
||||
|
||||
$human = new Human('John', 'Scott');
|
||||
static::assertSame('John', $human->getFirstName());
|
||||
}
|
||||
|
||||
public function testGetLastName()
|
||||
{
|
||||
$empty = new Human('', '');
|
||||
static::assertSame('', $empty->getLastName());
|
||||
|
||||
$human = new Human('John', 'Scott');
|
||||
static::assertSame('Scott', $human->getLastName());
|
||||
}
|
||||
|
||||
public function testGetBirthDate()
|
||||
{
|
||||
$empty = new Human('', '');
|
||||
static::assertNull($empty->getBirthDate());
|
||||
|
||||
$human = new Human('John', 'Scott', '', new \DateTime('2001-01-01'));
|
||||
static::assertEquals(new \DateTime('2001-01-01'), $human->getBirthDate());
|
||||
}
|
||||
|
||||
public function testGetFullName()
|
||||
{
|
||||
$empty = new Human('', '');
|
||||
static::assertSame('', $empty->getFullName());
|
||||
|
||||
$human = new Human('John', 'Scott', '', new \DateTime('2001-01-01'));
|
||||
static::assertSame('John Scott', $human->getFullName());
|
||||
$human = new Human('John', 'Scott', '', new DateTime('2001-01-01'));
|
||||
static::assertEquals(new DateTime('2001-01-01'), $human->getBirthDate());
|
||||
}
|
||||
|
||||
public function testGetEmail()
|
||||
@@ -90,30 +79,42 @@ class HumanTest extends BaseTestCase
|
||||
static::assertSame('john@scott.com', $human->getEmail());
|
||||
}
|
||||
|
||||
public function provideHuman()
|
||||
public function testGetFirstName()
|
||||
{
|
||||
yield[
|
||||
'Without any data (an empty human)',
|
||||
new Human('', ''),
|
||||
'',
|
||||
];
|
||||
$empty = new Human('', '');
|
||||
static::assertSame('', $empty->getFirstName());
|
||||
|
||||
yield[
|
||||
'With first and last name only',
|
||||
new Human('John', 'Scott'),
|
||||
'John Scott',
|
||||
];
|
||||
$human = new Human('John', 'Scott');
|
||||
static::assertSame('John', $human->getFirstName());
|
||||
}
|
||||
|
||||
yield[
|
||||
'With first name, last name and email',
|
||||
new Human('John', 'Scott', 'john@scott.com'),
|
||||
'John Scott <john@scott.com>',
|
||||
];
|
||||
public function testGetFullName()
|
||||
{
|
||||
$empty = new Human('', '');
|
||||
static::assertSame('', $empty->getFullName());
|
||||
|
||||
yield[
|
||||
'With whole/complete data',
|
||||
new Human('John', 'Scott', 'john@scott.com', new \DateTime('2001-01-01')),
|
||||
'John Scott <john@scott.com>',
|
||||
];
|
||||
$human = new Human('John', 'Scott', '', new DateTime('2001-01-01'));
|
||||
static::assertSame('John Scott', $human->getFullName());
|
||||
}
|
||||
|
||||
public function testGetLastName()
|
||||
{
|
||||
$empty = new Human('', '');
|
||||
static::assertSame('', $empty->getLastName());
|
||||
|
||||
$human = new Human('John', 'Scott');
|
||||
static::assertSame('Scott', $human->getLastName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description Description of test
|
||||
* @param Human $human Human to verify
|
||||
* @param string $expected Expected string
|
||||
*
|
||||
* @dataProvider provideHuman
|
||||
*/
|
||||
public function testToString($description, Human $human, $expected)
|
||||
{
|
||||
static::assertSame($expected, (string) $human, $description);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -27,6 +27,183 @@ use Meritoo\Common\ValueObject\Template;
|
||||
*/
|
||||
class TemplateTest extends BaseTestCase
|
||||
{
|
||||
public function provideInvalidContent(): ?Generator
|
||||
{
|
||||
$template = 'Content of template \'%s\' is invalid. Did you use string with 1 placeholder at least?';
|
||||
|
||||
yield [
|
||||
'An empty string' => '',
|
||||
sprintf($template, ''),
|
||||
];
|
||||
|
||||
yield [
|
||||
'Without placeholders' => 'test',
|
||||
sprintf($template, 'test'),
|
||||
];
|
||||
|
||||
yield [
|
||||
'With starting tag only (invalid placeholder)' => 'This is %test',
|
||||
sprintf($template, 'This is %test'),
|
||||
];
|
||||
|
||||
yield [
|
||||
'With ending tag only (invalid placeholder)' => 'This is test%',
|
||||
sprintf($template, 'This is test%'),
|
||||
];
|
||||
}
|
||||
|
||||
public function provideTemplateToFill(): ?Generator
|
||||
{
|
||||
yield [
|
||||
'Template with 1 placeholder',
|
||||
new Template('%test%'),
|
||||
[
|
||||
'test' => 123,
|
||||
],
|
||||
'123',
|
||||
];
|
||||
|
||||
yield [
|
||||
'Template with 1 placeholder, but more values',
|
||||
new Template('%test%'),
|
||||
[
|
||||
'test' => 123,
|
||||
'anotherTest' => 456,
|
||||
],
|
||||
'123',
|
||||
];
|
||||
|
||||
yield [
|
||||
'Template with 2 placeholders',
|
||||
new Template('My name is %name% and I am %profession%'),
|
||||
[
|
||||
'name' => 'Jane',
|
||||
'profession' => 'photographer',
|
||||
],
|
||||
'My name is Jane and I am photographer',
|
||||
];
|
||||
|
||||
yield [
|
||||
'Template with 2 placeholders, but more values',
|
||||
new Template('My name is %name% and I am %profession%'),
|
||||
[
|
||||
'name' => 'Jane',
|
||||
'test-test' => 123,
|
||||
'profession' => 'photographer',
|
||||
'anotherTest' => 456,
|
||||
],
|
||||
'My name is Jane and I am photographer',
|
||||
];
|
||||
|
||||
yield [
|
||||
'Template with 2 placeholders that contains space',
|
||||
new Template('My name is %first name% %last name% and I live in %current location%'),
|
||||
[
|
||||
'first name' => 'Jane',
|
||||
'last name' => 'Brown',
|
||||
'current location' => 'NY, USA',
|
||||
],
|
||||
'My name is Jane Brown and I live in NY, USA',
|
||||
];
|
||||
|
||||
yield [
|
||||
'Template with 2 placeholders that contains space, but more values',
|
||||
new Template('My name is %first name% %last name% and I live in %current location%'),
|
||||
[
|
||||
'first name' => 'Jane',
|
||||
'profession' => 'photographer',
|
||||
'last name' => 'Brown',
|
||||
'test-test' => 123,
|
||||
'anotherTest' => 456,
|
||||
'current location' => 'NY, USA',
|
||||
],
|
||||
'My name is Jane Brown and I live in NY, USA',
|
||||
];
|
||||
}
|
||||
|
||||
public function provideTemplateToFillUsingIncorrectValues(): ?Generator
|
||||
{
|
||||
$template = 'Cannot fill template \'%s\', because of missing values for placeholder(s): %s. Did you provide all'
|
||||
.' required values?';
|
||||
|
||||
yield [
|
||||
new Template('%test%'),
|
||||
[
|
||||
'something' => 123,
|
||||
],
|
||||
sprintf(
|
||||
$template,
|
||||
'%test%',
|
||||
'test'
|
||||
),
|
||||
];
|
||||
|
||||
yield [
|
||||
new Template('%test%'),
|
||||
[],
|
||||
sprintf(
|
||||
$template,
|
||||
'%test%',
|
||||
'test'
|
||||
),
|
||||
];
|
||||
|
||||
yield [
|
||||
new Template('%test1% - %test2%'),
|
||||
[
|
||||
'test1' => 123,
|
||||
],
|
||||
sprintf(
|
||||
$template,
|
||||
'%test1% - %test2%',
|
||||
'test2'
|
||||
),
|
||||
];
|
||||
|
||||
yield [
|
||||
new Template('%test1% - %test2%'),
|
||||
[
|
||||
'test1' => 123,
|
||||
'test3' => 456,
|
||||
],
|
||||
sprintf(
|
||||
$template,
|
||||
'%test1% - %test2%',
|
||||
'test2'
|
||||
),
|
||||
];
|
||||
|
||||
yield [
|
||||
new Template('%test1% / %test2% / %test3%'),
|
||||
[
|
||||
'test1' => 123,
|
||||
],
|
||||
sprintf(
|
||||
$template,
|
||||
'%test1% / %test2% / %test3%',
|
||||
'test2, test3'
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
public function provideValidContent(): ?Generator
|
||||
{
|
||||
yield [
|
||||
'Template with 1 placeholder',
|
||||
'%test%',
|
||||
];
|
||||
|
||||
yield [
|
||||
'Template with 2 placeholders',
|
||||
'My name is %name% and I am %profession%',
|
||||
];
|
||||
|
||||
yield [
|
||||
'Template with 2 placeholders that contains space',
|
||||
'My name is %first name% %last name% and I live in %current location%',
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -37,6 +214,36 @@ class TemplateTest extends BaseTestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description Description of test
|
||||
* @param Template $template Template to fill
|
||||
* @param array $values Pairs of key-value where: key - name of placeholder, value - value of the
|
||||
* placeholder
|
||||
* @param string $expected Expected result
|
||||
*
|
||||
* @dataProvider provideTemplateToFill
|
||||
*/
|
||||
public function testFill(string $description, Template $template, array $values, string $expected): void
|
||||
{
|
||||
static::assertSame($expected, $template->fill($values), $description);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Template $template Template to fill
|
||||
* @param array $values Pairs of key-value where: key - name of placeholder, value - value of the
|
||||
* placeholder
|
||||
* @param string $exceptionMessage Expected message of exception
|
||||
*
|
||||
* @dataProvider provideTemplateToFillUsingIncorrectValues
|
||||
*/
|
||||
public function testFillUsingIncorrectValues(Template $template, array $values, string $exceptionMessage): void
|
||||
{
|
||||
$this->expectException(MissingPlaceholdersInValuesException::class);
|
||||
$this->expectExceptionMessage($exceptionMessage);
|
||||
|
||||
$template->fill($values);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $content Raw string with placeholders (content of the template)
|
||||
* @param string $exceptionMessage Expected message of exception
|
||||
@@ -62,211 +269,4 @@ class TemplateTest extends BaseTestCase
|
||||
$template = new Template($content);
|
||||
static::assertSame($content, Reflection::getPropertyValue($template, 'content', true), $description);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Template $template Template to fill
|
||||
* @param array $values Pairs of key-value where: key - name of placeholder, value - value of the
|
||||
* placeholder
|
||||
* @param string $exceptionMessage Expected message of exception
|
||||
*
|
||||
* @dataProvider provideTemplateToFillUsingIncorrectValues
|
||||
*/
|
||||
public function testFillUsingIncorrectValues(Template $template, array $values, string $exceptionMessage): void
|
||||
{
|
||||
$this->expectException(MissingPlaceholdersInValuesException::class);
|
||||
$this->expectExceptionMessage($exceptionMessage);
|
||||
|
||||
$template->fill($values);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description Description of test
|
||||
* @param Template $template Template to fill
|
||||
* @param array $values Pairs of key-value where: key - name of placeholder, value - value of the
|
||||
* placeholder
|
||||
* @param string $expected Expected result
|
||||
*
|
||||
* @dataProvider provideTemplateToFill
|
||||
*/
|
||||
public function testFill(string $description, Template $template, array $values, string $expected): void
|
||||
{
|
||||
static::assertSame($expected, $template->fill($values), $description);
|
||||
}
|
||||
|
||||
public function provideInvalidContent(): ?Generator
|
||||
{
|
||||
$template = 'Content of template \'%s\' is invalid. Did you use string with 1 placeholder at least?';
|
||||
|
||||
yield[
|
||||
'An empty string' => '',
|
||||
sprintf($template, ''),
|
||||
];
|
||||
|
||||
yield[
|
||||
'Without placeholders' => 'test',
|
||||
sprintf($template, 'test'),
|
||||
];
|
||||
|
||||
yield[
|
||||
'With starting tag only (invalid placeholder)' => 'This is %test',
|
||||
sprintf($template, 'This is %test'),
|
||||
];
|
||||
|
||||
yield[
|
||||
'With ending tag only (invalid placeholder)' => 'This is test%',
|
||||
sprintf($template, 'This is test%'),
|
||||
];
|
||||
}
|
||||
|
||||
public function provideTemplateToFillUsingIncorrectValues(): ?Generator
|
||||
{
|
||||
$template = 'Cannot fill template \'%s\', because of missing values for placeholder(s): %s. Did you provide all'
|
||||
. ' required values?';
|
||||
|
||||
yield[
|
||||
new Template('%test%'),
|
||||
[
|
||||
'something' => 123,
|
||||
],
|
||||
sprintf(
|
||||
$template,
|
||||
'%test%',
|
||||
'test'
|
||||
),
|
||||
];
|
||||
|
||||
yield[
|
||||
new Template('%test%'),
|
||||
[],
|
||||
sprintf(
|
||||
$template,
|
||||
'%test%',
|
||||
'test'
|
||||
),
|
||||
];
|
||||
|
||||
yield[
|
||||
new Template('%test1% - %test2%'),
|
||||
[
|
||||
'test1' => 123,
|
||||
],
|
||||
sprintf(
|
||||
$template,
|
||||
'%test1% - %test2%',
|
||||
'test2'
|
||||
),
|
||||
];
|
||||
|
||||
yield[
|
||||
new Template('%test1% - %test2%'),
|
||||
[
|
||||
'test1' => 123,
|
||||
'test3' => 456,
|
||||
],
|
||||
sprintf(
|
||||
$template,
|
||||
'%test1% - %test2%',
|
||||
'test2'
|
||||
),
|
||||
];
|
||||
|
||||
yield[
|
||||
new Template('%test1% / %test2% / %test3%'),
|
||||
[
|
||||
'test1' => 123,
|
||||
],
|
||||
sprintf(
|
||||
$template,
|
||||
'%test1% / %test2% / %test3%',
|
||||
'test2, test3'
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
public function provideTemplateToFill(): ?Generator
|
||||
{
|
||||
yield[
|
||||
'Template with 1 placeholder',
|
||||
new Template('%test%'),
|
||||
[
|
||||
'test' => 123,
|
||||
],
|
||||
'123',
|
||||
];
|
||||
|
||||
yield[
|
||||
'Template with 1 placeholder, but more values',
|
||||
new Template('%test%'),
|
||||
[
|
||||
'test' => 123,
|
||||
'anotherTest' => 456,
|
||||
],
|
||||
'123',
|
||||
];
|
||||
|
||||
yield[
|
||||
'Template with 2 placeholders',
|
||||
new Template('My name is %name% and I am %profession%'),
|
||||
[
|
||||
'name' => 'Jane',
|
||||
'profession' => 'photographer',
|
||||
],
|
||||
'My name is Jane and I am photographer',
|
||||
];
|
||||
|
||||
yield[
|
||||
'Template with 2 placeholders, but more values',
|
||||
new Template('My name is %name% and I am %profession%'),
|
||||
[
|
||||
'name' => 'Jane',
|
||||
'test-test' => 123,
|
||||
'profession' => 'photographer',
|
||||
'anotherTest' => 456,
|
||||
],
|
||||
'My name is Jane and I am photographer',
|
||||
];
|
||||
|
||||
yield[
|
||||
'Template with 2 placeholders that contains space',
|
||||
new Template('My name is %first name% %last name% and I live in %current location%'),
|
||||
[
|
||||
'first name' => 'Jane',
|
||||
'last name' => 'Brown',
|
||||
'current location' => 'NY, USA',
|
||||
],
|
||||
'My name is Jane Brown and I live in NY, USA',
|
||||
];
|
||||
|
||||
yield[
|
||||
'Template with 2 placeholders that contains space, but more values',
|
||||
new Template('My name is %first name% %last name% and I live in %current location%'),
|
||||
[
|
||||
'first name' => 'Jane',
|
||||
'profession' => 'photographer',
|
||||
'last name' => 'Brown',
|
||||
'test-test' => 123,
|
||||
'anotherTest' => 456,
|
||||
'current location' => 'NY, USA',
|
||||
],
|
||||
'My name is Jane Brown and I live in NY, USA',
|
||||
];
|
||||
}
|
||||
|
||||
public function provideValidContent(): ?Generator
|
||||
{
|
||||
yield[
|
||||
'Template with 1 placeholder',
|
||||
'%test%',
|
||||
];
|
||||
|
||||
yield[
|
||||
'Template with 2 placeholders',
|
||||
'My name is %name% and I am %profession%',
|
||||
];
|
||||
|
||||
yield[
|
||||
'Template with 2 placeholders that contains space',
|
||||
'My name is %first name% %last name% and I live in %current location%',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,15 +21,153 @@ use Meritoo\Common\ValueObject\Version;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\ValueObject\Version
|
||||
* @covers \Meritoo\Common\ValueObject\Version
|
||||
*/
|
||||
class VersionTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Provide version as array and expected instance of version
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideAsArray()
|
||||
{
|
||||
yield [
|
||||
[],
|
||||
null,
|
||||
];
|
||||
|
||||
yield [
|
||||
[
|
||||
1,
|
||||
0,
|
||||
],
|
||||
null,
|
||||
];
|
||||
|
||||
yield [
|
||||
[
|
||||
10,
|
||||
],
|
||||
null,
|
||||
];
|
||||
|
||||
yield [
|
||||
[
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
],
|
||||
new Version(0, 0, 0),
|
||||
];
|
||||
|
||||
yield [
|
||||
[
|
||||
1,
|
||||
0,
|
||||
2,
|
||||
],
|
||||
new Version(1, 0, 2),
|
||||
];
|
||||
|
||||
yield [
|
||||
[
|
||||
10,
|
||||
5,
|
||||
41,
|
||||
],
|
||||
new Version(10, 5, 41),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide version as string and expected instance of version
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideAsString()
|
||||
{
|
||||
yield [
|
||||
'',
|
||||
null,
|
||||
];
|
||||
|
||||
yield [
|
||||
'1.0',
|
||||
null,
|
||||
];
|
||||
|
||||
yield [
|
||||
'10',
|
||||
null,
|
||||
];
|
||||
|
||||
yield [
|
||||
'0.0.0',
|
||||
new Version(0, 0, 0),
|
||||
];
|
||||
|
||||
yield [
|
||||
'1.0.2',
|
||||
new Version(1, 0, 2),
|
||||
];
|
||||
|
||||
yield [
|
||||
'10.5.41',
|
||||
new Version(10, 5, 41),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide instance of version and expected version converted to string
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideConvertedToString()
|
||||
{
|
||||
yield [
|
||||
new Version(0, 0, 0),
|
||||
'0.0.0',
|
||||
];
|
||||
|
||||
yield [
|
||||
new Version(1, 0, 2),
|
||||
'1.0.2',
|
||||
];
|
||||
|
||||
yield [
|
||||
new Version(10, 5, 41),
|
||||
'10.5.41',
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(Version::class, OopVisibilityType::IS_PUBLIC, 3, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $version The version
|
||||
* @param Version $expected (optional) Expected version
|
||||
*
|
||||
* @dataProvider provideAsArray
|
||||
*/
|
||||
public function testFromArray(array $version, Version $expected = null)
|
||||
{
|
||||
static::assertEquals($expected, Version::fromArray($version));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $version The version
|
||||
* @param Version $expected (optional) Expected version
|
||||
*
|
||||
* @dataProvider provideAsString
|
||||
*/
|
||||
public function testFromString($version, Version $expected = null)
|
||||
{
|
||||
static::assertEquals($expected, Version::fromString($version));
|
||||
}
|
||||
|
||||
public function testNewInstance()
|
||||
{
|
||||
$version = new Version(1, 0, 2);
|
||||
@@ -48,144 +186,6 @@ class VersionTest extends BaseTestCase
|
||||
*/
|
||||
public function testToString(Version $version, $expected)
|
||||
{
|
||||
static::assertSame($expected, (string)$version);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $version The version
|
||||
* @param Version $expected (optional) Expected version
|
||||
*
|
||||
* @dataProvider provideAsString
|
||||
*/
|
||||
public function testFromString($version, Version $expected = null)
|
||||
{
|
||||
static::assertEquals($expected, Version::fromString($version));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $version The version
|
||||
* @param Version $expected (optional) Expected version
|
||||
*
|
||||
* @dataProvider provideAsArray
|
||||
*/
|
||||
public function testFromArray(array $version, Version $expected = null)
|
||||
{
|
||||
static::assertEquals($expected, Version::fromArray($version));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide instance of version and expected version converted to string
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideConvertedToString()
|
||||
{
|
||||
yield[
|
||||
new Version(0, 0, 0),
|
||||
'0.0.0',
|
||||
];
|
||||
|
||||
yield[
|
||||
new Version(1, 0, 2),
|
||||
'1.0.2',
|
||||
];
|
||||
|
||||
yield[
|
||||
new Version(10, 5, 41),
|
||||
'10.5.41',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide version as string and expected instance of version
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideAsString()
|
||||
{
|
||||
yield[
|
||||
'',
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
'1.0',
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
'10',
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
'0.0.0',
|
||||
new Version(0, 0, 0),
|
||||
];
|
||||
|
||||
yield[
|
||||
'1.0.2',
|
||||
new Version(1, 0, 2),
|
||||
];
|
||||
|
||||
yield[
|
||||
'10.5.41',
|
||||
new Version(10, 5, 41),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide version as array and expected instance of version
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideAsArray()
|
||||
{
|
||||
yield[
|
||||
[],
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
[
|
||||
1,
|
||||
0,
|
||||
],
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
[
|
||||
10,
|
||||
],
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
[
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
],
|
||||
new Version(0, 0, 0),
|
||||
];
|
||||
|
||||
yield[
|
||||
[
|
||||
1,
|
||||
0,
|
||||
2,
|
||||
],
|
||||
new Version(1, 0, 2),
|
||||
];
|
||||
|
||||
yield[
|
||||
[
|
||||
10,
|
||||
5,
|
||||
41,
|
||||
],
|
||||
new Version(10, 5, 41),
|
||||
];
|
||||
static::assertSame($expected, (string) $version);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user