/** * */ public function test() { $jsonDataList = \UserProvider::getJsonData(); $rawUserInfoList = []; foreach ($jsonDataList as $json) { $arr = json_decode($json, true); $this->assertTrue(is_array($arr)); $rawUserInfoList[] = $arr; } $docFactory = new DocumentFactory(self::$documentPrototype); foreach ($rawUserInfoList as $rawUserInfo) { $payload = $docFactory->buildPayload($rawUserInfo); $this->assertArrayNotHasKey('name', $payload, print_r($payload, true)); $this->assertArrayNotHasKey('email', $payload, print_r($payload, true)); $this->assertArrayNotHasKey('track_ref', $payload, print_r($payload, true)); $this->assertArrayNotHasKey('loginip', $payload, print_r($payload, true)); $this->assertArrayHasKey('country', $payload, print_r($payload, true)); foreach ($payload as $field => $value) { if ($field === 'status') { $this->assertTrue(is_int($value) && $value >= 0); continue; } $this->assertNotEmpty($value, sprintf('field [%s] should not be empty', $field)); } $document = $docFactory->buildDocument($payload['snsid'], $payload); $this->assertEquals($payload, $document->getData()); $document2 = $docFactory->make($payload['snsid'], $rawUserInfo); $this->assertEquals($payload, $document2->getData()); } }
/** * @return array */ public function userProvider() { require_once __DIR__ . '/UserProvider.php'; $jsonArr = \UserProvider::getJsonData(); $data = array_map(function ($json) { $array = json_decode($json, true); $this->assertTrue(is_array($array)); return $array; }, $jsonArr); return $data; }
/** * */ public function testMakeUser() { require_once __DIR__ . '/UserProvider.php'; $jsonArr = \UserProvider::getJsonData(); foreach ($jsonArr as $json) { $dbEntity = json_decode($json, true); static::assertArrayHasKey('snsid', $dbEntity); $userObj = $this->factory->makeUser($dbEntity); static::assertInstanceOf(User::class, $userObj); $userArr = $this->factory->toArray($userObj); static::assertArrayHasKey('snsid', $userArr); static::assertArrayHasKey('status', $userArr, print_r($userArr, true)); } }