I have a static function is given below: want to test this function using PHPUnit
One.php:
static function myArray(myArrays $one) {
$data = [
"Name" => "name",
"id" => "_id",
"addressLine1" => "address1",
"town" => "town",
"district" => "district",
"country" => "country",
"mobile" => "mobile_number",
"email" => "email",
"url" => "_url"
];
$output = [];
foreach ($data as $myDatas => $value) {
if ($one->truthy($myDatas)) {
$field = $one->getField($myDatas);
$output[$value] = $field;
}
}
$output['country'] = strtolower($oneninetwo->getField("countryCode", ""));
return $output;
}
I have created a JSON file for this tests:
{
"success":true,
"data":{
"id":"0001",
"name":"Pizza",
"addressLine1":"001 Down Town",
"addressLine2":null,
"addressLine3":null,
"country":"AU",
"countryCode":"au";
"mobile":0123456789,
"email":"[email protected]"
}
}
My tests:
public function testmyArray() {
$mockreg = $this->getMockRegistry();
$json = file_get_contents(__DIR__."/src/myjson.json");
$data = json_decode($json, true);
$name = $data['data']['name'];
$addressLine1 = $data['data']['addressLine1'];
$addressLine2 = $data['data']['addressLine2'];
$addressLine3 = $data['data']['addressLine3'];
$mobile = $data['data']['mobile'];
self::assertEquals($name, "Pizza");
self::assertEquals($addressLine1, "001 Down Town");
self::assertNull($addressLine2);
self::assertTrue(is_numeric($mobile));
$test = new class() extends One{
function __construct() {
$this->myArray();
----
}
};
}
Now want to tests the One class returns an array of objects with a value set and check the values?
Is this a good way to test or another way to test the array objects?
Any help?