From 39b7e9261aa6dfdb1ccfd23e33acd12c01f3ea6a Mon Sep 17 00:00:00 2001 From: goldenapples Date: Mon, 26 Oct 2020 10:41:44 -0400 Subject: [PATCH 1/5] Add helper for finding the first readable manifest Adds a helper function, `Asset_Loader\Manifest\get_active_manifest()`, which can be used to retrieve the correct manifest file to use depending on whether the dev server is running or not. --- inc/manifest.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/inc/manifest.php b/inc/manifest.php index b60d7b8..85f2c82 100644 --- a/inc/manifest.php +++ b/inc/manifest.php @@ -9,6 +9,26 @@ use Altis; +/** + * Return the first readable file from an array of manifest paths. + * + * This is a helper which can be used when different manifest files need to be + * read under different conditions: for example, using a dev server manifest + * when the dev server is running, and a production manifest otherwise. + * + * @param string[] Array of potential paths to manifest files. + * @return string|null; + */ +function get_active_manifest( $paths ) { + foreach ( $paths as $path ) { + if ( is_readable( $path ) ) { + return $path; + } + } + + return null; +} + /** * Attempt to load a manifest at the specified path and parse its contents as JSON. * From 55f83ee131451efc5787c8eb5b0ee50c32753334 Mon Sep 17 00:00:00 2001 From: K Adam White Date: Wed, 28 Oct 2020 10:24:55 -0400 Subject: [PATCH 2/5] Add unit tests --- tests/inc/class-test-manifest.php | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/inc/class-test-manifest.php b/tests/inc/class-test-manifest.php index c988371..037a405 100644 --- a/tests/inc/class-test-manifest.php +++ b/tests/inc/class-test-manifest.php @@ -124,4 +124,47 @@ public function test_get_version_in_altis_environment() : void { $this->assertEquals( 'spiffy-altis-deploy-revision', $version, 'Version should fall back to the deployed Altis revision when available' ); } + + /** + * Test get_active_manifest() function. + * + * @dataProvider provide_get_active_manifest_cases + */ + public function test_get_active_manifest( array $manifest_options, ?string $expected, string $message ) : void { + $result = Manifest\get_active_manifest( $manifest_options ); + + $this->assertEquals( $expected, $result, $message ); + } + + /** + * Test cases for get_manifest_resource() utility function. + */ + public function provide_get_active_manifest_cases() : array { + $dev_manifest = dirname( __DIR__ ) . '/fixtures/devserver-asset-manifest.json'; + $prod_manifest = dirname( __DIR__ ) . '/fixtures/prod-asset-manifest.json'; + $invalid_manifest_1 = dirname( __DIR__ ) . '/fixtures/does-not-exist.json'; + $invalid_manifest_2 = dirname( __DIR__ ) . '/fixtures/also-does-not-exist.json'; + return [ + 'first manifest exists' => [ + [ $dev_manifest, $prod_manifest, $invalid_manifest_1, $invalid_manifest_2 ], + $dev_manifest, + 'First valid manifest should be returned', + ], + 'second manifest exists' => [ + [ $invalid_manifest_1, $dev_manifest, $prod_manifest, $invalid_manifest_2 ], + $dev_manifest, + 'Unreadable paths should be skipped', + ], + 'second manifest exists' => [ + [ $invalid_manifest_1, $invalid_manifest_2, $prod_manifest, $dev_manifest ], + $prod_manifest, + 'Multiple unreadable paths should be skipped', + ], + 'no manifest exists' => [ + [ $invalid_manifest_1, $invalid_manifest_2 ], + null, + 'null should be returned if no manifest is readable', + ], + ]; + } } From 7cfd78e04a2a15b1b6c6747ff004e2350e234f6f Mon Sep 17 00:00:00 2001 From: K Adam White Date: Wed, 28 Oct 2020 10:25:22 -0400 Subject: [PATCH 3/5] Pin to Coding Standards 1.1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d721874..8c3d590 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "composer/installers": "~1.0" }, "require-dev": { - "humanmade/coding-standards": "dev-master", + "humanmade/coding-standards": "^1.1.0", "10up/wp_mock": "^0.4.2", "phpunit/phpunit": "^7.5" }, From 10aa8bcc5736f47356594447279411e6fc244036 Mon Sep 17 00:00:00 2001 From: K Adam White Date: Wed, 28 Oct 2020 10:40:44 -0400 Subject: [PATCH 4/5] Fix incompatible ranges in composer.lock --- composer.lock | 179 +++++++++++++++++++++++++++----------------------- 1 file changed, 98 insertions(+), 81 deletions(-) diff --git a/composer.lock b/composer.lock index 9bedcb7..ffa67f7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "47b0003d6c9c4011059183ab4395f221", + "content-hash": "cac601ae6a9787072b510ca3ce0b926a", "packages": [ { "name": "composer/installers", @@ -268,22 +268,22 @@ }, { "name": "dealerdirect/phpcodesniffer-composer-installer", - "version": "v0.6.2", + "version": "v0.7.0", "source": { "type": "git", "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", - "reference": "8001af8eb107fbfcedc31a8b51e20b07d85b457a" + "reference": "e8d808670b8f882188368faaf1144448c169c0b7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/8001af8eb107fbfcedc31a8b51e20b07d85b457a", - "reference": "8001af8eb107fbfcedc31a8b51e20b07d85b457a", + "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/e8d808670b8f882188368faaf1144448c169c0b7", + "reference": "e8d808670b8f882188368faaf1144448c169c0b7", "shasum": "" }, "require": { - "composer-plugin-api": "^1.0", - "php": "^5.3|^7", - "squizlabs/php_codesniffer": "^2|^3" + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2 || ^3 || 4.0.x-dev" }, "require-dev": { "composer/composer": "*", @@ -330,7 +330,7 @@ "stylecheck", "tests" ], - "time": "2020-01-29T20:22:20+00:00" + "time": "2020-06-25T14:57:39+00:00" }, { "name": "doctrine/instantiator", @@ -436,20 +436,20 @@ }, { "name": "hamcrest/hamcrest-php", - "version": "v2.0.0", + "version": "v2.0.1", "source": { "type": "git", "url": "https://github.com/hamcrest/hamcrest-php.git", - "reference": "776503d3a8e85d4f9a1148614f95b7a608b046ad" + "reference": "8c3d0a3f6af734494ad8f6fbbee0ba92422859f3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/776503d3a8e85d4f9a1148614f95b7a608b046ad", - "reference": "776503d3a8e85d4f9a1148614f95b7a608b046ad", + "url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/8c3d0a3f6af734494ad8f6fbbee0ba92422859f3", + "reference": "8c3d0a3f6af734494ad8f6fbbee0ba92422859f3", "shasum": "" }, "require": { - "php": "^5.3|^7.0" + "php": "^5.3|^7.0|^8.0" }, "replace": { "cordoval/hamcrest-php": "*", @@ -457,14 +457,13 @@ "kodova/hamcrest-php": "*" }, "require-dev": { - "phpunit/php-file-iterator": "1.3.3", - "phpunit/phpunit": "~4.0", - "satooshi/php-coveralls": "^1.0" + "phpunit/php-file-iterator": "^1.4 || ^2.0", + "phpunit/phpunit": "^4.8.36 || ^5.7 || ^6.5 || ^7.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "2.1-dev" } }, "autoload": { @@ -474,31 +473,31 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "BSD" + "BSD-3-Clause" ], "description": "This is the PHP port of Hamcrest Matchers", "keywords": [ "test" ], - "time": "2016-01-20T08:20:44+00:00" + "time": "2020-07-09T08:09:16+00:00" }, { "name": "humanmade/coding-standards", - "version": "dev-master", + "version": "v1.1.1", "source": { "type": "git", "url": "https://github.com/humanmade/coding-standards.git", - "reference": "94d9874e417056c76caaecea7ca2566f44724a0d" + "reference": "841d51064c492b8c9ec5210bbfff38f63cee3243" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/humanmade/coding-standards/zipball/94d9874e417056c76caaecea7ca2566f44724a0d", - "reference": "94d9874e417056c76caaecea7ca2566f44724a0d", + "url": "https://api.github.com/repos/humanmade/coding-standards/zipball/841d51064c492b8c9ec5210bbfff38f63cee3243", + "reference": "841d51064c492b8c9ec5210bbfff38f63cee3243", "shasum": "" }, "require": { "automattic/vipwpcs": "2.0.0", - "dealerdirect/phpcodesniffer-composer-installer": "^0.6.0", + "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", "fig-r/psr2r-sniffer": "^0.5.0", "php": ">=7.1", "phpcompatibility/phpcompatibility-wp": "^2.0.0", @@ -513,30 +512,30 @@ "license": [ "GPL-2.0-or-later" ], - "description": "Human Made coding standards", - "time": "2020-07-08T19:36:21+00:00" + "description": "Human Made Coding Standards", + "time": "2020-10-27T14:25:16+00:00" }, { "name": "mockery/mockery", - "version": "1.3.1", + "version": "1.3.3", "source": { "type": "git", "url": "https://github.com/mockery/mockery.git", - "reference": "f69bbde7d7a75d6b2862d9ca8fab1cd28014b4be" + "reference": "60fa2f67f6e4d3634bb4a45ff3171fa52215800d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/mockery/mockery/zipball/f69bbde7d7a75d6b2862d9ca8fab1cd28014b4be", - "reference": "f69bbde7d7a75d6b2862d9ca8fab1cd28014b4be", + "url": "https://api.github.com/repos/mockery/mockery/zipball/60fa2f67f6e4d3634bb4a45ff3171fa52215800d", + "reference": "60fa2f67f6e4d3634bb4a45ff3171fa52215800d", "shasum": "" }, "require": { - "hamcrest/hamcrest-php": "~2.0", + "hamcrest/hamcrest-php": "^2.0.1", "lib-pcre": ">=7.0", "php": ">=5.6.0" }, "require-dev": { - "phpunit/phpunit": "~5.7.10|~6.5|~7.0|~8.0" + "phpunit/phpunit": "^5.7.10|^6.5|^7.5|^8.5|^9.3" }, "type": "library", "extra": { @@ -579,7 +578,7 @@ "test double", "testing" ], - "time": "2019-12-26T09:49:15+00:00" + "time": "2020-08-11T18:10:21+00:00" }, { "name": "myclabs/deep-copy", @@ -942,28 +941,27 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "5.1.0", + "version": "5.2.2", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e" + "reference": "069a785b2141f5bcf49f3e353548dc1cce6df556" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e", - "reference": "cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/069a785b2141f5bcf49f3e353548dc1cce6df556", + "reference": "069a785b2141f5bcf49f3e353548dc1cce6df556", "shasum": "" }, "require": { - "ext-filter": "^7.1", - "php": "^7.2", - "phpdocumentor/reflection-common": "^2.0", - "phpdocumentor/type-resolver": "^1.0", - "webmozart/assert": "^1" + "ext-filter": "*", + "php": "^7.2 || ^8.0", + "phpdocumentor/reflection-common": "^2.2", + "phpdocumentor/type-resolver": "^1.3", + "webmozart/assert": "^1.9.1" }, "require-dev": { - "doctrine/instantiator": "^1", - "mockery/mockery": "^1" + "mockery/mockery": "~1.3.2" }, "type": "library", "extra": { @@ -991,20 +989,20 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2020-02-22T12:28:44+00:00" + "time": "2020-09-03T19:13:55+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "1.3.0", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "e878a14a65245fbe78f8080eba03b47c3b705651" + "reference": "6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/e878a14a65245fbe78f8080eba03b47c3b705651", - "reference": "e878a14a65245fbe78f8080eba03b47c3b705651", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0", + "reference": "6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0", "shasum": "" }, "require": { @@ -1036,32 +1034,32 @@ } ], "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", - "time": "2020-06-27T10:12:23+00:00" + "time": "2020-09-17T18:55:26+00:00" }, { "name": "phpspec/prophecy", - "version": "1.11.1", + "version": "1.12.1", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "b20034be5efcdab4fb60ca3a29cba2949aead160" + "reference": "8ce87516be71aae9b956f81906aaf0338e0d8a2d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/b20034be5efcdab4fb60ca3a29cba2949aead160", - "reference": "b20034be5efcdab4fb60ca3a29cba2949aead160", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/8ce87516be71aae9b956f81906aaf0338e0d8a2d", + "reference": "8ce87516be71aae9b956f81906aaf0338e0d8a2d", "shasum": "" }, "require": { "doctrine/instantiator": "^1.2", - "php": "^7.2", - "phpdocumentor/reflection-docblock": "^5.0", + "php": "^7.2 || ~8.0, <8.1", + "phpdocumentor/reflection-docblock": "^5.2", "sebastian/comparator": "^3.0 || ^4.0", "sebastian/recursion-context": "^3.0 || ^4.0" }, "require-dev": { "phpspec/phpspec": "^6.0", - "phpunit/phpunit": "^8.0" + "phpunit/phpunit": "^8.0 || ^9.0 <9.3" }, "type": "library", "extra": { @@ -1099,7 +1097,7 @@ "spy", "stub" ], - "time": "2020-07-08T12:44:21+00:00" + "time": "2020-09-29T09:10:42+00:00" }, { "name": "phpunit/php-code-coverage", @@ -2005,16 +2003,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.5.5", + "version": "3.5.8", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "73e2e7f57d958e7228fce50dc0c61f58f017f9f6" + "reference": "9d583721a7157ee997f235f327de038e7ea6dac4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/73e2e7f57d958e7228fce50dc0c61f58f017f9f6", - "reference": "73e2e7f57d958e7228fce50dc0c61f58f017f9f6", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/9d583721a7157ee997f235f327de038e7ea6dac4", + "reference": "9d583721a7157ee997f235f327de038e7ea6dac4", "shasum": "" }, "require": { @@ -2052,24 +2050,24 @@ "phpcs", "standards" ], - "time": "2020-04-17T01:09:41+00:00" + "time": "2020-10-23T02:01:07+00:00" }, { "name": "symfony/polyfill-ctype", - "version": "v1.17.1", + "version": "v1.20.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "2edd75b8b35d62fd3eeabba73b26b8f1f60ce13d" + "reference": "f4ba089a5b6366e453971d3aad5fe8e897b37f41" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/2edd75b8b35d62fd3eeabba73b26b8f1f60ce13d", - "reference": "2edd75b8b35d62fd3eeabba73b26b8f1f60ce13d", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/f4ba089a5b6366e453971d3aad5fe8e897b37f41", + "reference": "f4ba089a5b6366e453971d3aad5fe8e897b37f41", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": ">=7.1" }, "suggest": { "ext-ctype": "For best performance" @@ -2077,7 +2075,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.17-dev" + "dev-main": "1.20-dev" }, "thanks": { "name": "symfony/polyfill", @@ -2114,27 +2112,41 @@ "polyfill", "portable" ], - "time": "2020-06-06T08:46:27+00:00" + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-10-23T14:02:19+00:00" }, { "name": "theseer/tokenizer", - "version": "1.1.3", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/theseer/tokenizer.git", - "reference": "11336f6f84e16a720dae9d8e6ed5019efa85a0f9" + "reference": "75a63c33a8577608444246075ea0af0d052e452a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/11336f6f84e16a720dae9d8e6ed5019efa85a0f9", - "reference": "11336f6f84e16a720dae9d8e6ed5019efa85a0f9", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/75a63c33a8577608444246075ea0af0d052e452a", + "reference": "75a63c33a8577608444246075ea0af0d052e452a", "shasum": "" }, "require": { "ext-dom": "*", "ext-tokenizer": "*", "ext-xmlwriter": "*", - "php": "^7.0" + "php": "^7.2 || ^8.0" }, "type": "library", "autoload": { @@ -2154,7 +2166,13 @@ } ], "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", - "time": "2019-06-13T22:48:21+00:00" + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2020-07-12T23:59:07+00:00" }, { "name": "webmozart/assert", @@ -2253,11 +2271,10 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "humanmade/coding-standards": 20 - }, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": [], - "platform-dev": [] + "platform-dev": [], + "plugin-api-version": "1.1.0" } From db909b29ca4e4cb689c343453381919dcc122d21 Mon Sep 17 00:00:00 2001 From: K Adam White Date: Wed, 28 Oct 2020 11:03:09 -0400 Subject: [PATCH 5/5] Fix PHPDoc argument annotations for get_active_manifest --- inc/manifest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/inc/manifest.php b/inc/manifest.php index 85f2c82..b6d303a 100644 --- a/inc/manifest.php +++ b/inc/manifest.php @@ -16,10 +16,10 @@ * read under different conditions: for example, using a dev server manifest * when the dev server is running, and a production manifest otherwise. * - * @param string[] Array of potential paths to manifest files. - * @return string|null; + * @param string[] $paths Array of potential paths to manifest files. + * @return string|null The first readable manifest path, or null. */ -function get_active_manifest( $paths ) { +function get_active_manifest( array $paths ) : ?string { foreach ( $paths as $path ) { if ( is_readable( $path ) ) { return $path;