-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Shureban/v0.4.0
support setters
- Loading branch information
Showing
12 changed files
with
133 additions
and
25 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
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
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,16 @@ | ||
<?php | ||
|
||
namespace Shureban\LaravelObjectMapper\Tests\Unit; | ||
|
||
use Shureban\LaravelObjectMapper\Attributes\SetterName; | ||
use Tests\TestCase; | ||
|
||
class SetterNameTest extends TestCase | ||
{ | ||
public function test_SetterName() | ||
{ | ||
$this->assertEquals('setSimple', (string)new SetterName('simple')); | ||
$this->assertEquals('setCamelCaseMethod', (string)new SetterName('camelCaseMethod')); | ||
$this->assertEquals('setSnakeCaseMethod', (string)new SetterName('snake_case_method')); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,28 @@ | ||
<?php | ||
|
||
namespace Shureban\LaravelObjectMapper\Tests\Unit\Structs; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class WithSetterClass | ||
{ | ||
public string $value; | ||
public string $request_value; | ||
|
||
/** | ||
* @param string $value | ||
*/ | ||
public function setValue(string $value): void | ||
{ | ||
$this->value = sprintf('setter_%s', $value); | ||
} | ||
|
||
/** | ||
* @param string $value | ||
* @param FormRequest $request | ||
*/ | ||
public function setRequestValue(string $value, FormRequest $request): void | ||
{ | ||
$this->request_value = sprintf('setter_%s', $value); | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
namespace Shureban\LaravelObjectMapper\Tests\Unit\Structs; | ||
|
||
class WithoutTypeClass | ||
{ | ||
public $int; | ||
public $float; | ||
public $string; | ||
public $bool; | ||
public $array; | ||
public $object; | ||
} |
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,20 @@ | ||
<?php | ||
|
||
namespace Shureban\LaravelObjectMapper\Tests\Unit; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
use Shureban\LaravelObjectMapper\ObjectMapper; | ||
use Shureban\LaravelObjectMapper\Tests\Unit\Structs\WithSetterClass; | ||
use Tests\TestCase; | ||
|
||
class WithSetterTest extends TestCase | ||
{ | ||
public function test_withSetter() | ||
{ | ||
$request = new FormRequest(); | ||
$request->merge(['request_value' => 'request_value']); | ||
|
||
$this->assertEquals('setter_value', (new ObjectMapper(new WithSetterClass()))->mapFromJson('{"value": "value"}')->value); | ||
$this->assertEquals('setter_request_value', (new ObjectMapper(new WithSetterClass()))->mapFromRequest($request, false)->request_value); | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
namespace Shureban\LaravelObjectMapper\Tests\Unit; | ||
|
||
use Shureban\LaravelObjectMapper\ObjectMapper; | ||
use Shureban\LaravelObjectMapper\Tests\Unit\Structs\SimpleTypeClass; | ||
use Tests\TestCase; | ||
|
||
class WithoutTypeTest extends TestCase | ||
{ | ||
public function test_withoutType() | ||
{ | ||
$this->assertEquals(10, (new ObjectMapper(new SimpleTypeClass()))->mapFromJson('{"int": 10}')->int); | ||
$this->assertEquals(10.10, (new ObjectMapper(new SimpleTypeClass()))->mapFromJson('{"float": 10.10}')->float); | ||
$this->assertEquals("10", (new ObjectMapper(new SimpleTypeClass()))->mapFromJson('{"string": "10"}')->string); | ||
$this->assertEquals(true, (new ObjectMapper(new SimpleTypeClass()))->mapFromJson('{"bool": true}')->bool); | ||
$this->assertEquals([10], (new ObjectMapper(new SimpleTypeClass()))->mapFromJson('{"array": [10]}')->array); | ||
$this->assertEquals((object)['key' => 'value'], (new ObjectMapper(new SimpleTypeClass()))->mapFromJson('{"object": {"key":"value"}}')->object); | ||
} | ||
} |