Skip to content

Commit

Permalink
CS fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Apr 4, 2024
1 parent 95b1fc4 commit 2c54702
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 25 deletions.
12 changes: 6 additions & 6 deletions tests/WP_SQLite_Translator_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,28 +150,28 @@ public function testLeftFunction1Char() {
$result = $this->assertQuery(
'SELECT LEFT("abc", 1) as output'
);
$this->assertEquals( "a", $result[0]->output );
$this->assertEquals( 'a', $result[0]->output );
}

public function testLeftFunction5Chars() {
$result = $this->assertQuery(
'SELECT LEFT("Lorem ipsum", 5) as output'
);
$this->assertEquals( "Lorem", $result[0]->output );
$this->assertEquals( 'Lorem', $result[0]->output );
}

public function testLeftFunctionNullString() {
$result = $this->assertQuery(
'SELECT LEFT(NULL, 5) as output'
);
$this->assertEquals( null, $result[0]->output );
$this->assertEquals( null, $result[0]->output );
}

public function testLeftFunctionNullLength() {
$result = $this->assertQuery(
'SELECT LEFT("Test", NULL) as output'
);
$this->assertEquals( null, $result[0]->output );
$this->assertEquals( null, $result[0]->output );
}

public function testInsertSelectFromDual() {
Expand Down Expand Up @@ -1279,8 +1279,8 @@ public function testShowGrantsFor() {
$result,
array(
(object) array(
'Grants for root@localhost' => 'GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `root`@`localhost` WITH GRANT OPTION'
)
'Grants for root@localhost' => 'GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `root`@`localhost` WITH GRANT OPTION',
),
)
);
}
Expand Down
84 changes: 71 additions & 13 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,22 @@
* Polyfills for WordPress functions
*/
if ( ! function_exists( 'do_action' ) ) {
function do_action() {
}
/**
* Polyfill the do_action function.
*/
function do_action() {}
}

if( ! function_exists( 'apply_filters' ) ) {
if ( ! function_exists( 'apply_filters' ) ) {
/**
* Polyfill the apply_filters function.
*
* @param string $tag The filter name.
* @param mixed $value The value to filter.
* @param mixed ...$args Additional arguments to pass to the filter.
*
* @return mixed Returns $value.
*/
function apply_filters( $tag, $value, ...$args ) {
return $value;
}
Expand All @@ -24,48 +35,95 @@ function apply_filters( $tag, $value, ...$args ) {
/**
* Polyfills for php 8 functions
*/
/**
* @see https://www.php.net/manual/en/function.str-starts-with
*/

if ( ! function_exists( 'str_starts_with' ) ) {
/**
* Check if a string starts with a specific substring.
*
* @param string $haystack The string to search in.
* @param string $needle The string to search for.
*
* @see https://www.php.net/manual/en/function.str-starts-with
*
* @return bool
*/
function str_starts_with( string $haystack, string $needle ) {
return empty( $needle ) || 0 === strpos( $haystack, $needle );
}
}

/**
* @see https://www.php.net/manual/en/function.str-contains
*/
if ( ! function_exists( 'str_contains' ) ) {
/**
* Check if a string contains a specific substring.
*
* @param string $haystack The string to search in.
* @param string $needle The string to search for.
*
* @see https://www.php.net/manual/en/function.str-contains
*
* @return bool
*/
function str_contains( string $haystack, string $needle ) {
return empty( $needle ) || false !== strpos( $haystack, $needle );
}
}

/**
* @see https://www.php.net/manual/en/function.str-ends-with
*/
if ( ! function_exists( 'str_ends_with' ) ) {
/**
* Check if a string ends with a specific substring.
*
* @param string $haystack The string to search in.
* @param string $needle The string to search for.
*
* @see https://www.php.net/manual/en/function.str-ends-with
*
* @return bool
*/
function str_ends_with( string $haystack, string $needle ) {
return empty( $needle ) || $needle === substr( $haystack, -strlen( $needle ) );
return empty( $needle ) || substr( $haystack, -strlen( $needle ) === $needle );
}
}
if ( extension_loaded( 'mbstring' ) ) {

if ( ! function_exists( 'mb_str_starts_with' ) ) {
/**
* Polyfill for mb_str_starts_with.
*
* @param string $haystack The string to search in.
* @param string $needle The string to search for.
*
* @return bool
*/
function mb_str_starts_with( string $haystack, string $needle ) {
return empty( $needle ) || 0 === mb_strpos( $haystack, $needle );
}
}

if ( ! function_exists( 'mb_str_contains' ) ) {
/**
* Polyfill for mb_str_contains.
*
* @param string $haystack The string to search in.
* @param string $needle The string to search for.
*
* @return bool
*/
function mb_str_contains( string $haystack, string $needle ) {
return empty( $needle ) || false !== mb_strpos( $haystack, $needle );
}
}

if ( ! function_exists( 'mb_str_ends_with' ) ) {
/**
* Polyfill for mb_str_ends_with.
*
* @param string $haystack The string to search in.
* @param string $needle The string to search for.
*
* @return bool
*/
function mb_str_ends_with( string $haystack, string $needle ) {
// phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found
return empty( $needle ) || $needle = mb_substr( $haystack, - mb_strlen( $needle ) );
}
}
Expand Down
14 changes: 8 additions & 6 deletions wp-includes/sqlite/class-wp-sqlite-translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2028,9 +2028,9 @@ private function translate_date_add_sub( $token ) {

/**
* Translate the LEFT() function.
*
*
* > Returns the leftmost len characters from the string str, or NULL if any argument is NULL.
*
*
* https://dev.mysql.com/doc/refman/8.3/en/string-functions.html#function_left
*
* @param WP_SQLite_Token $token The token to translate.
Expand Down Expand Up @@ -3063,11 +3063,13 @@ private function execute_show() {
return;

case 'GRANTS FOR':
$this->set_results_from_fetched_data( array(
(object) array(
'Grants for root@localhost' => 'GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `root`@`localhost` WITH GRANT OPTION'
$this->set_results_from_fetched_data(
array(
(object) array(
'Grants for root@localhost' => 'GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `root`@`localhost` WITH GRANT OPTION',
),
)
) );
);
return;

case 'FULL COLUMNS':
Expand Down

0 comments on commit 2c54702

Please sign in to comment.