From f5995515c8a19e1332a267b8861e3d80b0491f4c Mon Sep 17 00:00:00 2001 From: David Naber Date: Fri, 12 Feb 2016 13:01:59 +0100 Subject: [PATCH] Assert that the new post ID is passed to the ImportPost #57 --- .../Import/Service/WpPostImporterTest.php | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/WpIntegration/Import/Service/WpPostImporterTest.php b/tests/phpunit/WpIntegration/Import/Service/WpPostImporterTest.php index 8537506..89f6be3 100644 --- a/tests/phpunit/WpIntegration/Import/Service/WpPostImporterTest.php +++ b/tests/phpunit/WpIntegration/Import/Service/WpPostImporterTest.php @@ -59,6 +59,11 @@ public function test_import_post( Array $post_data, Array $meta_data, Array $id_ ->method( 'action_fired' ) ->with( $text_action ); + /** + * Todo: #57 + * Instantiate the new actors here, and bind them to the action. + * The tests should still pass then. + */ add_action( $text_action, /** @@ -77,6 +82,10 @@ function( $wp_post, $import_post ) $import_post_mock, $import_post ); + $this->assertSame( + $wp_post->ID, + $import_post->id() + ); $this->make_post_assertions( $wp_post, $import_post, $id_map ); $this->make_meta_assertions( $wp_post, $meta_data ); $this->make_term_assertions( $wp_post, $import_post, $term_data ); @@ -260,7 +269,30 @@ public function build_import_post_mock( Array $post_data, Array $meta_data, $ter ); } - return $this->mock_builder->type_wp_import_post( [], $post_data ); + $post_mock = $this->mock_builder->type_wp_import_post( [], $post_data ); + + /** + * WpPostImporter MUST pass the new wp-post id to the import post object. + * Its used as a one-time setter. Each ensuing call will return this new post id. + * This is asserted in test_import_post() + */ + $post_mock->expects( $this->atLeast( 1 ) ) + ->method( 'id' ) + ->willReturnCallback( + function( $id = NULL ) { + static $local_id; + if ( ! $local_id ) { + $local_id = 0; + } + if ( ! $id || $local_id ) + return $local_id; + + $local_id = (int) $id; + return $local_id; + } + ); + + return $post_mock; } /**