Skip to content

Commit

Permalink
Remove RUN_PARSER_TESTS flag from PHPUnit tests (#1605)
Browse files Browse the repository at this point in the history
  • Loading branch information
nylen authored Jul 1, 2017
1 parent 7804758 commit c4d7836
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 49 deletions.
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 );
}
}

0 comments on commit c4d7836

Please sign in to comment.