first commit
This commit is contained in:
5
wp-content/plugins/weglot/vendor/gmulti/morphism-php/tests/Mocks/User.php
vendored
Normal file
5
wp-content/plugins/weglot/vendor/gmulti/morphism-php/tests/Mocks/User.php
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class User {
|
||||
|
||||
}
|
||||
112
wp-content/plugins/weglot/vendor/gmulti/morphism-php/tests/MorphismArrayTest.php
vendored
Normal file
112
wp-content/plugins/weglot/vendor/gmulti/morphism-php/tests/MorphismArrayTest.php
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
use Morphism\Morphism;
|
||||
|
||||
class MorphismArrayTest extends TestCase
|
||||
{
|
||||
public function setUp(){
|
||||
$this->data = array(
|
||||
array(
|
||||
"name" => "Iron Man",
|
||||
"firstName" => "Tony",
|
||||
"lastName" => "Stark",
|
||||
"address" => array(
|
||||
"city" => "New York City",
|
||||
"country" => "USA"
|
||||
),
|
||||
"phoneNumber" => array(
|
||||
array(
|
||||
"type" => "home",
|
||||
"number" => "212 555-1234"
|
||||
),
|
||||
array(
|
||||
"type" => "mobile",
|
||||
"number" => "646 555-4567"
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
"name" => "Spiderman",
|
||||
"firstName" => "Peter",
|
||||
"lastName" => "Parker",
|
||||
"address" => array(
|
||||
"city" => "New York City",
|
||||
"country" => "USA"
|
||||
),
|
||||
"phoneNumber" => array(
|
||||
array(
|
||||
"type" => "home",
|
||||
"number" => "293 093-2321"
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function testActionArrayStringPath()
|
||||
{
|
||||
$schema = array(
|
||||
"city" => "address.city"
|
||||
);
|
||||
|
||||
Morphism::setMapper("User", $schema);
|
||||
|
||||
$result = Morphism::map("User", $this->data);
|
||||
|
||||
$this->assertEquals(count($result), 2);
|
||||
$this->assertEquals($result[0]->city, "New York City");
|
||||
}
|
||||
|
||||
|
||||
public function testActionFunctionPath(){
|
||||
$schema = array(
|
||||
"city" => function($data){
|
||||
return strtolower($data["address"]["city"]);
|
||||
}
|
||||
);
|
||||
|
||||
Morphism::setMapper("User", $schema);
|
||||
|
||||
$result = Morphism::map("User", $this->data);
|
||||
|
||||
$this->assertEquals($result[0]->city, "new york city");
|
||||
$this->assertEquals($result[1]->city, "new york city");
|
||||
}
|
||||
|
||||
public function testActionAgregatorPath(){
|
||||
$schema = array(
|
||||
"fullName" => array(
|
||||
"firstName", "lastName"
|
||||
)
|
||||
);
|
||||
|
||||
Morphism::setMapper("User", $schema);
|
||||
|
||||
$result = Morphism::map("User", $this->data);
|
||||
|
||||
$this->assertEquals($result[0]->fullName, "Tony Stark");
|
||||
$this->assertEquals($result[1]->fullName, "Peter Parker");
|
||||
}
|
||||
|
||||
public function testActionFunctionObjectPath(){
|
||||
$schema = array(
|
||||
"city" => (object) array(
|
||||
"path" => "address.city",
|
||||
"fn" => function($city) {
|
||||
return strtolower($city);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
Morphism::setMapper("User", $schema);
|
||||
|
||||
$result = Morphism::map("User", $this->data);
|
||||
|
||||
$this->assertEquals($result[0]->city, "new york city");
|
||||
$this->assertEquals($result[1]->city, "new york city");
|
||||
}
|
||||
|
||||
}
|
||||
91
wp-content/plugins/weglot/vendor/gmulti/morphism-php/tests/MorphismTest.php
vendored
Normal file
91
wp-content/plugins/weglot/vendor/gmulti/morphism-php/tests/MorphismTest.php
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
use Morphism\Morphism;
|
||||
|
||||
require __DIR__ . "/Mocks/User.php";
|
||||
|
||||
class MorphismTest extends TestCase
|
||||
{
|
||||
public function setUp(){
|
||||
$this->data = array(
|
||||
"name" => "Iron Man",
|
||||
"firstName" => "Tony",
|
||||
"lastName" => "Stark",
|
||||
"address" => array(
|
||||
"city" => "New York City",
|
||||
"country" => "USA"
|
||||
),
|
||||
"phoneNumber" => array(
|
||||
array(
|
||||
"type" => "home",
|
||||
"number" => "212 555-1234"
|
||||
),
|
||||
array(
|
||||
"type" => "mobile",
|
||||
"number" => "646 555-4567"
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function testActionStringPath(){
|
||||
$schema = array(
|
||||
"city" => "address.city"
|
||||
);
|
||||
|
||||
Morphism::setMapper("User", $schema);
|
||||
|
||||
$result = Morphism::map("User", $this->data);
|
||||
|
||||
$this->assertEquals($result->city, "New York City");
|
||||
|
||||
}
|
||||
|
||||
public function testActionFunctionPath(){
|
||||
$schema = array(
|
||||
"city" => function($data){
|
||||
return strtolower($data["address"]["city"]);
|
||||
}
|
||||
);
|
||||
|
||||
Morphism::setMapper("User", $schema);
|
||||
|
||||
$result = Morphism::map("User", $this->data);
|
||||
|
||||
$this->assertEquals($result->city, "new york city");
|
||||
}
|
||||
|
||||
public function testActionAgregatorPath(){
|
||||
$schema = array(
|
||||
"fullName" => array(
|
||||
"firstName", "lastName"
|
||||
)
|
||||
);
|
||||
|
||||
Morphism::setMapper("User", $schema);
|
||||
|
||||
$result = Morphism::map("User", $this->data);
|
||||
|
||||
$this->assertEquals($result->fullName, "Tony Stark");
|
||||
}
|
||||
|
||||
public function testActionFunctionObjectPath(){
|
||||
$schema = array(
|
||||
"city" => (object) array(
|
||||
"path" => "address.city",
|
||||
"fn" => function($city) {
|
||||
return strtolower($city);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
Morphism::setMapper("User", $schema);
|
||||
|
||||
$result = Morphism::map("User", $this->data);
|
||||
|
||||
$this->assertEquals($result->city, "new york city");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user