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

Improve Windows support #129

Merged
merged 1 commit into from
Jan 31, 2022
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
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ on:

jobs:
PHPUnit:
name: PHPUnit (PHP ${{ matrix.php }})
runs-on: ubuntu-20.04
name: PHPUnit (PHP ${{ matrix.php }} on ${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-20.04
- windows-2019
php:
- 8.1
- 8.0
Expand Down Expand Up @@ -37,7 +40,7 @@ jobs:
- run: composer require symfony/console:^6.0 --dry-run --working-dir=tests/install-as-dep
if: ${{ matrix.php >= 8.0 }}
- run: composer require symfony/console:^5.0 --dry-run --working-dir=tests/install-as-dep
if: ${{ matrix.php >= 7.2 }}
if: ${{ matrix.php >= 7.2 && (matrix.php < 8.0 || matrix.os != 'windows-2019') }}
- run: composer require symfony/console:^4.0 --dry-run --working-dir=tests/install-as-dep
if: ${{ matrix.php >= 7.1 && matrix.php < 8.0 }}
- run: composer require symfony/console:^3.0 --dry-run --working-dir=tests/install-as-dep
Expand Down
6 changes: 3 additions & 3 deletions src/Phar/Packager.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,12 @@ public function exec($cmd, $chdir = null)
$process->setTimeout(null);
$code = $process->run(function($type, $data) use ($output, &$nl) {
if ($nl === true) {
$data = "\n" . $data;
$data = PHP_EOL . $data;
$nl = false;
}
if (substr($data, -1) === "\n") {
$nl = true;
$data = substr($data, 0, -1);
$data = substr($data, 0, -strlen(PHP_EOL));
}
$data = str_replace("\n", "\n ", $data);

Expand Down Expand Up @@ -327,7 +327,7 @@ private function isPackageName($path)

public function isPackageUrl($path)
{
return (strpos($path, '://') !== false && @parse_url($path) !== false) || preg_match('/^[^-\/\s][^:\/\s]*:\S+/', $path);
return (strpos($path, '://') !== false && @parse_url($path) !== false) || preg_match('/^[^-\/\s][^:\/\s]*:[^\s\\\\]\S*/', $path);
}

private function getDirTemporary()
Expand Down
12 changes: 6 additions & 6 deletions tests/Package/PackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ private function createMockLogger()

public function testBundleWillContainComposerJsonButNotVendor()
{
$dir = realpath(__DIR__ . '/../fixtures/03-project-with-phars') . '/';
$dir = realpath(__DIR__ . '/../fixtures/03-project-with-phars') . DIRECTORY_SEPARATOR;
$package = new Package(array(), $dir);
$bundle = $package->bundle();

$this->assertTrue($bundle->contains($dir . 'composer.json'));
$this->assertFalse($bundle->contains($dir . 'vendor/autoload.php'));
$this->assertFalse($bundle->contains($dir . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'));
}

public function testBundleWillNotContainComposerPharInRoot()
{
$dir = realpath(__DIR__ . '/../fixtures/03-project-with-phars') . '/';
$dir = realpath(__DIR__ . '/../fixtures/03-project-with-phars') . DIRECTORY_SEPARATOR;
$package = new Package(array(), $dir);
$bundle = $package->bundle();

Expand All @@ -67,12 +67,12 @@ public function testBundleWillNotContainComposerPharInRoot()

public function testBundleWillContainComposerPharFromSrc()
{
$dir = realpath(__DIR__ . '/../fixtures/04-project-with-phars-in-src') . '/';
$dir = realpath(__DIR__ . '/../fixtures/04-project-with-phars-in-src') . DIRECTORY_SEPARATOR;
$package = new Package(array(), $dir);
$bundle = $package->bundle();

$this->assertTrue($bundle->contains($dir . 'composer.json'));
$this->assertTrue($bundle->contains($dir . 'src/composer.phar'));
$this->assertTrue($bundle->contains($dir . 'src/phar-composer.phar'));
$this->assertTrue($bundle->contains($dir . 'src' . DIRECTORY_SEPARATOR . 'composer.phar'));
$this->assertTrue($bundle->contains($dir . 'src' . DIRECTORY_SEPARATOR . 'phar-composer.phar'));
}
}
41 changes: 33 additions & 8 deletions tests/Phar/PackagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ public function setUpPackager()
*/
public function testExec($expectedOutput, $command)
{
$this->expectOutputString($expectedOutput);

// Travis CI occasionally discards (parts of) the output, so wrap in shell and add some delay just in case
if (getenv('TRAVIS') === 'true') {
$command = 'exec sh -c ' . escapeshellarg($command . '; sleep 0.1');
}
$this->expectOutputString(str_replace("\n", PHP_EOL, $expectedOutput));

$this->packager->exec($command);
}
Expand All @@ -40,11 +35,11 @@ public function provideExecCommands()
),
array(
"\n error\n",
'echo error >&2'
'echo error>&2'
),
array(
"\n mixed\n errors\n",
'echo mixed && echo errors >&1'
'php -r ' . escapeshellarg('fwrite(STDOUT, \'mixed\' . PHP_EOL);fwrite(STDERR,\'errors\' . PHP_EOL);')
)
);
}
Expand All @@ -69,6 +64,10 @@ public function testNoComposerMissing()

public function testGetPharerTriesToExecuteGitStubInDirectoryWithSpaceAndThrowsWhenGitStubDoesNotCreateTargetDirectory()
{
if (DIRECTORY_SEPARATOR === '\\') {
$this->markTestSkipped('Not supported on Windows');
}

$path = getenv('PATH');

$temp = sys_get_temp_dir() . '/test phar-composer-' . mt_rand();
Expand All @@ -93,6 +92,10 @@ public function testGetPharerTriesToExecuteGitStubInDirectoryWithSpaceAndThrowsW

public function testGetSystemBinDefaultsToPackageNameInBin()
{
if (DIRECTORY_SEPARATOR === '\\') {
$this->markTestSkipped('Not supported on Windows');
}

$package = new Package(array(
'name' => 'clue/phar-composer'
), '');
Expand All @@ -102,20 +105,32 @@ public function testGetSystemBinDefaultsToPackageNameInBin()

public function testGetSystemBinReturnsPackageDirectoryBinWhenNameIsNotSet()
{
if (DIRECTORY_SEPARATOR === '\\') {
$this->markTestSkipped('Not supported on Windows');
}

$package = new Package(array(), __DIR__);

$this->assertEquals('/usr/local/bin/Phar', $this->packager->getSystemBin($package, null));
}

public function testGetSystemBinReturnsPackageDirectoryRealNameInBinWhenNameIsNotSet()
{
if (DIRECTORY_SEPARATOR === '\\') {
$this->markTestSkipped('Not supported on Windows');
}

$package = new Package(array(), __DIR__ . '/../');

$this->assertEquals('/usr/local/bin/tests', $this->packager->getSystemBin($package, null));
}

public function testGetSystemBinReturnsCustomPackageInBin()
{
if (DIRECTORY_SEPARATOR === '\\') {
$this->markTestSkipped('Not supported on Windows');
}

$package = new Package(array(
'name' => 'clue/phar-composer'
), '');
Expand All @@ -125,6 +140,10 @@ public function testGetSystemBinReturnsCustomPackageInBin()

public function testGetSystemBinReturnsCustomTargetPath()
{
if (DIRECTORY_SEPARATOR === '\\') {
$this->markTestSkipped('Not supported on Windows');
}

$package = new Package(array(
'name' => 'clue/phar-composer'
), '');
Expand All @@ -134,6 +153,10 @@ public function testGetSystemBinReturnsCustomTargetPath()

public function testGetSystemBinReturnsDefaultPackageNameInCustomBin()
{
if (DIRECTORY_SEPARATOR === '\\') {
$this->markTestSkipped('Not supported on Windows');
}

$package = new Package(array(
'name' => 'clue/phar-composer'
), '');
Expand Down Expand Up @@ -174,6 +197,8 @@ public function provideInvalidPackageUrl()
array('git @github.com:clue/phar-composer.git'),
array('-invalid@github.com:clue/phar-composer.git'),
array(':clue/phar-composer.git'),
array('/home/alice/Desktop/package/acme.json'),
array('C:\Users\Alice\Desktop\package\acme.json')
);
}

Expand Down