/** * Persist the film data. * * @param array $data Data of film with the next structure: * [ * [ * 'id' => the id of the film * 'name' => The name * 'url' => the url of the film * 'tags' => [tag1, tag2, ...] * ], * ... * ] * Note: The id and the tags can be empty * * @return bool */ public function execute($data) { $tagCollection = TagCollectionFactory::buildTagCollectionFromArray($this->tagEntity, $data['tags']); $film = FilmFactory::buildFilm($this->filmEntity, $data['name'], $data['url'], $data['id'], $tagCollection); $film->persist(); return true; }
/** * @test */ public function testPersistWithTag() { $this->expectOutputString("importing: \"name test\"; Url: url test; Tags: tag 1,tag 2\n"); $film = new Film(); $tag = new Tag(); $tagCollection = TagCollectionFactory::buildTagCollectionFromArray($tag, ['tag 1', 'tag 2']); $film->persist(FilmFactory::buildFilm($film, 'name test', 'url test', '', $tagCollection)); }
/** * @test */ public function testBuildTagCollectionFromArrayWithItemsInArray() { $tags = ['tag1', 'tag2']; $collection = TagCollectionFactory::buildTagCollectionFromArray($this->dummyTagEntity, $tags); $tagsResult = []; foreach ($collection as $item) { $tagsResult[] = $item->getTag(); } $this->assertEquals($tags, $tagsResult, 'Some think has not got well when you are build a collection from a not empty array'); }