Code Duplication    Length = 21-24 lines in 2 locations

tests/phpunit/tests/rest-api/rest-post-meta-fields.php 1 location

@@ 420-443 (lines=24) @@
417
    /**
418
     * @depends test_set_value
419
     */
420
    public function test_set_value_db_error() 
421
    {
422
        $data = array(
423
         'meta' => array(
424
          'test_single' => 'test_value',
425
         ),
426
        );
427
428
        $this->grant_write_permission();
429
430
        $request = new WP_REST_Request('POST', sprintf('/wp/v2/posts/%d', self::$post_id));
431
        $request->set_body_params($data);
432
433
        /**
434
         * Disable showing error as the below is going to intentionally
435
         * trigger a DB error.
436
         */
437
        global $wpdb;
438
        $wpdb->suppress_errors = true;
439
        add_filter('query', array( $this, 'error_insert_query' ));
440
441
        $response = $this->server->dispatch($request);
442
        remove_filter('query', array( $this, 'error_insert_query' ));
443
        $wpdb->show_errors = true;
444
    }
445
446
    public function test_set_value_invalid_type() 

tests/phpunit/tests/rest-api/rest-posts-controller.php 1 location

@@ 1729-1749 (lines=21) @@
1726
        $this->assertEquals($time, strtotime($new_post->post_modified));
1727
    }
1728
1729
    public function test_create_post_with_db_error() 
1730
    {
1731
        wp_set_current_user(self::$editor_id);
1732
1733
        $request = new WP_REST_Request('POST', '/wp/v2/posts');
1734
        $params  = $this->set_post_data(array());
1735
        $request->set_body_params($params);
1736
1737
        /**
1738
         * Disable showing error as the below is going to intentionally
1739
         * trigger a DB error.
1740
         */
1741
        global $wpdb;
1742
        $wpdb->suppress_errors = true;
1743
        add_filter('query', array( $this, 'error_insert_query' ));
1744
1745
        $response = $this->server->dispatch($request);
1746
        remove_filter('query', array( $this, 'error_insert_query' ));
1747
        $wpdb->show_errors = true;
1748
1749
        $this->assertErrorResponse('db_insert_error', $response, 500);
1750
    }
1751
1752
    public function test_create_post_with_invalid_date()