Reformat code automatically

This commit is contained in:
Meritoo
2022-02-12 14:46:47 +01:00
parent a3af138f0c
commit a3adae50b8
116 changed files with 19152 additions and 19091 deletions

View File

@@ -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

View File

@@ -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);
}
/**

View File

@@ -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);
}
/**

View File

@@ -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

View File

@@ -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%',
];
}
}

View File

@@ -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);
}
}