Skip to content
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
6 changes: 3 additions & 3 deletions src/WordPress/Blueprints/Runner/Step/UnzipStepRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class UnzipStepRunner extends BaseStepRunner {
* Runs the Unzip Step
*
* @param UnzipStep $input Step.
* @param Tracker $progress_tracker Tracker.
* @param Tracker $progress_tracker Tracker.
* @return void
*/
public function run(
$input,
$progress_tracker
UnzipStep $input,
Tracker $progress_tracker
) {
$progress_tracker->set( 10, 'Unzipping...' );

Expand Down
2 changes: 1 addition & 1 deletion src/WordPress/Zip/ZipCentralDirectoryEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct(
$this->versionNeeded = $versionNeeded;
$this->versionCreated = $versionCreated;
$this->firstByteAt = $firstByteAt;
$this->isDirectory = $this->path[- 1] === '/';
$this->isDirectory = substr( $this->path, -1 ) === '/';
}

public function isFileEntry() {
Expand Down
2 changes: 1 addition & 1 deletion src/WordPress/Zip/ZipFileEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function __construct(
$this->compressionMethod = $compressionMethod;
$this->generalPurpose = $generalPurpose;
$this->version = $version;
$this->isDirectory = $this->path[- 1] === '/';
$this->isDirectory = substr( $this->path, -1 ) === '/';
}

public function isFileEntry() {
Expand Down
77 changes: 37 additions & 40 deletions tests/unit/steps/UnzipStepRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace unit\steps;

use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\MockObject\Stub;
use PHPUnitTestCase;
use Symfony\Component\Filesystem\Filesystem;
Expand All @@ -25,17 +26,17 @@ class UnzipStepRunnerTest extends PHPUnitTestCase {
private $runtime;

/**
* @var UnzipStepRunner $step
* @var UnzipStepRunner $step_runner
*/
private $step;
private $step_runner;

/**
* @var Filesystem
*/
private $file_system;
private $filesystem;

/**
* @var Stub
* @var ResourceManager&MockObject $resource_manager resource manager mock
*/
private $resource_manager;

Expand All @@ -48,51 +49,47 @@ public function before() {

$this->resource_manager = $this->createMock( ResourceManager::class );

$this->step = new UnzipStepRunner();
$this->step->setRuntime( $this->runtime );
$this->step->setResourceManager( $this->resource_manager );
$this->step_runner = new UnzipStepRunner();
$this->step_runner->setRuntime( $this->runtime );
$this->step_runner->setResourceManager( $this->resource_manager );

$this->file_system = new Filesystem();
$this->filesystem = new Filesystem();
}

/**
* @after
*/
public function after() {
$this->file_system->remove( $this->document_root );
$this->filesystem->remove( $this->document_root );
}

public function test(){
$this->assertTrue(true); // Placeholder until true test are fixed.
public function testUnzipFileWhenUsingAbsolutePath() {
$zip = __DIR__ . '/resources/test_zip.zip';
$this->resource_manager->method( 'getStream' )
->willReturn( fopen( $zip, 'rb' ) );

$step = new UnzipStep();
$step->setZipFile( $zip );
$extracted_file_path = $this->runtime->resolvePath( 'dir/test_zip.txt' );
$step->setExtractToPath( Path::getDirectory( $extracted_file_path ) );

$this->step_runner->run( $step, new Tracker() );

self::assertFileEquals( __DIR__ . '/resources/test_zip.txt', $extracted_file_path );
}

// public function testUnzipFileWhenUsingAbsolutePath() {
// $zip = __DIR__ . '/resources/test_zip.zip';
// $this->resource_manager->method( 'getStream' )
// ->willReturn( fopen( $zip, 'rb' ) );
//
// $input = new UnzipStep();
// $input->setZipFile( $zip );
// $extracted_file_path = $this->runtime->resolvePath( 'dir/test_zip.txt' );
// $input->setExtractToPath( Path::getDirectory( $extracted_file_path ) );
//
// $this->step->run( $input, new Tracker() );
//
// $this->assertFileEquals( __DIR__ . '/resources/test_zip.txt', $extracted_file_path );
// }
//
// public function testUnzipFileWhenUsingRelativePath() {
// $zip = __DIR__ . '/resources/test_zip.zip';
// $this->resource_manager->method( 'getStream' )
// ->willReturn( fopen( $zip, 'rb' ) );
//
// $input = new UnzipStep();
// $input->setZipFile( $zip );
// $input->setExtractToPath( 'dir' );
//
// $this->step->run( $input, new Tracker() );
//
// $extracted_file_path = $this->runtime->resolvePath( 'dir/test_zip.txt' );
// $this->assertFileEquals( __DIR__ . '/resources/test_zip.txt', $extracted_file_path );
// }
public function testUnzipFileWhenUsingRelativePath() {
$zip = __DIR__ . '/resources/test_zip.zip';
$this->resource_manager->method( 'getStream' )
->willReturn( fopen( $zip, 'rb' ) );

$step = new UnzipStep();
$step->setZipFile( $zip );
$step->setExtractToPath( 'dir' );

$this->step_runner->run( $step, new Tracker() );

$extracted_file_path = $this->runtime->resolvePath( 'dir/test_zip.txt' );
self::assertFileEquals( __DIR__ . '/resources/test_zip.txt', $extracted_file_path );
}
}