public function editTextByUser(TextEntity $text, User $user) { if ($text->getUser()->getId() === $user->getId()) { $this->repository->save($text); return true; } else { return false; } }
public static function createDump(Text $text) { $dump = ['id' => $text->getId(), 'title' => $text->getTitle(), 'annotation' => $text->getAnnotation(), 'text' => $text->getText()]; return $dump; }
public function testDeleteFeed() { $newId = 12; $this->routeMatch->setParam('action', 'delete'); $currentUserMock = $this->login(); $data = ['id' => $newId]; #Current user create mock $currentUserMock->method('getId')->will($this->returnValue(1)); #End current user create mock # Define test entity $findedText = new Text(); $findedText->setId($newId); $findedText->setUser($currentUserMock); # #emMock $emMock = $this->getEmMock(); #Mock find method $emMock->expects($this->once())->method('find')->with('Texsts\\Entity\\Text', $newId)->will($this->returnValue($findedText)); # #Mock pesist method $persistedObject = null; $emMock->expects($this->once())->method('remove')->will($this->returnCallback(function ($object) use(&$persistedObject) { $persistedObject = $object; })); # $emMock->expects($this->once())->method('flush'); $this->service->getRepository()->setEm($emMock); #end emMock $this->request->setPost(new Parameters($data)); $result = $this->controller->dispatch($this->request); $response = $this->controller->getResponse(); $this->assertEquals(200, $response->getStatusCode()); if (!$result->getVariables()['success']) { $this->fail("Fail with deleting"); } $this->assertEquals($newId, $persistedObject->getId()); }