If you want to create a post via the post factory in you tests you can do it like this:
function test_getPostsInYear() {
$post1_id = $this->factory->post->create( array( 'post_date' => date( '2010-04-08 13:46:43' ) ) );
$post2_id = $this->factory->post->create( array( 'post_date' => date( '2014-04-08 13:46:43' ) ) );
..
Make sure to pass a date! Unix timestamps or other formats won’t work.
This creates 2 posts with different dates. You can test the function getPostsInYear(2014) as follows:
$result = $this->plugin->getPostsInYear( 2014 );
$post_ids = array();
foreach ( $result as $post ) {
$post_ids[] = $post->ID;
}
$this->assertNotContains( $post1_id, $post_ids );
$this->assertContains( $post2_id, $post_ids );Post1 should not be returned by getPostsInYear( 2014 ) because it was posted in 2010 so we cover this by assertNotContains().