/** @test */
 function it_should_add_post_to_repository()
 {
     $this->repo->add(new Post(5, '2015-04-20', 1, 'Title 5', 'slug-5'));
     $newRepo = new JsonPostRepository($this->jsonFile);
     $this->assertEquals(9, $this->repo->all()->count());
     $this->assertEquals(9, $newRepo->all()->count());
 }
Example #2
0
<?php

require 'bootstrap.php';
use LittleThings\JsonPostRepository;
use LittleThings\Post;
$postsJson = STORAGE_PATH . '/posts-copy.json';
copy(config()['posts_json'], $postsJson);
$repo = new JsonPostRepository($postsJson);
// Ensure that post with ID of 24280 works
var_dump($repo->findById(24280));
// Add new post to repository and ensure it persists
$repo->add(new Post(123, '2015-01-01', 1, 'This is the Title', 'this-is-the-title'));
var_dump($repo->findById(123));
// Get all posts and ensure json_encode works
echo json_encode($repo->all());