@@ -113,16 +113,35 @@ add_volume_to_service cli "$EXTENSION_INI_VOLUME"
113113
114114cat > " $WP_DIR /native-verify-extension.php" << 'EOF '
115115<?php
116- require '/var/www/src/wp-content/plugins/sqlite-database-integration/wp-includes/database/load.php';
116+ require_once '/var/www/src/wp-content/plugins/sqlite-database-integration/wp-includes/database/load.php';
117117
118118$lexer = new WP_MySQL_Lexer( 'SELECT 1' );
119119if ( ! ( $lexer instanceof WP_MySQL_Native_Lexer ) ) {
120120 fwrite( STDERR, "Native lexer is not available in the WordPress PHP test container.\n" );
121121 exit( 1 );
122122}
123123
124+ $tokens = $lexer->native_token_stream();
125+ $rules = include '/var/www/src/wp-content/plugins/sqlite-database-integration/wp-includes/database/mysql/mysql-grammar.php';
126+ $grammar = new WP_Parser_Grammar( $rules );
127+ $parser = new WP_MySQL_Parser( $grammar, $tokens );
128+ if ( ! ( $parser instanceof WP_MySQL_Native_Parser ) ) {
129+ fwrite( STDERR, "WordPress PHP test container did not select the native parser.\n" );
130+ exit( 1 );
131+ }
132+
133+ $parser_ast = $parser->parse();
134+ if ( ! ( $parser_ast instanceof WP_MySQL_Native_Parser_Node ) ) {
135+ fwrite( STDERR, "Native parser did not produce a native-backed AST in the WordPress PHP test container.\n" );
136+ exit( 1 );
137+ }
138+
124139$driver = new WP_PDO_MySQL_On_SQLite( 'mysql-on-sqlite:path=:memory:;dbname=wp;' );
125140$parser = $driver->create_parser( 'SELECT 1' );
141+ if ( ! ( $parser instanceof WP_MySQL_Native_Parser ) ) {
142+ fwrite( STDERR, "WordPress PHP test container SQLite driver did not create a native parser.\n" );
143+ exit( 1 );
144+ }
126145$parser->next_query();
127146$ast = $parser->get_query_ast();
128147
@@ -157,5 +176,31 @@ if ( $same_first !== $first || ! in_array( $synthetic, $same_first->get_children
157176}
158177EOF
159178
179+ node - " $WP_DIR /tests/phpunit/includes/bootstrap.php" << 'NODE '
180+ const fs = require( 'fs' );
181+
182+ const file = process.argv[2];
183+ const marker = "require_once ABSPATH . 'wp-settings.php';";
184+ const guard = [
185+ '/*',
186+ ' * Native parser CI guard. This file is generated by the SQLite integration workflow.',
187+ ' */',
188+ "require_once dirname( __DIR__, 3 ) . '/native-verify-extension.php';",
189+ ].join( '\n' );
190+
191+ let contents = fs.readFileSync( file, 'utf8' );
192+
193+ if ( contents.includes( guard ) ) {
194+ process.exit( 0 );
195+ }
196+
197+ if ( ! contents.includes( marker ) ) {
198+ throw new Error( `Unable to find WordPress bootstrap marker in ${ file }.` );
199+ }
200+
201+ contents = contents.replace( marker, `${ marker }\n\n${ guard }` );
202+ fs.writeFileSync( file, contents );
203+ NODE
204+
160205node tools/local-env/scripts/docker.js run --rm php php -m | grep -qx ' wp_mysql_parser'
161206node tools/local-env/scripts/docker.js run --rm php php /var/www/native-verify-extension.php
0 commit comments