Skip to content

Commit

Permalink
Merge pull request #149 from coenjacobs/dependency-update
Browse files Browse the repository at this point in the history
Dependency update and bump to PHP requirement 8.0 and higher
  • Loading branch information
coenjacobs authored Jul 23, 2024
2 parents 2fb827d + e1e529c commit 175fbdc
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 47 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.3', '7.4', '8.0', '8.1']
php: ['8.0', '8.1', '8.2', '8.3']
name: PHP ${{ matrix.php }} tests
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -56,7 +56,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
- name: Debugging
run: |
php --version
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Install PHP
uses: shivammathur/[email protected]
with:
php-version: 7.3
php-version: 8.0

- name: Install dependencies
run: composer install --no-dev --prefer-dist --no-suggest --no-progress
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ vendor/

.DS_Store
composer.lock

/.phpunit.cache
.phpunit.result.cache
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Mozart [![Latest Stable Version](https://poser.pugx.org/coenjacobs/mozart/v/stable.svg)](https://packagist.org/packages/coenjacobs/mozart) [![License](https://poser.pugx.org/coenjacobs/mozart/license.svg)](https://packagist.org/packages/coenjacobs/mozart) [![Total Downloads](https://poser.pugx.org/coenjacobs/mozart/downloads)](//packagist.org/packages/coenjacobs/mozart) [![Docker Image Pulls](https://img.shields.io/docker/pulls/coenjacobs/mozart.svg)](https://hub.docker.com/r/coenjacobs/mozart)
Composes all dependencies as a package inside a WordPress plugin. Load packages through Composer and have them wrapped inside your own namespace. Gone are the days when plugins could load conflicting versions of the same package, resulting in hard to reproduce bugs.

This package requires PHP 7.3 or higher in order to run the tool. You can use the resulting files as a bundle, requiring any PHP version you like, even PHP 5.2.
This package requires PHP 8.0 or higher in order to run the tool. You can use the resulting files as a bundle, requiring any PHP version you like, even PHP 5.2.

**Warning:** This package is very experimental and breaking changes are very likely until version 1.0.0 is tagged. Use with caution, always wear a helmet when using this in production environments.

Expand Down Expand Up @@ -42,7 +42,7 @@ php mozart.phar compose
To install Mozart and its dependencies, without conflicting with the dependencies of your project, it is recommended that you install Mozart as a global package, if you choose to install Mozart via Composer.

#### Global package
Using the `global` command when installing Mozart, it will be installed as a system wide package:
Using the `global` command when installing Mozart, it will be installed as a system wide package:

```
composer global require coenjacobs/mozart
Expand Down Expand Up @@ -113,7 +113,7 @@ The following configuration is optional:
- `excluded_packages` is an optional array that defines the packages to be excluded from the processing performed by Mozart. This is useful if some of the packages in the `packages` array define dependent packages whose namespaces you want to keep unchanged. The array requires the slugs of the packages, as in the case of the `packages` array.
- `override_autoload` a dictionary, keyed with the package names, of autoload settings to replace those in the original packages' `composer.json` `autoload` property.

After Composer has loaded the packages as defined in your `composer.json` file, you can now run `mozart compose` and Mozart will bundle your packages according to the above configuration. It is recommended to dump the autoloader after Mozart has finished running, in case there are new classes or namespaces generated that aren't included in the autoloader yet.
After Composer has loaded the packages as defined in your `composer.json` file, you can now run `mozart compose` and Mozart will bundle your packages according to the above configuration. It is recommended to dump the autoloader after Mozart has finished running, in case there are new classes or namespaces generated that aren't included in the autoloader yet.

## Scripts
Mozart is designed to install and be forgotten about. Using Composer scripts, the Mozart script can be run as soon as Composer either installs a new package, or updates an already installed one. This ensures that the packages you want to bundle, are always bundled in the latest installed version, automatically. These scripts also offer you the possibility to script dumping the autoloader, after Mozart is finished running:
Expand Down
23 changes: 13 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
"prefer-stable": true,
"license": "MIT",
"require": {
"php": "^7.3|^8.0",
"symfony/console": "^4|^5",
"symfony/finder": "^4|^5",
"league/flysystem": "^1.0"
"php": "^8.0"
},
"autoload": {
"psr-4": {
Expand All @@ -25,15 +22,21 @@
"config": {
"allow-plugins": {
"phpstan/extension-installer": true
},
"platform": {
"php": "8.0"
}
},
"require-dev": {
"phpunit/phpunit": "^8.5",
"squizlabs/php_codesniffer": "^3.5",
"mheap/phpunit-github-actions-printer": "^1.4",
"phpstan/phpstan": "^1.8",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/extension-installer": "^1.2"
"phpunit/phpunit": "^9.6",
"squizlabs/php_codesniffer": "^3.10",
"mheap/phpunit-github-actions-printer": "^1.5",
"phpstan/phpstan": "^1.11",
"phpstan/phpstan-deprecation-rules": "^1.2",
"phpstan/extension-installer": "^1.4",
"league/flysystem": "^2.5",
"symfony/console": "^5.4",
"symfony/finder": "^5.4"
},
"scripts": {
"lint": [
Expand Down
13 changes: 7 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.2/phpunit.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
>
<testsuites>
<testsuite name="all">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
</phpunit>
2 changes: 1 addition & 1 deletion src/Console/Commands/Compose.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function configure()
$this->setHelp('');
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$workingDir = getcwd();
$this->workingDir = $workingDir;
Expand Down
31 changes: 18 additions & 13 deletions src/Mover.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use CoenJacobs\Mozart\Composer\Autoload\Psr0;
use CoenJacobs\Mozart\Composer\Autoload\Psr4;
use CoenJacobs\Mozart\Composer\Package;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Local\LocalFilesystemAdapter;
use League\Flysystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
Expand Down Expand Up @@ -36,7 +36,12 @@ public function __construct($workingDir, $config)
$this->targetDir = $config->dep_directory;
$this->config = $config;

$this->filesystem = new Filesystem(new Local($this->workingDir));
$adapter = new LocalFilesystemAdapter(
$this->workingDir
);

// The FilesystemOperator
$this->filesystem = new Filesystem($adapter);
}

/**
Expand All @@ -48,9 +53,9 @@ public function __construct($workingDir, $config)
*/
public function deleteTargetDirs($packages): void
{
$this->filesystem->createDir($this->config->dep_directory);
$this->filesystem->createDirectory($this->config->dep_directory);

$this->filesystem->createDir($this->config->classmap_directory);
$this->filesystem->createDirectory($this->config->classmap_directory);

foreach ($packages as $package) {
$this->deleteDepTargetDirs($package);
Expand All @@ -76,12 +81,12 @@ private function deleteDepTargetDirs($package): void
case Psr4::class:
$outputDir = $this->config->dep_directory . $packageAutoloader->namespace;
$outputDir = str_replace('\\', DIRECTORY_SEPARATOR, $outputDir);
$this->filesystem->deleteDir($outputDir);
$this->filesystem->deleteDirectory($outputDir);
break;
case Classmap::class:
$outputDir = $this->config->classmap_directory . $package->config->name;
$outputDir = str_replace('\\', DIRECTORY_SEPARATOR, $outputDir);
$this->filesystem->deleteDir($outputDir);
$this->filesystem->deleteDirectory($outputDir);
break;
}
}
Expand All @@ -93,15 +98,15 @@ private function deleteDepTargetDirs($package): void

public function deleteEmptyDirs(): void
{
if (count($this->filesystem->listContents($this->config->dep_directory, true)) === 0) {
$this->filesystem->deleteDir($this->config->dep_directory);
if (count($this->filesystem->listContents($this->config->dep_directory, true)->toArray()) === 0) {
$this->filesystem->deleteDirectory($this->config->dep_directory);
}

if (count($this->filesystem->listContents($this->config->classmap_directory, true)) === 0) {
$this->filesystem->deleteDir($this->config->classmap_directory);
if (count($this->filesystem->listContents($this->config->classmap_directory, true)->toArray()) === 0) {
$this->filesystem->deleteDirectory($this->config->classmap_directory);
}
}

/**
* @return void
*/
Expand Down Expand Up @@ -224,13 +229,13 @@ protected function deletePackageVendorDirectories(): void
continue;
}

$this->filesystem->deleteDir($packageDir);
$this->filesystem->deleteDirectory($packageDir);

//Delete parent directory too if it became empty
//(because that package was the only one from that vendor)
$parentDir = dirname($packageDir);
if ($this->dirIsEmpty($parentDir)) {
$this->filesystem->deleteDir($parentDir);
$this->filesystem->deleteDirectory($parentDir);
}
}
}
Expand Down
23 changes: 16 additions & 7 deletions src/Replacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use CoenJacobs\Mozart\Composer\Package;
use CoenJacobs\Mozart\Replace\ClassmapReplacer;
use CoenJacobs\Mozart\Replace\NamespaceReplacer;
use League\Flysystem\Adapter\Local;
use League\Flysystem\FileNotFoundException;
use League\Flysystem\Local\LocalFilesystemAdapter;
use League\Flysystem\UnableToReadFile;
use League\Flysystem\Filesystem;
use Symfony\Component\Finder\Finder;

Expand All @@ -36,7 +36,12 @@ public function __construct($workingDir, $config)
$this->targetDir = $config->dep_directory;
$this->config = $config;

$this->filesystem = new Filesystem(new Local($this->workingDir));
$adapter = new LocalFilesystemAdapter(
$this->workingDir
);

// The FilesystemOperator
$this->filesystem = new Filesystem($adapter);
}

public function replacePackage(Package $package): void
Expand All @@ -57,7 +62,7 @@ public function replaceInFile($targetFile, Autoloader $autoloader): void
$targetFile = str_replace($this->workingDir, '', $targetFile);
try {
$contents = $this->filesystem->read($targetFile);
} catch (FileNotFoundException $e) {
} catch (UnableToReadFile $e) {
return;
}

Expand All @@ -80,7 +85,7 @@ public function replaceInFile($targetFile, Autoloader $autoloader): void
$this->replacedClasses = array_merge($this->replacedClasses, $replacer->replacedClasses);
}

$this->filesystem->put($targetFile, $contents);
$this->filesystem->write($targetFile, $contents);
}

/**
Expand Down Expand Up @@ -136,7 +141,7 @@ public function replaceParentClassesInDirectory(string $directory): void
if ('.php' == substr($targetFile, -4, 4)) {
try {
$contents = $this->filesystem->read($targetFile);
} catch (FileNotFoundException $e) {
} catch (UnableToReadFile $e) {
continue;
}

Expand All @@ -157,7 +162,11 @@ function ($matches) use ($replacement) {
);
}

$this->filesystem->put($targetFile, $contents);
if (empty($contents)) {
continue;
}

$this->filesystem->write($targetFile, $contents);
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions tests/Console/Commands/ComposeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use CoenJacobs\Mozart\Console\Commands\Compose;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand Down Expand Up @@ -35,6 +36,7 @@ public function setUp(): void
*
* @test
*/
#[Test]
public function it_fails_gracefully_when_composer_json_absent(): void
{

Expand All @@ -61,6 +63,7 @@ public function __construct($inputInterfaceMock, $outputInterfaceMock)
*
* @test
*/
#[Test]
public function it_handles_malformed_json_with_grace(): void
{

Expand Down Expand Up @@ -91,6 +94,7 @@ public function __construct($inputInterfaceMock, $outputInterfaceMock)
*
* @test
*/
#[Test]
public function it_handles_absent_extra_config_with_grace(): void
{

Expand Down Expand Up @@ -122,6 +126,7 @@ public function __construct($inputInterfaceMock, $outputInterfaceMock)
*
* @test
*/
#[Test]
public function it_handles_malformed_extra_config_with_grace(): void
{

Expand Down Expand Up @@ -152,6 +157,7 @@ public function __construct($inputInterfaceMock, $outputInterfaceMock)
*
* @test
*/
#[Test]
public function it_handles_absent_mozart_config_with_grace(): void
{

Expand Down Expand Up @@ -184,6 +190,7 @@ public function __construct($inputInterfaceMock, $outputInterfaceMock)
*
* @test
*/
#[Test]
public function it_handles_malformed_mozart_config__with_grace(): void
{

Expand Down
9 changes: 7 additions & 2 deletions tests/MoverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use CoenJacobs\Mozart\Console\Commands\Compose;
use CoenJacobs\Mozart\Mover;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand Down Expand Up @@ -61,6 +62,7 @@ public function setUp(): void
*
* @test
*/
#[Test]
public function it_creates_absent_dirs(): void
{
$mover = new Mover($this->testsWorkingDir, $this->config);
Expand All @@ -80,6 +82,7 @@ public function it_creates_absent_dirs(): void
*
* @test
*/
#[Test]
public function it_is_unpertrubed_by_existing_dirs(): void
{
$mover = new Mover($this->testsWorkingDir, $this->config);
Expand Down Expand Up @@ -111,6 +114,7 @@ public function it_is_unpertrubed_by_existing_dirs(): void
*
* @test
*/
#[Test]
public function it_deletes_subdirs_for_packages_about_to_be_moved(): void
{
$mover = new Mover($this->testsWorkingDir, $this->config);
Expand All @@ -137,8 +141,8 @@ public function it_deletes_subdirs_for_packages_about_to_be_moved(): void

$mover->deleteTargetDirs($packages);

$this->assertDirectoryNotExists($this->testsWorkingDir . $this->config->dep_directory . 'Pimple');
$this->assertDirectoryNotExists($this->testsWorkingDir . $this->config->dep_directory . 'ezyang');
$this->assertDirectoryDoesNotExist($this->testsWorkingDir . $this->config->dep_directory . 'Pimple');
$this->assertDirectoryDoesNotExist($this->testsWorkingDir . $this->config->dep_directory . 'ezyang');
}

/**
Expand Down Expand Up @@ -177,6 +181,7 @@ public function it_deletes_subdirs_for_packages_about_to_be_moved(): void
*
* @test
*/
#[Test]
public function it_moves_each_file_once_per_namespace()
{

Expand Down
Loading

0 comments on commit 175fbdc

Please sign in to comment.