public function __construct() { parent::__construct(); $this->title = 'How To Use Test Fixtures'; $this->excerpt = 'Test fixtures are really helpful.'; $this->content = 'Just use fixtures. You will not regret it'; }
public function __construct() { parent::__construct(); $this->id = 1; $this->title = 'Unit Testing Is Gnarly'; $this->excerpt = 'A short summary.'; $this->content = 'This is post content'; $this->date = \DateTime::createFromFormat('m/d/Y', '06/20/1986'); }
public function getAsPost() { $post = new Post(); $post->setTitle($this->getTitle()); $post->setExcerpt($this->getExcerpt()); $post->setContent($this->getContent()); $post->setDate($this->getDate()); return $post; }
public static function create($title, $content, $excerpt, User $user) { $post = new Post(); $post->setTitle($title); $post->setContent($content); $post->setExcerpt($excerpt); $post->setUser($user); return $post; }
public function isNew() { $this->__load(); return parent::isNew(); }
public function test_create_method_creates_new_post() { $user = new User(); $date = new \DateTime("now"); $post = Post::create("title", "content", "excerpt", $user); $this->assertEquals("title", $post->getTitle()); $this->assertEquals("excerpt", $post->getExcerpt()); $this->assertEquals("content", $post->getContent()); $this->assertSame($user, $post->getUser()); $this->assertEquals($date, $post->getDate()); }
<?php use Domain\Entities; use Presentation\Models\Input; use Infrastructure\Persistence\Doctrine\PostRepository; $authService->addRoute('/^\\/admin.*/'); $postRepo = new PostRepository(); $app->get('/admin/post', function () use($app, $postRepo, $authService) { $app->render('add_post.phtml', ['user_posts' => $postRepo->getBy(['user' => $authService->getLoggedInUser('superblorg')])]); }); $app->post('/admin/post', function () use($app, $authService, $postRepo) { $input = new Input\Post($app->request()->post('post')); $user = $authService->getLoggedInUser('superblorg'); $post = Entities\Post::create($input->title, $input->content, $input->excerpt, $user); if ($input->isValid()) { $postRepo->store($post); } $app->render('add_post.phtml', ['post' => $input, 'user_posts' => $postRepo->getBy(['user' => $user]), 'saved' => $post]); });
public function setPost(Post $post) { $post->addComment($this); $this->post = $post; }