Skip to content
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
7 changes: 7 additions & 0 deletions docs/releases/0.1.5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# QA 0.1.5

`static-analysis` and `tests` no longer skip a project whose SymPress packages
Composer installs outside `vendor/`, for example WordPress plugins and MU plugins
placed by `composer/installers` paths. A required `sympress/*` package now counts
as present when it is in `vendor/sympress/` or listed in
`vendor/composer/installed.json`.
39 changes: 38 additions & 1 deletion src/Support/ConfigDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function missingLocalSymPressDependencies(string $packageDir): array
$this->stringKeyArray($composer['require-dev'] ?? null),
);
$missing = [];
$installed = $this->installedPackageNames($packageDir);

foreach (array_keys($requires) as $packageName) {
if (!str_starts_with($packageName, 'sympress/')) {
Expand All @@ -81,7 +82,7 @@ public function missingLocalSymPressDependencies(string $packageDir): array
}

$vendorName = substr($packageName, strlen('sympress/'));
if (is_dir($packageDir . '/vendor/sympress/' . $vendorName)) {
if (is_dir($packageDir . '/vendor/sympress/' . $vendorName) || in_array($packageName, $installed, true)) {
continue;
}

Expand All @@ -91,6 +92,42 @@ public function missingLocalSymPressDependencies(string $packageDir): array
return $missing;
}

/**
* Packages Composer installed for this package, including those placed outside vendor/ by installer paths
* (WordPress plugins and MU plugins).
*
* @return list<string>
*/
private function installedPackageNames(string $packageDir): array
{
$installedFile = $packageDir . '/vendor/composer/installed.json';
if (!is_readable($installedFile)) {
return [];
}

try {
$installed = json_decode((string) file_get_contents($installedFile), true, 512, JSON_THROW_ON_ERROR);
} catch (JsonException) {
return [];
}

$packages = is_array($installed) ? ($installed['packages'] ?? []) : [];
if (!is_array($packages)) {
return [];
}

$names = [];
foreach ($packages as $package) {
if (!is_array($package) || !is_string($package['name'] ?? null)) {
continue;
}

$names[] = $package['name'];
}

return $names;
}

/** @return array<string, mixed> */
private function stringKeyArray(mixed $value): array
{
Expand Down
23 changes: 23 additions & 0 deletions tests/Unit/Support/ConfigDiscoveryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,29 @@ public function testMissingLocalSymPressDependenciesIgnoresQaAndCodingStandards(
self::assertSame(['sympress/kernel'], $missing);
}

public function testMissingLocalSymPressDependenciesAcceptsPackagesInstalledOutsideVendor(): void
{
file_put_contents($this->workspace . '/composer.json', json_encode([
'require' => [
'sympress/kernel' => '^1.1',
'sympress/profiler' => '^1.4',
'sympress/mailer' => '^0.1',
],
], JSON_THROW_ON_ERROR));
self::assertTrue(mkdir($this->workspace . '/vendor/sympress/kernel', 0777, true));
self::assertTrue(mkdir($this->workspace . '/vendor/composer', 0777, true));
file_put_contents($this->workspace . '/vendor/composer/installed.json', json_encode([
'packages' => [
['name' => 'sympress/kernel', 'install-path' => '../sympress/kernel'],
['name' => 'sympress/profiler', 'install-path' => '../../public/wp-content/mu-plugins/profiler'],
],
], JSON_THROW_ON_ERROR));

$missing = (new ConfigDiscovery())->missingLocalSymPressDependencies($this->workspace);

self::assertSame(['sympress/mailer'], $missing);
}

private function removeDirectory(string $directory): void
{
if (!is_dir($directory)) {
Expand Down
Loading