Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/tests' into tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reimic committed Mar 28, 2024
2 parents 30c0d6c + bef36be commit e6bf884
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 119 deletions.
2 changes: 1 addition & 1 deletion src/WordPress/Blueprints/Runner/Step/UnzipStepRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ 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(
Expand Down
226 changes: 113 additions & 113 deletions tests/unit/steps/RmStepRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,153 +11,153 @@
use WordPress\Blueprints\Runtime\Runtime;

class RmStepRunnerTest extends PHPUnitTestCase {
/**
* @var string
*/
private $document_root;

/**
* @var Runtime
*/
private $runtime;

/**
* @var RmStepRunner
*/
private $step_runner;

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

/**
* @before
*/
public function before() {
$this->document_root = Path::makeAbsolute( "test", sys_get_temp_dir() );
$this->runtime = new Runtime( $this->document_root );

$this->step_runner = new RmStepRunner();
$this->step_runner->setRuntime( $this->runtime );

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

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

public function testRemoveDirectoryWhenUsingAbsolutePath() {
$absolute_path = $this->runtime->resolvePath( "dir" );
$this->filesystem->mkdir( $absolute_path );

$step = new RmStep();
$step->path = $absolute_path;

$this->step_runner->run( $step );
/**
* @var string
*/
private $document_root;

/**
* @var Runtime
*/
private $runtime;

/**
* @var RmStepRunner
*/
private $step_runner;

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

/**
* @before
*/
public function before() {
$this->document_root = Path::makeAbsolute( "test", sys_get_temp_dir() );
$this->runtime = new Runtime( $this->document_root );

$this->step_runner = new RmStepRunner();
$this->step_runner->setRuntime( $this->runtime );

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

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

public function testRemoveDirectoryWhenUsingAbsolutePath() {
$absolute_path = $this->runtime->resolvePath( "dir" );
$this->filesystem->mkdir( $absolute_path );

$step = new RmStep();
$step->path = $absolute_path;

$this->step_runner->run( $step );

self::assertDirectoryDoesNotExist( $absolute_path );
}
}

public function testRemoveDirectoryWhenUsingRelativePath() {
$relative_path = "dir";
$absolute_path = $this->runtime->resolvePath( $relative_path );
$this->filesystem->mkdir( $absolute_path );
public function testRemoveDirectoryWhenUsingRelativePath() {
$relative_path = "dir";
$absolute_path = $this->runtime->resolvePath( $relative_path );
$this->filesystem->mkdir( $absolute_path );

$step = new RmStep();
$step->path = $relative_path;
$step = new RmStep();
$step->path = $relative_path;

$this->step_runner->run( $step );
$this->step_runner->run( $step );

self::assertDirectoryDoesNotExist( $absolute_path );
}
self::assertDirectoryDoesNotExist( $absolute_path );
}

public function testRemoveDirectoryWithSubdirectory() {
$relative_path = "dir/subdir";
$absolute_path = $this->runtime->resolvePath( $relative_path );
$this->filesystem->mkdir( $absolute_path );
public function testRemoveDirectoryWithSubdirectory() {
$relative_path = "dir/subdir";
$absolute_path = $this->runtime->resolvePath( $relative_path );
$this->filesystem->mkdir( $absolute_path );

$step = new RmStep();
$step->path = dirname( $relative_path );
$step = new RmStep();
$step->path = dirname( $relative_path );

$this->step_runner->run( $step );
$this->step_runner->run( $step );

self::assertDirectoryDoesNotExist( $absolute_path );
}
self::assertDirectoryDoesNotExist( $absolute_path );
}

public function testRemoveDirectoryWithFile() {
$relative_path = "dir/file.txt";
$absolute_pPath = $this->runtime->resolvePath( $relative_path );
$this->filesystem->dumpFile( $absolute_pPath, "test" );
public function testRemoveDirectoryWithFile() {
$relative_path = "dir/file.txt";
$absolute_pPath = $this->runtime->resolvePath( $relative_path );
$this->filesystem->dumpFile( $absolute_pPath, "test" );

$step = new RmStep();
$step->path = dirname( $relative_path );
$step = new RmStep();
$step->path = dirname( $relative_path );

$this->step_runner->run( $step );
$this->step_runner->run( $step );

self::assertDirectoryDoesNotExist( dirname( $absolute_pPath ) );
}
self::assertDirectoryDoesNotExist( dirname( $absolute_pPath ) );
}

public function testRemoveFile() {
$relative_path = "file.txt";
$absolute_path = $this->runtime->resolvePath( $relative_path );
$this->filesystem->dumpFile( $absolute_path, "test" );
public function testRemoveFile() {
$relative_path = "file.txt";
$absolute_path = $this->runtime->resolvePath( $relative_path );
$this->filesystem->dumpFile( $absolute_path, "test" );

$step = new RmStep();
$step->path = $relative_path;
$step = new RmStep();
$step->path = $relative_path;

$this->step_runner->run( $step );
$this->step_runner->run( $step );

self::assertDirectoryDoesNotExist( $absolute_path );
}
self::assertDirectoryDoesNotExist( $absolute_path );
}

public function testThrowExceptionWhenRemovingNonexistentDirectoryAndUsingRelativePath() {
$relative_path = "dir";
$absolute_path = $this->runtime->resolvePath( $relative_path );
public function testThrowExceptionWhenRemovingNonexistentDirectoryAndUsingRelativePath() {
$relative_path = "dir";
$absolute_path = $this->runtime->resolvePath( $relative_path );

$step = new RmStep();
$step->path = $relative_path;
$step = new RmStep();
$step->path = $relative_path;

self::expectException( BlueprintException::class );
self::expectExceptionMessage( "Failed to remove \"$absolute_path\": the directory or file does not exist." );
$this->step_runner->run( $step );
}
self::expectException( BlueprintException::class );
self::expectExceptionMessage( "Failed to remove \"$absolute_path\": the directory or file does not exist." );
$this->step_runner->run( $step );
}

public function testThrowExceptionWhenRemovingNonexistentDirectoryAndUsingAbsolutePath() {
$absolute_path = "/dir";
public function testThrowExceptionWhenRemovingNonexistentDirectoryAndUsingAbsolutePath() {
$absolute_path = "/dir";

$step = new RmStep();
$step->path = $absolute_path;
$step = new RmStep();
$step->path = $absolute_path;

self::expectException( BlueprintException::class );
self::expectExceptionMessage( "Failed to remove \"$absolute_path\": the directory or file does not exist." );
$this->step_runner->run( $step );
}
$this->step_runner->run( $step );
}

public function testThrowExceptionWhenRemovingNonexistentFileAndUsingAbsolutePath() {
$relative_path = "/file.txt";
public function testThrowExceptionWhenRemovingNonexistentFileAndUsingAbsolutePath() {
$relative_path = "/file.txt";

$step = new RmStep();
$step->path = $relative_path;
$step = new RmStep();
$step->path = $relative_path;

self::expectException( BlueprintException::class );
self::expectExceptionMessage( "Failed to remove \"$relative_path\": the directory or file does not exist." );
$this->step_runner->run( $step );
}
$this->step_runner->run( $step );
}

public function testThrowExceptionWhenRemovingNonexistentFileAndUsingRelativePath() {
$relativePath = "file.txt";
$absolutePath = $this->runtime->resolvePath($relativePath);
public function testThrowExceptionWhenRemovingNonexistentFileAndUsingRelativePath() {
$relativePath = "file.txt";
$absolutePath = $this->runtime->resolvePath($relativePath);

$step = new RmStep();
$step->path = $relativePath;
$step = new RmStep();
$step->path = $relativePath;

self::expectException( BlueprintException::class );
self::expectExceptionMessage( "Failed to remove \"$absolutePath\": the directory or file does not exist." );
$this->step_runner->run( $step );
}
$this->step_runner->run( $step );
}
}
11 changes: 6 additions & 5 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 Down Expand Up @@ -35,7 +36,7 @@ class UnzipStepRunnerTest extends PHPUnitTestCase {
private $filesystem;

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

Expand Down Expand Up @@ -82,11 +83,11 @@ public function testUnzipFileWhenUsingRelativePath() {
$this->resource_manager->method( 'getStream' )
->willReturn( fopen( $zip, 'rb' ) );

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

$this->step_runner->run( $input, new Tracker() );
$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 );
Expand Down

0 comments on commit e6bf884

Please sign in to comment.