-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix file wrapper tests and refactored code
Signed-off-by: Asad Ali <[email protected]>
- Loading branch information
1 parent
eb97c18
commit 14d5c3b
Showing
2 changed files
with
50 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,11 @@ | |
|
||
namespace Core\Tests; | ||
|
||
use Core\Tests\Mocking\MockHelper; | ||
use Core\Tests\Mocking\Other\Customer; | ||
use Core\Tests\Mocking\Other\MockClass; | ||
use Core\Tests\Mocking\Other\Order; | ||
use Core\Tests\Mocking\Other\Person; | ||
use Core\Tests\Mocking\Types\MockFileWrapper; | ||
use Core\Utils\CoreHelper; | ||
use Core\Utils\DateHelper; | ||
use Core\Utils\XmlDeserializer; | ||
|
@@ -187,7 +187,7 @@ public function testCoreHelperConvertToNullableString() | |
$this->assertEquals("false", CoreHelper::convertToNullableString("false")); | ||
} | ||
|
||
public function testToString() | ||
public function testToStringWithInheritanceAndNesting() | ||
{ | ||
$customer = new Customer(); | ||
$customer->name = 'John Doe'; | ||
|
@@ -210,94 +210,92 @@ public function testToString() | |
$order->total = 250.75; | ||
$order->delivered = true; | ||
|
||
$expected = 'Placed Order [orderId: 123, sender: Customer [email: [email protected], ' . | ||
$expected = 'Order [orderId: 123, sender: Customer [email: [email protected], ' . | ||
'name: John Doe, additionalProperties: [age: 21]], similarOrders: [Order [orderId: 345], ' . | ||
'Order [orderId: 567, sender: Customer [email: [email protected], name: John Doe, ' . | ||
'additionalProperties: [age: 21]]]], total: 250.75, delivered: true]'; | ||
$actual = "Placed $order"; | ||
|
||
$this->assertEquals($expected, $actual); | ||
$this->assertEquals($expected, $order); | ||
} | ||
|
||
public function testToStringWithNonArrayAndNonModelProperties() | ||
public function testToStringWithFileType() | ||
{ | ||
$fileWrapper = MockHelper::getFileWrapper(); | ||
$fileWrapper = MockFileWrapper::createFromPath('some\path\test.txt', 'text/plain', 'My Text'); | ||
|
||
$person = new Person(); | ||
$person->additionalProperties = [ | ||
'file' => $fileWrapper | ||
]; | ||
|
||
$expected = 'Person [additionalProperties: [file: MockFileWrapper [realFilePath: some\path\test.txt,' . | ||
' mimeType: text/plain, filename: My Text]]]'; | ||
|
||
$this->assertEquals($expected, $person); | ||
} | ||
|
||
public function testToStringWithStdClass() | ||
{ | ||
$object = new stdClass(); | ||
$object->name = "John"; | ||
$object->age = 30; | ||
|
||
$person = new Person(); | ||
$person->additionalProperties = [ | ||
'stdClass' => $object, | ||
'file' => $fileWrapper | ||
'stdClassArray' => [$object, $object], | ||
'stdClassMap' => ['keyA' => $object, 'keyB' => $object] | ||
]; | ||
|
||
$expected = 'My Person [additionalProperties: [stdClass: [name: John, age: 30], file: MockFileWrapper' . | ||
' [realFilePath: C:\Users\Asad Apimatic\vs-workspace\core-lib-php\tests\Mocking\Other\testFile.txt,' . | ||
' mimeType: text/plain, filename: My Text]]]'; | ||
$actual = "My $person"; | ||
$expected = 'Person [additionalProperties: [stdClass: [name: John, age: 30], stdClassArray: ' . | ||
'[[name: John, age: 30], [name: John, age: 30]], stdClassMap: [keyA: [name: John, age: 30], ' . | ||
'keyB: [name: John, age: 30]]]]'; | ||
|
||
$this->assertEquals($expected, $actual); | ||
$this->assertEquals($expected, $person); | ||
} | ||
|
||
public function testCoreHelperStringify() | ||
{ | ||
$expectedStringNotation = 'Model [prop1: true, prop2: 90, prop3: my string 1, additionalProperties: ' . | ||
'[additional1: [A, B, false, true], additional2: other string, additional3: false], ' . | ||
'parentProp1: 1.1, parentProp2: some string]'; | ||
$expectedStringNotation = 'Model [prop1: true, prop2: 90, prop3: my string 3, prop4: [23, 24.4]]'; | ||
|
||
$this->assertEquals($expectedStringNotation, CoreHelper::stringify( | ||
'Model', | ||
[ | ||
'prop1' => true, | ||
'prop2' => 90, | ||
'prop3' => 'my string 1', | ||
'additionalProperties' => | ||
[ | ||
'additional1' => [ 'A', 'B', false, true ], | ||
'additional2' => 'other string', | ||
'additional3' => false, | ||
] | ||
], | ||
CoreHelper::stringify( | ||
'Parent', | ||
[ | ||
'parentProp1' => 1.1, | ||
'parentProp2' => 'some string' | ||
] | ||
) | ||
'prop3' => 'my string 3', | ||
'prop4' => [23, 24.4] | ||
] | ||
)); | ||
} | ||
|
||
public function testCoreHelperStringifyWithoutAdditionalProperties() | ||
public function testCoreHelperStringifyWithProcessedProperties() | ||
{ | ||
$expectedStringNotation = 'Model [prop1: true, prop2: 90.234, prop3: my string 2, parentProp1: 1.0, ' . | ||
'parentProp2: some string]'; | ||
$expectedStringNotation = 'Model [prop1: true, prop2: 90, prop3: my string 1, ' . | ||
'parentProp1: 1.1, parentProp2: some string, additionalProperties: ' . | ||
'[additional1: [A, B, false, true], additional2: other string, additional3: false]]'; | ||
|
||
$this->assertEquals($expectedStringNotation, CoreHelper::stringify( | ||
'Model', | ||
$processedProperties = CoreHelper::stringify( | ||
'Parent', | ||
[ | ||
'prop1' => true, | ||
'prop2' => 90.234, | ||
'prop3' => 'my string 2' | ||
], | ||
'Parent [parentProp1: 1.0, parentProp2: some string]' | ||
)); | ||
} | ||
|
||
public function testCoreHelperStringifyWithoutPostfix() | ||
{ | ||
$expectedStringNotation = 'Model [prop1: true, prop2: 90, prop3: my string 3, prop4: [23, 24.4]]'; | ||
'parentProp1' => 1.1, | ||
'parentProp2' => 'some string', | ||
'additionalProperties' => | ||
[ | ||
'additional1' => [ 'A', 'B', false, true ], | ||
'additional2' => 'other string', | ||
'additional3' => false, | ||
] | ||
] | ||
); | ||
|
||
$this->assertEquals($expectedStringNotation, CoreHelper::stringify( | ||
'Model', | ||
[ | ||
'prop1' => true, | ||
'prop2' => 90, | ||
'prop3' => 'my string 3', | ||
'prop4' => [23, 24.4] | ||
] | ||
'prop3' => 'my string 1' | ||
], | ||
$processedProperties | ||
)); | ||
} | ||
|
||
|