From 7f7ee147a8b12fe57e4db3090f864d3b76004013 Mon Sep 17 00:00:00 2001 From: James Nylen Date: Fri, 30 Jun 2017 15:15:46 +0200 Subject: [PATCH] Remove `RUN_PARSER_TESTS` flag from PHPUnit tests --- .travis.yml | 2 +- phpunit/class-parsing-test.php | 89 ++++++++++++++++------------------ 2 files changed, 42 insertions(+), 49 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7d1a864c1a2d07..4e162f598ffcda 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 - | diff --git a/phpunit/class-parsing-test.php b/phpunit/class-parsing-test.php index 6b2f48209a3ff1..7c5be8c014647c 100644 --- a/phpunit/class-parsing-test.php +++ b/phpunit/class-parsing-test.php @@ -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 ); } }