Skip to content

Commit

Permalink
Display the file permission in the octal form (#197)
Browse files Browse the repository at this point in the history
Closes #190
  • Loading branch information
theofidry authored May 4, 2018
1 parent 96fbaa3 commit 4c2459d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
29 changes: 19 additions & 10 deletions src/Console/Command/Compile.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
use const DATE_ATOM;
use function array_shift;
use function count;
use function decoct;
use function explode;
use function function_exists;
use function get_class;
Expand Down Expand Up @@ -187,15 +188,7 @@ protected function execute(InputInterface $input, OutputInterface $output): void
'Done.'
);

$io->comment(
sprintf(
"<info>PHAR size: %s\nMemory usage: %.2fMB (peak: %.2fMB), time: %.2fs<info>",
formatted_filesize($path),
round(memory_get_usage() / 1024 / 1024, 2),
round(memory_get_peak_usage() / 1024 / 1024, 2),
round(microtime(true) - $startTime, 2)
)
);
$this->logCommandResourcesUsage($io, $path, $startTime);
}

/**
Expand Down Expand Up @@ -650,7 +643,10 @@ private function correctPermissions(string $path, Configuration $config, BuildLo
if (null !== ($chmod = $config->getFileMode())) {
$logger->log(
BuildLogger::QUESTION_MARK_PREFIX,
"Setting file permissions to <comment>$chmod</comment>"
sprintf(
'Setting file permissions to <comment>%s</comment>',
'0'.decoct($chmod)
)
);

chmod($path, $chmod);
Expand Down Expand Up @@ -745,4 +741,17 @@ private function logMap(MapFile $fileMapper, BuildLogger $logger): void
}
}
}

private function logCommandResourcesUsage(SymfonyStyle $io, string $path, float $startTime)
{
return $io->comment(
sprintf(
"<info>PHAR size: %s\nMemory usage: %.2fMB (peak: %.2fMB), time: %.2fs<info>",
formatted_filesize($path),
round(memory_get_usage() / 1024 / 1024, 2),
round(memory_get_peak_usage() / 1024 / 1024, 2),
round(microtime(true) - $startTime, 2)
)
);
}
}
9 changes: 9 additions & 0 deletions tests/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,21 @@ public function test_no_file_mode_is_configured_by_default(): void

public function test_configure_file_mode(): void
{
// Octal value provided
$this->setConfig([
'files' => [self::DEFAULT_FILE],
'chmod' => '0755',
]);

$this->assertSame(0755, $this->config->getFileMode());

// Decimal value provided
$this->setConfig([
'files' => [self::DEFAULT_FILE],
'chmod' => '755',
]);

$this->assertSame(0755, $this->config->getFileMode());
}

public function test_a_main_script_path_is_configured_by_default(): void
Expand Down
8 changes: 4 additions & 4 deletions tests/Console/Command/CompileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function test_it_can_build_a_PHAR_file(): void
? No compression
? Signing using a private key
Private key passphrase:
? Setting file permissions to 493
? Setting file permissions to 0755
* Done.
// PHAR size: 100B
Expand Down Expand Up @@ -499,7 +499,7 @@ public function test_it_can_build_a_PHAR_with_complete_mapping(): void
'rand' => $rand,
)
? No compression
? Setting file permissions to 493
? Setting file permissions to 0755
* Done.
// PHAR size: 100B
Expand Down Expand Up @@ -734,7 +734,7 @@ public function test_it_can_build_a_PHAR_file_in_verbose_mode(): void
? No compression
? Signing using a private key
Private key passphrase:
? Setting file permissions to 493
? Setting file permissions to 0755
* Done.
// PHAR size: 100B
Expand Down Expand Up @@ -831,7 +831,7 @@ public function test_it_can_build_a_PHAR_file_in_very_verbose_mode(): void
? No compression
? Signing using a private key
Private key passphrase:
? Setting file permissions to 493
? Setting file permissions to 0755
* Done.
// PHAR size: 100B
Expand Down

0 comments on commit 4c2459d

Please sign in to comment.