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

Resolve the vendor/wordpress-autoload.php file on Windows, add PHP 8.1-8.2 support #29

Merged
merged 9 commits into from
Dec 6, 2023
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
18 changes: 13 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
name: Tests

on: [push, pull_request]
on:
push:
branches:
- main
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will also trigger after the PR is merged. Is that intentional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I prefer to always have a status check on the main branch to get a valid status badge.

pull_request:

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [7.4, 8.0, 8.1]
os: [ubuntu-latest, windows-2019]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😮

php: [8.0, 8.1, 8.2, 8.3]
stability: [prefer-lowest, prefer-stable]

name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}
Expand Down Expand Up @@ -48,5 +52,9 @@ jobs:
- name: Install vendor-dir test dependencies
run: cd tests/fixtures/vendor-dir && composer install

- name: Execute tests
run: composer run test
- name: Execute phpcs
if: matrix.os != 'windows-2019'
run: composer run phpcs

- name: Execute phpunit
run: composer run phpunit
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ documented in this file.

## Unreleased

## v1.1.0

### Changed

- Dropped PHP 7.4 support, adding PHP 8.2 and 8.3 support explicitly with testing.
- Added testing against Windows.

### Fixed

- Fixed issue with `wordpress-autoload.php` file not properly loading on Windows.

## v1.0.0

No changes, tagging a stable release.

## v0.8.0

- Automatically translate the `vendor-dir` and set the autoloaded files relative to the root directory of the project.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
],
"require": {
"php": "^7.4.0|^8.0|^8.1",
"php": "^8.0",
"alleyinteractive/wordpress-autoloader": "^1.1.1",
"composer-plugin-api": "^2.0"
},
Expand Down
10 changes: 10 additions & 0 deletions src/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@
*/

$autoloadFiles = [
// Attempt to translate the /vendor/ in the directory path to the vendor directory.
preg_replace('#/vendor/.*$#', '/vendor/wordpress-autoload.php', __DIR__),
preg_replace('/\\\vendor\\\.*$/', '/vendor/wordpress-autoload.php', __DIR__),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like one too many backslashes - shouldn't it be like this?

Suggested change
preg_replace('/\\\vendor\\\.*$/', '/vendor/wordpress-autoload.php', __DIR__),
preg_replace('/\\vendor\\.*$/', '/vendor/wordpress-autoload.php', __DIR__),

Copy link
Member Author

@srtfisher srtfisher Dec 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a regex pro to know but in testing with C:\Users\Sean Fisher\Local Sites\wordpress\app\public\wp-content\vendor\alleyinteractive\composer-wordpress-autoloader\src as the __DIR__:

four slashes: preg_replace('/\\\vendor\\\.*$/', '/vendor/wordpress-autoload.php', __DIR__), -> "C:\Users\Sean Fisher\Local Sites\wordpress\app\public\wp-content/vendor/wordpress-autoload.php

two slashes: preg_replace('/\\vendor\\\.*$/', '/vendor/wordpress-autoload.php', __DIR__), -> C:\Users\Sean Fisher\Local Sites\wordpress\app\public\wp-content\vendor\alleyinteractive\composer-wordpress-autoloader\src

https://onlinephp.io?s=lc8_C8IwEAXw2UK_QwYhKtbu_sFBcHIrbgdyJocGYnNc0ha_vRHRRRfXx-P3eOstX7ksxtaJ2ii9W8IxkkRoCFu1d_FKAodg0KvGJYowBLEsFCMgM3B39s7AwJUJbaI2QU-tDQLoPd1djgRNcj2BCTcOWa4-QIVdCj6gzQtRjF6VRVn0KCfb3XhSFqPcupyE2KOhia4B3jjAYjau9Vzp-pXU3-gi38qN56_p_Bf2tv6mpqsH&v=8.2.13

/shrug


// Assuming this file is located at
// vendor/alleyinteractive/composer-wordpress-autoloader/src/autoload.php,
// hop up a few directories and try to load the file from there.
dirname(__DIR__, 3) . '/wordpress-autoload.php',

// Handle local development of the package where vendor directory is closer
// to the root.
'../../../vendor/wordpress-autoload.php',
'../../vendor/wordpress-autoload.php',
];
Expand Down
4 changes: 4 additions & 0 deletions tests/AutoloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public function autoloaders()

public function testAutoloaderFile()
{
if (DIRECTORY_SEPARATOR === '\\') {
$this->markTestSkipped('Skipping test on Windows');
}

$expected = '9893efd7d77972c681f2693e9d20a975';
$actual = md5(file_get_contents(__DIR__ . '/fixtures/root/vendor/wordpress-autoload.php'));

Expand Down