mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 01:31:45 +01:00
Size, e.g. of image
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\Test\Common\Exception\ValueObject;
|
||||
|
||||
use Meritoo\Common\Exception\ValueObject\InvalidSizeDimensionsException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while dimensions of size, passed to the instance of Size class, are invalid
|
||||
*
|
||||
* @author Meritoo <github@meritoo.pl>
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*/
|
||||
class InvalidSizeDimensionsExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
InvalidSizeDimensionsException::class,
|
||||
OopVisibilityType::IS_PUBLIC,
|
||||
3
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $width The width
|
||||
* @param int $height The height
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
*
|
||||
* @dataProvider provideWidthAndHeight
|
||||
*/
|
||||
public function testCreate($width, $height, $expectedMessage)
|
||||
{
|
||||
$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),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -624,6 +624,28 @@ class RegexTest extends BaseTestCase
|
||||
self::assertEquals($expected, Regex::getValidColorHexValue($color));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $emptyValue Empty value, e.g. ""
|
||||
* @dataProvider provideEmptyValue
|
||||
*/
|
||||
public static function testIsSizeValueUsingEmptyValue($emptyValue)
|
||||
{
|
||||
self::assertFalse(Regex::isSizeValue($emptyValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description Description of test
|
||||
* @param string $value Value to verify
|
||||
* @param string $separator Separator used to split width and height
|
||||
* @param bool $expected Expected result of verification
|
||||
*
|
||||
* @dataProvider provideSizeToVerify
|
||||
*/
|
||||
public function testIsSizeValue($description, $value, $separator, $expected)
|
||||
{
|
||||
self::assertEquals($expected, Regex::isSizeValue($value, $separator), $description);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value Value that should be transformed to slug
|
||||
* @param string $expected Expected slug
|
||||
@@ -1788,6 +1810,191 @@ class RegexTest extends BaseTestCase
|
||||
];
|
||||
}
|
||||
|
||||
public function provideSizeToVerify()
|
||||
{
|
||||
yield[
|
||||
'One number only',
|
||||
200,
|
||||
' x ',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'One number only as string',
|
||||
'200',
|
||||
' x ',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'The " " as invalid separator',
|
||||
'200 100',
|
||||
' x ',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'The "|" as separator (invalid separator)',
|
||||
'200 | 100',
|
||||
' x ',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'The "|" as invalid separator and no spaces around separator',
|
||||
'200|100',
|
||||
' x ',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'The "X" as invalid separator',
|
||||
'200 X 100',
|
||||
' x ',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'Simple, valid size',
|
||||
'200 x 100',
|
||||
' x ',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'Too much spaces at the right of separator',
|
||||
'200 x 100',
|
||||
' x ',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'Too much spaces at the left of separator',
|
||||
'200 x 100',
|
||||
' x ',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'Too much spaces around separator',
|
||||
'200 x 100',
|
||||
' x ',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'Too much spaces before width',
|
||||
' 200 x 100',
|
||||
' x ',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'Too much spaces after height',
|
||||
'200 x 100 ',
|
||||
' x ',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'Too much spaces before width and after height',
|
||||
' 200 x 100 ',
|
||||
' x ',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'Too much spaces everywhere (1st)',
|
||||
' 200 x 100 ',
|
||||
' x ',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'Too much spaces everywhere (2nd)',
|
||||
' 200 x 100 ',
|
||||
' x ',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'Too much spaces everywhere (3rd)',
|
||||
' 200 x 100 ',
|
||||
' x ',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'The " X " as custom separator',
|
||||
'200 X 100',
|
||||
' X ',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'The "|" as custom separator',
|
||||
'200|100',
|
||||
'|',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'The " | " as custom separator',
|
||||
'200 | 100',
|
||||
' | ',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'The "::" as custom separator',
|
||||
'200::100',
|
||||
'::',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'The " :: " as custom separator',
|
||||
'200 :: 100',
|
||||
' :: ',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'The "." as custom separator',
|
||||
'200.100',
|
||||
'.',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'The " . " as custom separator',
|
||||
'200 . 100',
|
||||
' . ',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'The "/" as custom separator',
|
||||
'200/100',
|
||||
'/',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'The " / " as custom separator',
|
||||
'200 / 100',
|
||||
' / ',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'The " : " as custom separator and too much spaces everywhere',
|
||||
' 200 : 100 ',
|
||||
' : ',
|
||||
true,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
||||
1095
tests/ValueObject/SizeTest.php
Normal file
1095
tests/ValueObject/SizeTest.php
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user