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
40 changes: 9 additions & 31 deletions inc/container.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@
use Syde\WpPhpUnitIntegration\Package\PackageComposerJsonReader;
use Syde\WpPhpUnitIntegration\Package\PackageType;
use Syde\WpPhpUnitIntegration\Package\PackageTypeDetector;
use Syde\WpPhpUnitIntegration\Path\Finder\CachedLocalDependencyPathFinder;
use Syde\WpPhpUnitIntegration\Path\Finder\CachedLocalDependencyPathFinderKey;
use Syde\WpPhpUnitIntegration\Path\Finder\LocalDependencyPathFinder;
use Syde\WpPhpUnitIntegration\Path\Finder\SqliteDatabaseIntegrationPluginFinder;
use Syde\WpPhpUnitIntegration\Path\Finder\WordPressPathFinder;
use Syde\WpPhpUnitIntegration\Path\Finder\WpCliPathFinder;
use Syde\WpPhpUnitIntegration\Path\ComposerPackagePath;
use Syde\WpPhpUnitIntegration\Path\LocalDependencyPath;
use Syde\WpPhpUnitIntegration\Path\LocalDependencyPathNormalizer;
use Syde\WpPhpUnitIntegration\Path\PackageRootPath;
use Syde\WpPhpUnitIntegration\Path\SqliteDatabaseIntegrationPluginPath;
use Syde\WpPhpUnitIntegration\Path\WordPressPath;
use Syde\WpPhpUnitIntegration\Path\WordPressPathFinder;
use Syde\WpPhpUnitIntegration\Path\WpCliPath;
use Syde\WpPhpUnitIntegration\PhpProcessIdProvider;
use Syde\WpPhpUnitIntegration\ShutdownFunctionRegisterer;
Expand Down Expand Up @@ -60,45 +56,27 @@
PackageTypeDetector::class => static fn (ContainerInterface $container): PackageTypeDetector => new PackageTypeDetector(
$container->get(PackageComposerJsonReader::class),
),
// /src/Path/Finder/
CachedLocalDependencyPathFinderKey::class => static fn (): CachedLocalDependencyPathFinderKey => new CachedLocalDependencyPathFinderKey(),
SqliteDatabaseIntegrationPluginFinder::class => static fn (ContainerInterface $container): LocalDependencyPathFinder => new CachedLocalDependencyPathFinder(
new SqliteDatabaseIntegrationPluginFinder(
$container->get(PackageRootPath::class),
),
$container->get(CachedLocalDependencyPathFinderKey::class),
$container->get(EnvVar::class),
),
WordPressPathFinder::class => static fn (ContainerInterface $container): LocalDependencyPathFinder => new CachedLocalDependencyPathFinder(
new WordPressPathFinder(
$container->get(PackageRootPath::class),
),
$container->get(CachedLocalDependencyPathFinderKey::class),
$container->get(EnvVar::class),
),
WpCliPathFinder::class => static fn (ContainerInterface $container): LocalDependencyPathFinder => new CachedLocalDependencyPathFinder(
new WpCliPathFinder(
$container->get(PackageRootPath::class),
),
$container->get(CachedLocalDependencyPathFinderKey::class),
$container->get(EnvVar::class),
),
// /src/Path/
ComposerPackagePath::class => static fn (): ComposerPackagePath => new ComposerPackagePath(),
LocalDependencyPathNormalizer::class => static fn (): LocalDependencyPathNormalizer => new LocalDependencyPathNormalizer(),
PackageRootPath::class => static fn (ContainerInterface $container): LocalDependencyPath => new PackageRootPath(
$packageRootPath,
$container->get(LocalDependencyPathNormalizer::class),
),
SqliteDatabaseIntegrationPluginPath::class => static fn (ContainerInterface $container): LocalDependencyPath => new SqliteDatabaseIntegrationPluginPath(
$container->get(SqliteDatabaseIntegrationPluginFinder::class),
$container->get(ComposerPackagePath::class),
$container->get(LocalDependencyPathNormalizer::class),
),
WordPressPath::class => static fn (ContainerInterface $container): LocalDependencyPath => new WordPressPath(
$container->get(ComposerPackagePath::class),
$container->get(WordPressPathFinder::class),
$container->get(LocalDependencyPathNormalizer::class),
),
WordPressPathFinder::class => static fn (ContainerInterface $container): WordPressPathFinder => new WordPressPathFinder(
$container->get(PackageRootPath::class),
),
WpCliPath::class => static fn (ContainerInterface $container): LocalDependencyPath => new WpCliPath(
$container->get(WpCliPathFinder::class),
$container->get(ComposerPackagePath::class),
$container->get(LocalDependencyPathNormalizer::class),
),
// /src/Task/Bundle/
Expand Down
33 changes: 33 additions & 0 deletions src/Path/ComposerPackagePath.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Syde\WpPhpUnitIntegration\Path;

use Composer\InstalledVersions;
use Exception;

class ComposerPackagePath
{
/**
* @throws Exception
*/
public function installPath(string $package): string
{
$installPath = InstalledVersions::getInstallPath($package);

if ($installPath === null) {
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
throw new Exception("Package $package is not installed.");
}

$installRealPath = realpath($installPath);

if ($installRealPath === false) {
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
throw new Exception("Can't determine real path of $package.");
}

return $installRealPath;
}
}
27 changes: 0 additions & 27 deletions src/Path/DiscoveredPath.php

This file was deleted.

33 changes: 0 additions & 33 deletions src/Path/Finder/CachedLocalDependencyPathFinder.php

This file was deleted.

19 changes: 0 additions & 19 deletions src/Path/Finder/CachedLocalDependencyPathFinderKey.php

This file was deleted.

15 changes: 0 additions & 15 deletions src/Path/Finder/LocalDependencyPathFinder.php

This file was deleted.

39 changes: 0 additions & 39 deletions src/Path/Finder/SqliteDatabaseIntegrationPluginFinder.php

This file was deleted.

49 changes: 0 additions & 49 deletions src/Path/Finder/WpCliPathFinder.php

This file was deleted.

5 changes: 5 additions & 0 deletions src/Path/LocalDependencyPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

namespace Syde\WpPhpUnitIntegration\Path;

use Exception;

interface LocalDependencyPath
{
/**
* @throws Exception
*/
public function path(): string;
}
16 changes: 15 additions & 1 deletion src/Path/SqliteDatabaseIntegrationPluginPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@

namespace Syde\WpPhpUnitIntegration\Path;

readonly class SqliteDatabaseIntegrationPluginPath extends DiscoveredPath
readonly class SqliteDatabaseIntegrationPluginPath implements LocalDependencyPath
{
private const PACKAGE_NAME = 'wpackagist-plugin/sqlite-database-integration';

public function __construct(
private ComposerPackagePath $composerPackagePath,
private LocalDependencyPathNormalizer $localDependencyPathNormalizer,
) {
}

public function path(): string
{
return $this->localDependencyPathNormalizer->normalize(
$this->composerPackagePath->installPath(self::PACKAGE_NAME),
);
}
}
24 changes: 23 additions & 1 deletion src/Path/WordPressPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@

namespace Syde\WpPhpUnitIntegration\Path;

readonly class WordPressPath extends DiscoveredPath
use Throwable;

readonly class WordPressPath implements LocalDependencyPath
{
// The composer.json file requires the roots/wordpress meta-package, which in turn requires the no-content package that contains the WordPress files.
private const PACKAGE_NAME = 'roots/wordpress-no-content';

public function __construct(
private ComposerPackagePath $composerPackagePath,
private WordPressPathFinder $wordPressPathFinder,
private LocalDependencyPathNormalizer $localDependencyPathNormalizer,
) {
}

public function path(): string
{
try {
$wordPressPath = $this->composerPackagePath->installPath(self::PACKAGE_NAME);
Comment thread
strangerkir marked this conversation as resolved.
} catch (Throwable) {
$wordPressPath = $this->wordPressPathFinder->discoveredPath();
}

return $this->localDependencyPathNormalizer->normalize($wordPressPath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

declare(strict_types=1);

namespace Syde\WpPhpUnitIntegration\Path\Finder;
namespace Syde\WpPhpUnitIntegration\Path;

use Exception;
use Syde\WpPhpUnitIntegration\Path\LocalDependencyPath;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;

readonly class WordPressPathFinder implements LocalDependencyPathFinder
readonly class WordPressPathFinder
{
public function __construct(private LocalDependencyPath $packageRootPath)
{
}

public function find(): string
/**
* @throws Exception
*/
public function discoveredPath(): string
{
$matches = (new Finder())
->ignoreDotFiles(false)
Expand Down
Loading
Loading