public function createWebsites() { $websites = [['n' => 'Rekenmeeseter', 'u' => 'www.rekenmeester.be', 'o' => ['WIS G1', 'WIS G1.a'], 't' => ['optellen', 'aftrekken']], ['n' => 'Google', 'u' => 'www.google.be', 'o' => ['WIS G7', 'WIS G9', 'WIS G9.e'], 't' => ['optellen', 'Sinterklaas']]]; foreach ($websites as $awebsite) { $website = Website::register(new Name($awebsite['n']), new URL($awebsite['u'])); foreach ($awebsite['t'] as $atag) { $tag = $this->tagRepo->tagOfName(new TagName($atag)); $website->addTag($tag); } foreach ($awebsite['o'] as $aobjective) { $objective = $this->currRepo->objectiveOfCode($aobjective); $website->addObjective($objective); } $this->manager->persist($website); $this->websiteRepo->add($website); } }
/** * Updates a website (with tags and objectives) of a given id . * @param $id * @param $data * @return Website * @throws WebsiteNotFoundException */ public function update($id, $data) { //MANDATORY FIELDS --------------------------------- $this->nameIsRequired($data); $this->urlIsRequired($data); /** @var Website $website */ $website = $this->websiteOfId($id); if (!$website) { throw new WebsiteNotFoundException($id); } $website->setName(new Name($data['name'])); $website->setUrl(new URL($data['url'])); $this->setDescription($data, $website); $this->addImage($data, $website); $this->syncTags($data, $website); $this->syncObjectives($data, $website); $this->websitesRepository->update($website); return $website; }
/** * @test * @group websitesrepo */ public function should_return_null_when_website_not_found_with_url() { $url = new URL('foo.be'); $site = $this->websiteRepo->websiteOfURL($url); $this->assertNull($site); }