Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove RUN_PARSER_TESTS flag from PHPUnit tests #1605

Merged
merged 1 commit into from
Jul 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ script:
# Check parser syntax
php lib/parser.php || exit 1
# Run PHPUnit tests
RUN_PARSER_TESTS=1 phpunit || exit 1
phpunit || exit 1
WP_MULTISITE=1 phpunit || exit 1
fi
- |
Expand Down
89 changes: 41 additions & 48 deletions phpunit/class-parsing-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,65 +5,58 @@
* @package Gutenberg
*/

// To run these tests, set the RUN_PARSER_TESTS environment variable to a
// truthy value.
if ( getenv( 'RUN_PARSER_TESTS' ) ) {
/**
* Tests for the PHP parser generated from our PEG grammar by `phpegjs`.
*/
class Parsing_Test extends WP_UnitTestCase {
protected static $fixtures_dir;
class Parsing_Test extends WP_UnitTestCase {
protected static $fixtures_dir;

function parsing_test_filenames() {
self::$fixtures_dir = dirname( dirname( __FILE__ ) ) . '/blocks/test/fixtures';
function parsing_test_filenames() {
self::$fixtures_dir = dirname( dirname( __FILE__ ) ) . '/blocks/test/fixtures';

require_once dirname( dirname( __FILE__ ) ) . '/lib/parser.php';
require_once dirname( dirname( __FILE__ ) ) . '/lib/parser.php';

$fixture_filenames = glob( self::$fixtures_dir . '/*.{json,html}', GLOB_BRACE );
$fixture_filenames = array_values( array_unique( array_map(
array( $this, 'clean_fixture_filename' ),
$fixture_filenames
) ) );
$fixture_filenames = glob( self::$fixtures_dir . '/*.{json,html}', GLOB_BRACE );
$fixture_filenames = array_values( array_unique( array_map(
array( $this, 'clean_fixture_filename' ),
$fixture_filenames
) ) );

return array_map(
array( $this, 'pass_parser_fixture_filenames' ),
$fixture_filenames
);
}
return array_map(
array( $this, 'pass_parser_fixture_filenames' ),
$fixture_filenames
);
}

function clean_fixture_filename( $filename ) {
$filename = basename( $filename );
$filename = preg_replace( '/\..+$/', '', $filename );
return $filename;
}
function clean_fixture_filename( $filename ) {
$filename = basename( $filename );
$filename = preg_replace( '/\..+$/', '', $filename );
return $filename;
}

function pass_parser_fixture_filenames( $filename ) {
return array(
"$filename.html",
"$filename.parsed.json",
);
}
function pass_parser_fixture_filenames( $filename ) {
return array(
"$filename.html",
"$filename.parsed.json",
);
}

/**
* @dataProvider parsing_test_filenames
*/
function test_parser_output( $html_filename, $parsed_json_filename ) {
$html_filename = self::$fixtures_dir . '/' . $html_filename;
$parsed_json_filename = self::$fixtures_dir . '/' . $parsed_json_filename;
/**
* @dataProvider parsing_test_filenames
*/
function test_parser_output( $html_filename, $parsed_json_filename ) {
$html_filename = self::$fixtures_dir . '/' . $html_filename;
$parsed_json_filename = self::$fixtures_dir . '/' . $parsed_json_filename;

foreach ( array( $html_filename, $parsed_json_filename ) as $filename ) {
if ( ! file_exists( $filename ) ) {
throw new Exception( "Missing fixture file: '$filename'" );
}
foreach ( array( $html_filename, $parsed_json_filename ) as $filename ) {
if ( ! file_exists( $filename ) ) {
throw new Exception( "Missing fixture file: '$filename'" );
}
}

$html = file_get_contents( $html_filename );
$expected_parsed = json_decode( file_get_contents( $parsed_json_filename ), true );
$html = file_get_contents( $html_filename );
$expected_parsed = json_decode( file_get_contents( $parsed_json_filename ), true );

$parser = new Gutenberg_PEG_Parser;
$result = $parser->parse( $html );
$parser = new Gutenberg_PEG_Parser;
$result = $parser->parse( $html );

$this->assertEquals( $expected_parsed, $result );
}
$this->assertEquals( $expected_parsed, $result );
}
}