Make WordPress Core

Changes between Initial Version and Version 1 of Ticket #41722, comment 8


Ignore:
Timestamp:
08/30/2017 09:55:40 AM (6 years ago)
Author:
birgire
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #41722, comment 8

    initial v1  
    1 Here's a first draft for db host strings examples:
     1Here's a first draft for db host string examples:
    22
    33{{{
    44
    55// db hosts and the expected host, port, socket
    6 $data = array(
    7         // db_host                              // host                 //port          //socket
    8         '::1'                           => array( '[::1]',              null,           null                    ),
    9         '[::1]'                         => array( '[::1]',              null,           null                    ),
    10         '[::1]:3306'                    => array( '[::1]',              '3306',         null                    ),
    11         '127.0.0.1'                     => array( '127.0.0.1',          null,           null                    ),
    12         '127.0.0.1:3306'                => array( '127.0.0.1',          '3306',         null                    ),
    13         'example.com'                   => array( 'example.com',        null,           null                    ),
    14         'example.com:3306'              => array( 'example.com',        '3306',         null                    ),                     
    15         'localhost'                     => array( 'localhost',          null,           null                    ),
    16         'localhost:/tmp/mysql.sock'     => array( 'localhost',          null,           '/tmp/mysql.sock'       ),
     6$data = array(
     7        // db_host                                              // host                                         //port          //socket
     8        ''                                              => array( null,                                         null,           null                    ),
     9        ':3306'                                         => array( null,                                         '3306',         null                    ),
     10        ':/tmp/mysql.sock'                              => array( null,                                         null,          '/tmp/mysql.sock'        ),
     11        '127.0.0.1'                                     => array( '127.0.0.1',                                  null,           null                    ),
     12        '127.0.0.1:3306'                                => array( '127.0.0.1',                                  '3306',         null                    ),
     13        'example.com'                                   => array( 'example.com',                                null,           null                    ),
     14        'example.com:3306'                              => array( 'example.com',                                '3306',         null                    ),
     15        'localhost'                                     => array( 'localhost',                                  null,           null                    ),
     16        'localhost:/tmp/mysql.sock'                     => array( 'localhost',                                  null,           '/tmp/mysql.sock'       ),
     17        '0000:0000:0000:0000:0000:0000:0000:0001'       => array( '[0000:0000:0000:0000:0000:0000:0000:0001]',  null,           null                    ),
     18        '::1'                                           => array( '[::1]',                                      null,           null                    ),
     19        '[::1]'                                         => array( '[::1]',                                      null,           null                    ),
     20        '[::1]:3306'                                    => array( '[::1]',                                      '3306',         null                    ),
     21        '2001:0db8:0000:0000:0000:ff00:0042:8329'       => array( '[2001:0db8:0000:0000:0000:ff00:0042:8329]',  null,           null                    ),
     22        '2001:db8:0:0:0:ff00:42:8329'                   => array( '[2001:db8:0:0:0:ff00:42:8329]',              null,           null                    ),
     23        '2001:db8::ff00:42:8329'                        => array( '[2001:db8::ff00:42:8329]',                   null,           null                    ),
    1724);
    1825}}}
     26
     27Some host string examples come from:
     28
     29- https://en.wikipedia.org/wiki/IPv6#Addressing
     30
     31- https://dev.mysql.com/doc/apis-php/en/apis-php-function.mysql-connect.html
     32
    1933
    2034Here we assume the mysql native driver.
     
    2438{{{
    2539foreach( (array) $data as $db_host => $expected ) {
    26         $result = $wpdb->parse_db_host( $db_host );
    27         $this->assertEqualSets( $expected, $result );
     40        $actual = $wpdb->parse_db_host( $db_host );
     41        $this->assertEquals( $expected, $actual );
    2842}
    2943               
    3044}}}
    3145
    32 we get:
    33 
    34 {{{
    35 FAILURES!
    36 Tests: 1, Assertions: 9, Failures: 1.
    37 }}}
    38 
    39 The socket test seem to fail.
     46we get failed tests for the db host strings:  {{{':3306'}}}, {{{':/tmp/mysql.sock'}}} and {{{'localhost:/tmp/mysql.sock'}}}
    4047
    4148I wonder if the brackets should be handled outside of the {{{parse_db_host()}}} function? That way the output would be more predictable, as it wouldn't depend on the library. It would also make the above testing easier.