/**
  * Remove post with given id
  *
  * @param $id
  * @return mixed
  */
 public function remove($id)
 {
     $post = $this->getRepository()->find($id);
     EntityManager::remove($post);
     EntityManager::flush();
     return Redirect::route('post.list');
 }
 /**
  * Convenient method for returning object repository
  * @param string $name
  */
 protected function getRepository($name = null)
 {
     if ($name === null) {
         $name = $this->getDefaultRepositoryName();
     }
     return EntityManager::getRepository($name);
 }
 /**
  * POST: Create new object if no id is presented, otherwise update the object with given id
  * @param Request $request
  * @return Response
  */
 protected function createOrUpdate(Request $request)
 {
     $object = Api::handle($request, $this->getDefaultRepositoryName());
     EntityManager::persist($object);
     EntityManager::flush();
     return Api::render($object, $this->getDefaultDetailsSerializerGroup());
 }
 public function testShow()
 {
     $articleData = $this->_getArticleData();
     $testArticle = new Article($articleData['title'], $articleData['body']);
     $articleId = 15;
     $this->_mockEntityManagerFacade();
     EntityManager::shouldReceive('find')->with(Article::class, $articleId)->andReturn($testArticle);
     $this->visit('/articles/' . $articleId)->see($articleData['title'])->see($articleData['body']);
 }
 protected function _mockEntityManagerFacade()
 {
     // Now, mock the repository so it returns the mock of the employee
     /** @var TestCase $this */
     $testRepository = $this->getMockBuilder(ArticleRepository::class)->disableOriginalConstructor()->getMock();
     // Last, mock the EntityManager to return the mock of the repository
     EntityManager::shouldReceive('getRepository')->with(Article::class)->andReturn($testRepository);
     /** @var DatabaseTransactions $this */
     EntityManager::shouldReceive('getConnection')->andReturn($this->_getMockConnection());
 }
 /**
  * @param string $prefix
  * @return array
  */
 protected function _saveTags($prefix = 'testTag#0')
 {
     $aTags = [$prefix . '-1', $prefix . '-2', $prefix . '-3'];
     $savedTags = [];
     foreach ($aTags as $tagName) {
         $tagEntity = new Tag($tagName);
         EntityManager::persist($tagEntity);
         $savedTags[] = $tagEntity;
     }
     EntityManager::flush();
     return array_map(function (Tag $oTag) {
         return $oTag->getId();
     }, $savedTags);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $article = EntityManager::find(Article::class, $id);
     if (!$article) {
         return view('doctrination.article.show', compact('article'));
     }
     EntityManager::remove($article);
     EntityManager::flush();
     return redirect("articles");
 }