Code Duplication    Length = 14-14 lines in 4 locations

projects/packages/connection/tests/php/test_Tokens.php 1 location

@@ 193-206 (lines=14) @@
190
	 *
191
	 * @return array
192
	 */
193
	public function intercept_jetpack_token_health_request_failed( $response, $args, $url ) {
194
		if ( false === strpos( $url, 'jetpack-token-health' ) ) {
195
			return $response;
196
		}
197
198
		return array(
199
			'headers'  => new Requests_Utility_CaseInsensitiveDictionary( array( 'content-type' => 'application/json' ) ),
200
			'body'     => wp_json_encode( array( 'dummy_error' => true ) ),
201
			'response' => array(
202
				'code'    => 500,
203
				'message' => 'failed',
204
			),
205
		);
206
	}
207
208
	/**
209
	 * Intercept the `jetpack-token-health` API request sent to WP.com, and mock successful response.

projects/packages/connection/tests/php/test-rest-endpoints.php 3 locations

@@ 563-576 (lines=14) @@
560
	 *
561
	 * @return array
562
	 */
563
	public function intercept_validate_tokens_request_failed( $response, $args, $url ) {
564
		if ( false === strpos( $url, 'jetpack-token-health' ) ) {
565
			return $response;
566
		}
567
568
		return array(
569
			'headers'  => new Requests_Utility_CaseInsensitiveDictionary( array( 'content-type' => 'application/json' ) ),
570
			'body'     => wp_json_encode( array( 'dummy_error' => true ) ),
571
			'response' => array(
572
				'code'    => 500,
573
				'message' => 'failed',
574
			),
575
		);
576
	}
577
578
	/**
579
	 * Build the response for a tokens validation request
@@ 630-643 (lines=14) @@
627
	 *
628
	 * @return array
629
	 */
630
	public function intercept_refresh_blog_token_request( $response, $args, $url ) {
631
		if ( false === strpos( $url, 'jetpack-refresh-blog-token' ) ) {
632
			return $response;
633
		}
634
635
		return array(
636
			'headers'  => new Requests_Utility_CaseInsensitiveDictionary( array( 'content-type' => 'application/json' ) ),
637
			'body'     => wp_json_encode( array( 'jetpack_secret' => self::BLOG_TOKEN ) ),
638
			'response' => array(
639
				'code'    => 200,
640
				'message' => 'OK',
641
			),
642
		);
643
	}
644
645
	/**
646
	 * Intercept the `jetpack-refresh-blog-token` API request sent to WP.com, and mock the failure response.
@@ 654-667 (lines=14) @@
651
	 *
652
	 * @return array
653
	 */
654
	public function intercept_refresh_blog_token_request_fail( $response, $args, $url ) {
655
		if ( false === strpos( $url, 'jetpack-refresh-blog-token' ) ) {
656
			return $response;
657
		}
658
659
		return array(
660
			'headers'  => new Requests_Utility_CaseInsensitiveDictionary( array( 'content-type' => 'application/json' ) ),
661
			'body'     => wp_json_encode( array( 'jetpack_secret_missing' => true ) ), // Meaningless body.
662
			'response' => array(
663
				'code'    => 200,
664
				'message' => 'OK',
665
			),
666
		);
667
	}
668
669
	/**
670
	 * Intercept the `jetpack-token-health` API request sent to WP.com, and mock the "invalid blog token" response.