-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
130 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
namespace Blueprints\Runner\Step; | ||
|
||
use Symfony\Component\Filesystem\Filesystem; | ||
use Symfony\Component\Filesystem\Path; | ||
use WordPress\Blueprints\BlueprintException; | ||
use WordPress\Blueprints\Model\DataClass\FilesystemResource; | ||
use WordPress\Blueprints\Model\DataClass\UnzipStep; | ||
use WordPress\Blueprints\Resources\Resolver\FilesystemResourceResolver; | ||
use WordPress\Blueprints\Resources\ResourceManager; | ||
use WordPress\Blueprints\Runner\Step\UnzipStepRunner; | ||
use PHPUnit\Framework\TestCase; | ||
use WordPress\Blueprints\Runtime\NativePHPRuntime; | ||
|
||
class UnzipStepRunnerTest extends TestCase { | ||
|
||
|
||
/** | ||
* @var string | ||
*/ | ||
private string $document_root; | ||
|
||
/** | ||
* @var NativePHPRuntime | ||
*/ | ||
private NativePHPRuntime $runtime; | ||
|
||
/** | ||
* @var UnzipStepRunner | ||
*/ | ||
private UnzipStepRunner $step; | ||
|
||
/** | ||
* @var Filesystem | ||
*/ | ||
private Filesystem $file_system; | ||
|
||
/** | ||
* @before | ||
*/ | ||
public function before() { | ||
$this->document_root = Path::makeAbsolute( 'test', sys_get_temp_dir() ); | ||
$this->runtime = new NativePHPRuntime( $this->document_root ); | ||
|
||
$resource_manager = $this->createStub( ResourceManager::class ); | ||
$resource_manager->method( 'getStream' ) | ||
->willReturn( fopen( __DIR__ . '\test.zip', 'rb' ) ); | ||
|
||
$this->step = new UnzipStepRunner(); | ||
$this->step->setRuntime( $this->runtime ); | ||
$this->step->setResourceManager( $resource_manager ); | ||
|
||
$this->file_system = new Filesystem(); | ||
} | ||
|
||
/** | ||
* @after | ||
*/ | ||
public function after() { | ||
$this->file_system->remove( $this->document_root ); | ||
} | ||
|
||
public function testUnzipFileWhenUsingAbsolutePath(): void { | ||
$input = new UnzipStep(); | ||
$zip = __DIR__ . '\test.zip'; | ||
$input->setZipFile( $zip ); | ||
$relative_path = 'dir'; | ||
$absolute_path = $this->runtime->resolvePath( $relative_path ); | ||
$input->setExtractToPath( $absolute_path ); | ||
|
||
$this->step->run( $input ); | ||
|
||
$this->assertDirectoryExists( $absolute_path ); | ||
} | ||
|
||
public function testUnzipFileWhenUsingRelativePath(): void { | ||
$input = new UnzipStep(); | ||
$zip = __DIR__ . '\test.zip'; | ||
$input->setZipFile( $zip ); | ||
$relative_path = 'dir'; | ||
$input->setExtractToPath( $relative_path ); | ||
|
||
$this->step->run( $input ); | ||
|
||
$absolute_path = $this->runtime->resolvePath( $relative_path ); | ||
$this->assertDirectoryExists( $absolute_path ); | ||
} | ||
} |
File renamed without changes.
This file was deleted.
Oops, something went wrong.