Skip to content

Commit

Permalink
Fix for the unit test and throwing an exception in the action class w…
Browse files Browse the repository at this point in the history
…hen there is no access to the package directory.
  • Loading branch information
rosven9856 committed Oct 8, 2024
1 parent d58582a commit 69feff4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
55 changes: 29 additions & 26 deletions src/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,36 +44,39 @@ public function run(): void

$rootDirectory = $this->configuration->getRootDirectory();

if (is_dir($rootDirectory) && is_readable($rootDirectory) && is_writable($rootDirectory)) {

$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($rootDirectory),
\RecursiveIteratorIterator::CHILD_FIRST,
if (!is_dir($rootDirectory) || !is_readable($rootDirectory) || !is_writable($rootDirectory)) {

Check warning on line 47 in src/Action.php

View workflow job for this annotation

GitHub Actions / mutation-tests (8.3)

Escaped Mutant for Mutator "LogicalOr": --- Original +++ New @@ @@ throw new \Exception('Failed to create zip archive'); } $rootDirectory = $this->configuration->getRootDirectory(); - if (!is_dir($rootDirectory) || !is_readable($rootDirectory) || !is_writable($rootDirectory)) { + if ((!is_dir($rootDirectory) || !is_readable($rootDirectory)) && !is_writable($rootDirectory)) { throw new \Exception(\sprintf('Directory "%s" is not exists or is not readable or is not writable', $rootDirectory)); } $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($rootDirectory), \RecursiveIteratorIterator::CHILD_FIRST);

Check warning on line 47 in src/Action.php

View workflow job for this annotation

GitHub Actions / mutation-tests (8.3)

Escaped Mutant for Mutator "LogicalOr": --- Original +++ New @@ @@ throw new \Exception('Failed to create zip archive'); } $rootDirectory = $this->configuration->getRootDirectory(); - if (!is_dir($rootDirectory) || !is_readable($rootDirectory) || !is_writable($rootDirectory)) { + if (!is_dir($rootDirectory) && !is_readable($rootDirectory) || !is_writable($rootDirectory)) { throw new \Exception(\sprintf('Directory "%s" is not exists or is not readable or is not writable', $rootDirectory)); } $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($rootDirectory), \RecursiveIteratorIterator::CHILD_FIRST);

Check warning on line 47 in src/Action.php

View workflow job for this annotation

GitHub Actions / mutation-tests (8.3)

Escaped Mutant for Mutator "LogicalOr": --- Original +++ New @@ @@ throw new \Exception('Failed to create zip archive'); } $rootDirectory = $this->configuration->getRootDirectory(); - if (!is_dir($rootDirectory) || !is_readable($rootDirectory) || !is_writable($rootDirectory)) { + if ((!is_dir($rootDirectory) || !is_readable($rootDirectory)) && !is_writable($rootDirectory)) { throw new \Exception(\sprintf('Directory "%s" is not exists or is not readable or is not writable', $rootDirectory)); } $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($rootDirectory), \RecursiveIteratorIterator::CHILD_FIRST);
throw new \Exception(
\sprintf('Directory "%s" is not exists or is not readable or is not writable', $rootDirectory),
);
}

$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($rootDirectory),
\RecursiveIteratorIterator::CHILD_FIRST,
);

foreach ($iterator as $path) {

Check warning on line 58 in src/Action.php

View workflow job for this annotation

GitHub Actions / mutation-tests (8.3)

Escaped Mutant for Mutator "Foreach_": --- Original +++ New @@ @@ throw new \Exception(\sprintf('Directory "%s" is not exists or is not readable or is not writable', $rootDirectory)); } $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($rootDirectory), \RecursiveIteratorIterator::CHILD_FIRST); - foreach ($iterator as $path) { + foreach (array() as $path) { /** * @var \SplFileInfo $path */

Check warning on line 58 in src/Action.php

View workflow job for this annotation

GitHub Actions / mutation-tests (8.3)

Escaped Mutant for Mutator "Foreach_": --- Original +++ New @@ @@ throw new \Exception(\sprintf('Directory "%s" is not exists or is not readable or is not writable', $rootDirectory)); } $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($rootDirectory), \RecursiveIteratorIterator::CHILD_FIRST); - foreach ($iterator as $path) { + foreach (array() as $path) { /** * @var \SplFileInfo $path */
/**
* @var \SplFileInfo $path
*/
if ($path->getBasename() === '.gitignore') {
$ignore->add(
file_get_contents($path->getRealPath()),
\dirname($path->getRealPath()) . '/',
);
}
}

foreach ($iterator as $path) {
/**
* @var \SplFileInfo $path
*/
if ($path->getBasename() === '.gitignore') {
$ignore->add(
file_get_contents($path->getRealPath()),
\dirname($path->getRealPath()) . '/',
);
}
foreach ($iterator as $path) {
/**
* @var \SplFileInfo $path
*/
if (!$path->isFile()) {
continue;

Check warning on line 75 in src/Action.php

View workflow job for this annotation

GitHub Actions / mutation-tests (8.3)

Escaped Mutant for Mutator "Continue_": --- Original +++ New @@ @@ * @var \SplFileInfo $path */ if (!$path->isFile()) { - continue; + break; } if (!$ignore->ignores($path->getPathname())) { $zip->addFile($path->getPathname(), str_replace($rootDirectory . \DIRECTORY_SEPARATOR, '', $path->getPathname()));
}

foreach ($iterator as $path) {
/**
* @var \SplFileInfo $path
*/
if (!$path->isFile()) {
continue;
}

if (!$ignore->ignores($path->getPathname())) {
$zip->addFile($path->getPathname(), str_replace($rootDirectory . \DIRECTORY_SEPARATOR, '', $path->getPathname()));
}
if (!$ignore->ignores($path->getPathname())) {
$zip->addFile($path->getPathname(), str_replace($rootDirectory . \DIRECTORY_SEPARATOR, '', $path->getPathname()));

Check warning on line 79 in src/Action.php

View workflow job for this annotation

GitHub Actions / mutation-tests (8.3)

Escaped Mutant for Mutator "Concat": --- Original +++ New @@ @@ continue; } if (!$ignore->ignores($path->getPathname())) { - $zip->addFile($path->getPathname(), str_replace($rootDirectory . \DIRECTORY_SEPARATOR, '', $path->getPathname())); + $zip->addFile($path->getPathname(), str_replace(\DIRECTORY_SEPARATOR . $rootDirectory, '', $path->getPathname())); } } $zip->close();

Check warning on line 79 in src/Action.php

View workflow job for this annotation

GitHub Actions / mutation-tests (8.3)

Escaped Mutant for Mutator "ConcatOperandRemoval": --- Original +++ New @@ @@ continue; } if (!$ignore->ignores($path->getPathname())) { - $zip->addFile($path->getPathname(), str_replace($rootDirectory . \DIRECTORY_SEPARATOR, '', $path->getPathname())); + $zip->addFile($path->getPathname(), str_replace(\DIRECTORY_SEPARATOR, '', $path->getPathname())); } } $zip->close();

Check warning on line 79 in src/Action.php

View workflow job for this annotation

GitHub Actions / mutation-tests (8.3)

Escaped Mutant for Mutator "ConcatOperandRemoval": --- Original +++ New @@ @@ continue; } if (!$ignore->ignores($path->getPathname())) { - $zip->addFile($path->getPathname(), str_replace($rootDirectory . \DIRECTORY_SEPARATOR, '', $path->getPathname())); + $zip->addFile($path->getPathname(), str_replace($rootDirectory, '', $path->getPathname())); } } $zip->close();

Check warning on line 79 in src/Action.php

View workflow job for this annotation

GitHub Actions / mutation-tests (8.3)

Escaped Mutant for Mutator "UnwrapStrReplace": --- Original +++ New @@ @@ continue; } if (!$ignore->ignores($path->getPathname())) { - $zip->addFile($path->getPathname(), str_replace($rootDirectory . \DIRECTORY_SEPARATOR, '', $path->getPathname())); + $zip->addFile($path->getPathname(), $path->getPathname()); } } $zip->close();

Check warning on line 79 in src/Action.php

View workflow job for this annotation

GitHub Actions / mutation-tests (8.3)

Escaped Mutant for Mutator "Concat": --- Original +++ New @@ @@ continue; } if (!$ignore->ignores($path->getPathname())) { - $zip->addFile($path->getPathname(), str_replace($rootDirectory . \DIRECTORY_SEPARATOR, '', $path->getPathname())); + $zip->addFile($path->getPathname(), str_replace(\DIRECTORY_SEPARATOR . $rootDirectory, '', $path->getPathname())); } } $zip->close();

Check warning on line 79 in src/Action.php

View workflow job for this annotation

GitHub Actions / mutation-tests (8.3)

Escaped Mutant for Mutator "ConcatOperandRemoval": --- Original +++ New @@ @@ continue; } if (!$ignore->ignores($path->getPathname())) { - $zip->addFile($path->getPathname(), str_replace($rootDirectory . \DIRECTORY_SEPARATOR, '', $path->getPathname())); + $zip->addFile($path->getPathname(), str_replace(\DIRECTORY_SEPARATOR, '', $path->getPathname())); } } $zip->close();

Check warning on line 79 in src/Action.php

View workflow job for this annotation

GitHub Actions / mutation-tests (8.3)

Escaped Mutant for Mutator "ConcatOperandRemoval": --- Original +++ New @@ @@ continue; } if (!$ignore->ignores($path->getPathname())) { - $zip->addFile($path->getPathname(), str_replace($rootDirectory . \DIRECTORY_SEPARATOR, '', $path->getPathname())); + $zip->addFile($path->getPathname(), str_replace($rootDirectory, '', $path->getPathname())); } } $zip->close();

Check warning on line 79 in src/Action.php

View workflow job for this annotation

GitHub Actions / mutation-tests (8.3)

Escaped Mutant for Mutator "UnwrapStrReplace": --- Original +++ New @@ @@ continue; } if (!$ignore->ignores($path->getPathname())) { - $zip->addFile($path->getPathname(), str_replace($rootDirectory . \DIRECTORY_SEPARATOR, '', $path->getPathname())); + $zip->addFile($path->getPathname(), $path->getPathname()); } } $zip->close();
}
}

Expand Down
6 changes: 5 additions & 1 deletion tests/ActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ private function removeDirectory(string $dir): void
public function testBuildComposerPackage(): void
{
if ($this->action instanceof Action) {
$this->action->run();
try {
$this->action->run();
} catch (\Exception $e) {
self::assertNotNull($e);
}
}

self::assertFileExists((string) $this->getConfiguration()->get('build.file'));
Expand Down

0 comments on commit 69feff4

Please sign in to comment.