/** * Test Get/Set, create, endpoint methods. */ public function testUserEntity() { $user = User::create(); $this->assertInstanceOf('Shoko\\TwitchApiBundle\\Model\\Entity\\User', $user); $this->assertEquals('user', $user->getType()); $this->assertEquals('some_type', $user->setType('some_type')->getType()); $this->assertEquals(null, $user->getName()); $this->assertEquals('some_name', $user->setName('some_name')->getName()); $date = new \DateTime(); $this->assertEquals(null, $user->getCreatedAt()); $this->assertEquals($date, $user->setCreatedAt($date)->getCreatedAt()); $this->assertEquals(null, $user->getUpdatedAt()); $this->assertEquals($date, $user->setUpdatedAt($date)->getUpdatedAt()); $this->assertEquals(array(), $user->getLinks()); $link = 'some_link'; $this->assertEquals([$link], $user->setLinks([$link])->getLinks()); $this->assertEquals(null, $user->getLogo()); $this->assertEquals('some_logo', $user->setLogo('some_logo')->getLogo()); $this->assertEquals(null, $user->getId()); $this->assertEquals('some_id', $user->setId('some_id')->getId()); $this->assertEquals(null, $user->getDisplayName()); $this->assertEquals('some_display_name', $user->setDisplayName('some_display_name')->getDisplayName()); $this->assertEquals(null, $user->getBio()); $this->assertEquals('some_bio', $user->setBio('some_bio')->getBio()); }
/** * @param array $data * @param false|User $user * * @return User */ public function createEntity(array $data, $user = false) { if (false === $user) { $user = User::create(); } if (isset($data['type'])) { $user = $user->setType($data['type']); } if (isset($data['name'])) { $user = $user->setName($data['name']); } if (isset($data['created_at'])) { $user = $user->setCreatedAt(new \DateTime($data['created_at'])); } if (isset($data['updated_at'])) { $user = $user->setUpdatedAt(new \DateTime($data['updated_at'])); } if (isset($data['_links'])) { $user = $user->setLinks($data['_links']); } if (isset($data['logo'])) { $user = $user->setLogo($data['logo']); } if (isset($data['_id'])) { $user = $user->setId($data['_id']); } if (isset($data['display_name'])) { $user = $user->setDisplayName($data['display_name']); } if (isset($data['bio'])) { $user = $user->setBio($data['bio']); } return $user; }