-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added hydrateFrom() and appendFrom() methods #26
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cccfe54
Added hydrateFrom() and appendFrom() methods.
smolinari dcc1998
no message
smolinari 8150bc6
Added an exception for incorrect type
smolinari 9bd99c6
Added test for test coverage
smolinari 38b0561
Added another exception for incorrect data
smolinari 805e6db
Some improvements and added type checker.
smolinari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
namespace Michaels\Manager\Exceptions; | ||
|
||
/** | ||
* SerializationTypeNotSupportedException | ||
* @package Michaels\Manager | ||
*/ | ||
class IncorrectDataException extends \InvalidArgumentException | ||
{ | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
namespace Michaels\Manager\Exceptions; | ||
|
||
/** | ||
* SerializationTypeNotSupportedException | ||
* @package Michaels\Manager | ||
*/ | ||
class SerializationTypeNotSupportedException extends \InvalidArgumentException | ||
{ | ||
|
||
} | ||
|
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 |
---|---|---|
|
@@ -212,7 +212,7 @@ public function testGetIfHasReturnsMessageIfNoExists() | |
$actual = $this->manager->getIfHas('nope'); | ||
|
||
$this->assertInstanceOf('Michaels\Manager\Messages\NoItemFoundMessage', $actual, 'failed to return an instance of NoItemFoundMessage'); | ||
$this->assertEquals("`nope` was not found", $actual->getMessage(), 'failed to return the correct mesage'); | ||
$this->assertEquals("`nope` was not found", $actual->getMessage(), 'failed to return the correct message'); | ||
} | ||
|
||
public function testUpdateSingleItem() | ||
|
@@ -498,4 +498,133 @@ public function testLoadDefaultsIntoNonEmptyManager() | |
|
||
$this->assertEquals($expected, $manager->getAll(), "failed to load defaults"); | ||
} | ||
|
||
public function testHydrateFromJson() | ||
{ | ||
$json = json_encode($this->testData); | ||
$this->manager->clear(); | ||
$this->manager->hydrateFrom('json', $json); | ||
|
||
$this->assertEquals($this->testData, $this->manager->getAll(), "failed to hydrate from JSON"); | ||
|
||
} | ||
|
||
public function testAppendFromJson() | ||
{ | ||
$startData = [ | ||
'one' => [ | ||
'two' => [ | ||
'three' => [ | ||
'true' => true, | ||
] | ||
], | ||
'four' => [ | ||
'six' => false, | ||
] | ||
], | ||
'five' => 5, | ||
'six' => [ | ||
'a' => 'A', | ||
'b' => 'B', | ||
'c' => 'C', | ||
] | ||
]; | ||
|
||
$appendData = json_encode([ | ||
'seven' => [ | ||
'two' => [], | ||
'four' => 'michael' | ||
], | ||
'eight' => [ | ||
'foo' => 'bar', | ||
], | ||
'nine' => 10 | ||
]); | ||
|
||
$expected = [ | ||
'one' => [ | ||
'two' => [ | ||
'three' => [ | ||
'true' => true, | ||
] | ||
], | ||
'four' => [ | ||
'six' => false, | ||
] | ||
], | ||
'five' => 5, | ||
'six' => [ | ||
'a' => 'A', | ||
'b' => 'B', | ||
'c' => 'C', | ||
], | ||
'seven' => [ | ||
'two' => [], | ||
'four' => 'michael' | ||
], | ||
'eight' => [ | ||
'foo' => 'bar' | ||
], | ||
'nine' => 10 | ||
]; | ||
|
||
$this->manager->reset($startData); | ||
$this->manager->appendFrom('json', $appendData); | ||
|
||
$this->assertEquals($expected, $this->manager->getAll(), "failed to append from JSON"); | ||
|
||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding to the comment on line 411, a quick test to for passing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. |
||
/** | ||
* @expectedException \Michaels\Manager\Exceptions\SerializationTypeNotSupportedException | ||
*/ | ||
|
||
public function testSerializationTypeUnsupportedExceptionForHydrate() | ||
{ | ||
$data = "just a string"; | ||
$this->manager->hydrateFrom('someType', $data); | ||
|
||
} | ||
|
||
/** | ||
* @expectedException \Michaels\Manager\Exceptions\SerializationTypeNotSupportedException | ||
*/ | ||
|
||
public function testSerializationTypeUnsupportedExceptionForAppend() | ||
{ | ||
$data = "just a string"; | ||
$this->manager->appendFrom('someType', $data); | ||
|
||
} | ||
|
||
/** | ||
* @expectedException \Michaels\Manager\Exceptions\IncorrectDataException | ||
*/ | ||
|
||
public function testIncorrectDataExceptionForHydrate() | ||
{ | ||
$data = array(); | ||
$this->manager->hydrateFrom('json', $data); | ||
|
||
} | ||
|
||
/** | ||
* @expectedException \Michaels\Manager\Exceptions\IncorrectDataException | ||
*/ | ||
|
||
public function testIncorrectDataExceptionForAppend() | ||
{ | ||
$data = array(); | ||
$this->manager->appendFrom('json', $data); | ||
|
||
} | ||
|
||
public function testDenormalizedTypeInput() | ||
{ | ||
$json = json_encode($this->testData); | ||
$this->manager->clear(); | ||
$this->manager->hydrateFrom('jSOn ', $json); | ||
|
||
$this->assertEquals($this->testData, $this->manager->getAll(), "failed to hydrate from JSON, with type `jSOn `."); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching the typo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No Problem.