diff --git a/.github/workflows/php-qa.yml b/.github/workflows/php-qa.yml index 7292f5de..b0349be5 100644 --- a/.github/workflows/php-qa.yml +++ b/.github/workflows/php-qa.yml @@ -6,7 +6,7 @@ jobs: if: "!contains(github.event.head_commit.message, 'ci skip')" strategy: matrix: - php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4'] + php-versions: ['7.1', '7.2', '7.3', '7.4'] steps: - uses: actions/checkout@v2 diff --git a/.gitignore b/.gitignore index 01820fd8..911db961 100644 Binary files a/.gitignore and b/.gitignore differ diff --git a/README.md b/README.md index 6d913aad..ed67462d 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ WP Starter is the easiest and fastest way to bootstrap WordPress sites entirely # System Requirements - PHP 7.0+ - - [Composer](https://getcomposer.org/) v1 + - [Composer](https://getcomposer.org/) >= 1.5.0 <= 2 # License diff --git a/src/Util/Unzipper.php b/src/Util/Unzipper.php index 9ba432c9..0d6e1f9f 100644 --- a/src/Util/Unzipper.php +++ b/src/Util/Unzipper.php @@ -14,7 +14,6 @@ use Composer\Config; use Composer\Downloader\ZipDownloader; use Composer\IO\IOInterface; -use Composer\Util\Platform; /** * Wrapper around Composer ZipDownloader because we need just an unzipper, not a downloader. @@ -32,7 +31,7 @@ class Unzipper */ public function __construct(IOInterface $io, Config $config) { - $this->unzipper = $this->createUnzipper($io, $config); + $this->unzipper = new ZipDownloader($io, $config); } /** @@ -44,58 +43,12 @@ public function __construct(IOInterface $io, Config $config) */ public function unzip(string $zipPath, string $target): bool { - /** @var callable(string, string): bool */ - $unzip = [$this->unzipper, 'unzip']; + try { + $this->unzipper->extract($zipPath, $target); - return $unzip($zipPath, $target); - } - - /** - * We create this anonymous class extending ZipDownloader because its extract* methods - * we are interested in are protected, and the public `extract()` method does not return. - * - * @param IOInterface $io - * @param Config $config - * @return ZipDownloader - * - * phpcs:disable Inpsyde.CodeQuality.NestingLevel - */ - private function createUnzipper(IOInterface $io, Config $config): ZipDownloader - { - // phpcs:enable Inpsyde.CodeQuality.NestingLevel - - return new class ($io, $config) extends ZipDownloader - { - /** - * @var bool - */ - private $useZipArchive; - - /** - * @param IOInterface $io - * @param Config $config - */ - public function __construct(IOInterface $io, Config $config) - { - $this->useZipArchive = Platform::isWindows(); - parent::__construct($io, $config); - } - - /** - * @param string $zipPath - * @param string $target - * @return bool - */ - public function unzip(string $zipPath, string $target): bool - { - try { - return $this->useZipArchive - ? $this->extractWithZipArchive($zipPath, $target, false) - : $this->extractWithSystemUnzip($zipPath, $target, false); - } catch (\Throwable $exception) { - return false; - } - } - }; + return true; + } catch (\Throwable $throwable) { + return false; + } } } diff --git a/tests/integration/Cli/PhpToolProcessFactoryTest.php b/tests/integration/Cli/PhpToolProcessFactoryTest.php index 75cd8d1b..facc5664 100644 --- a/tests/integration/Cli/PhpToolProcessFactoryTest.php +++ b/tests/integration/Cli/PhpToolProcessFactoryTest.php @@ -230,7 +230,7 @@ public function testRunWpCliCommandViaFileSystemBootstrap() */ private function assertProcessWorks(PhpToolProcess $process) { - static::assertTrue($process->execute('-r "echo \'Hi!!!\'";')); + static::assertTrue($process->execute('-r "echo \'Hi!!!\';"')); $output = trim($this->collectOutput()); diff --git a/tests/integration/Util/UnzipperTest.php b/tests/integration/Util/UnzipperTest.php index e88c834d..70074259 100644 --- a/tests/integration/Util/UnzipperTest.php +++ b/tests/integration/Util/UnzipperTest.php @@ -8,31 +8,21 @@ namespace WeCodeMore\WpStarter\Tests\Integration\Util; -use org\bovigo\vfs\vfsStream; use WeCodeMore\WpStarter\Tests\IntegrationTestCase; use WeCodeMore\WpStarter\Util\Unzipper; class UnzipperTest extends IntegrationTestCase { - private function createUnzipper(): Unzipper - { - return new Unzipper($this->createComposerIo(), $this->createComposerConfig()); - } - /** * @covers \WeCodeMore\WpStarter\Util\Unzipper */ public function testUnzipFail() { - $source = getenv('TESTS_FIXTURES_PATH') . '/faulty-zip.zip'; - - $dir = vfsStream::setup('directory'); - $targetDir = $dir->url(); + $dir = getenv('TESTS_FIXTURES_PATH'); + $source = $dir . '/faulty-zip.zip'; + $unzipper = new Unzipper($this->createComposerIo(), $this->createComposerConfig()); - $unzipper = $this->createUnzipper(); - - static::assertFalse($unzipper->unzip($source, $targetDir)); - static::assertFalse($dir->hasChildren()); + static::assertFalse($unzipper->unzip($source, $dir)); } /** @@ -40,14 +30,15 @@ public function testUnzipFail() */ public function testUnzipSuccess() { - $source = getenv('TESTS_FIXTURES_PATH') . '/good-zip.zip'; - - $dir = vfsStream::setup('directory'); - $targetDir = $dir->url(); - - $unzipper = $this->createUnzipper(); - - static::assertTrue($unzipper->unzip($source, $targetDir)); - static::assertTrue($dir->hasChildren()); + $dir = getenv('TESTS_FIXTURES_PATH'); + $unzipper = new Unzipper($this->createComposerIo(), $this->createComposerConfig()); + + try { + static::assertTrue($unzipper->unzip("{$dir}/good-zip.zip", $dir)); + // this is the file contained in `good-zip.zip` file + static::assertTrue(file_exists("{$dir}/some-zip-content.txt")); + } finally { + @unlink("{$dir}/some-zip-content.txt"); + } } -} \ No newline at end of file +} diff --git a/tests/src/DummyPhpTool.php b/tests/src/DummyPhpTool.php index 4609be3c..9c1d82ab 100644 --- a/tests/src/DummyPhpTool.php +++ b/tests/src/DummyPhpTool.php @@ -111,4 +111,4 @@ public function prepareCommand(string $command, Paths $paths, Io $io): string return $command; } -} \ No newline at end of file +}