Skip to content

Commit

Permalink
clean up mocks on destruct (#1320)
Browse files Browse the repository at this point in the history
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
  • Loading branch information
ghostwriter committed Aug 4, 2023
1 parent 061d7de commit 8bade9a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions library/Mockery/Loader/RequireLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,23 @@ public function __construct($path = null)
$this->path = realpath($path) ?: sys_get_temp_dir();
}

public function __destruct()
{
foreach (glob($this->path . DIRECTORY_SEPARATOR . 'Mockery_*.php') as $file) {
@unlink($file);
}
}

public function load(MockDefinition $definition)
{
if (class_exists($definition->getClassName(), false)) {
return;
}

$tmpfname = $this->path . DIRECTORY_SEPARATOR . "Mockery_" . uniqid() . ".php";
file_put_contents($tmpfname, $definition->getCode());
$fileName = sprintf('%s%s%s.php', $this->path, DIRECTORY_SEPARATOR, uniqid('Mockery_'));

Check failure on line 38 in library/Mockery/Loader/RequireLoader.php

View workflow job for this annotation

GitHub Actions / Psalm

MixedArgument

library/Mockery/Loader/RequireLoader.php:38:43: MixedArgument: Argument 2 of sprintf cannot be mixed, expecting float|int|string (see https://psalm.dev/030)

file_put_contents($fileName, $definition->getCode());

require $tmpfname;
require $fileName;

Check failure on line 42 in library/Mockery/Loader/RequireLoader.php

View workflow job for this annotation

GitHub Actions / Psalm

UnresolvableInclude

library/Mockery/Loader/RequireLoader.php:42:9: UnresolvableInclude: Cannot resolve the given expression to a file path (see https://psalm.dev/106)
}
}

0 comments on commit 8bade9a

Please sign in to comment.