Refactoring

This commit is contained in:
gamonoid
2017-09-03 20:39:22 +02:00
parent af40881847
commit a7274d3cfd
5075 changed files with 238202 additions and 16291 deletions

View File

@@ -0,0 +1,24 @@
<?php
$I = new CliGuy($scenario);
$I->wantTo('minify a css file');
$I->amInPath(codecept_data_dir().'sandbox');
$sampleCss = dirname(__DIR__) . '/_data/sample.css';
$outputCss = 'minifiedSample.css';
$initialFileSize = filesize($sampleCss);
$I->taskMinify($sampleCss)
->to('minifiedSample.css')
->run();
$I->seeFileFound($outputCss);
$minifiedFileSize = filesize($outputCss);
$outputCssContents = file_get_contents($outputCss);
$I->assertLessThan($initialFileSize, $minifiedFileSize, 'Minified file is smaller than the source file');
$I->assertGreaterThan(0, $minifiedFileSize, 'Minified file is not empty');
$I->assertContains('body', $outputCssContents, 'Minified file has some content from the source file');
$I->assertNotContains('Sample css file', $outputCssContents, 'Minified file does not contain comment from source file');

View File

@@ -0,0 +1,13 @@
<?php
$I = new CliGuy($scenario);
$I->wantTo('clean dir with DeleteDirTask');
$I->amInPath(codecept_data_dir());
$I->seeFileFound('robo.txt', 'sandbox');
$I->taskCleanDir(['sandbox'])
->run();
$I->dontSeeFileFound('box', 'sandbox');
$I->dontSeeFileFound('robo.txt', 'sandbox');
$I->dontSeeFileFound('a.txt' , 'sandbox');

View File

@@ -0,0 +1,409 @@
<?php
namespace Robo;
use \CliGuy;
use Robo\Contract\TaskInterface;
use Robo\Collection\Temporary;
use Robo\Result;
class CollectionCest
{
public function _before(CliGuy $I)
{
$I->amInPath(codecept_data_dir().'sandbox');
}
public function toRunMultipleTasksViaACollectionBuilder(CliGuy $I)
{
// This tests creating multiple tasks in a single builder,
// which implicitly adds them to a collection. To keep things
// simple, we are only going to use taskFilesystemStack. It
// would be possible, of course, to do these operations with
// a single FilesystemStack, but our goal is to test creating
// multiple tasks with a builder, and ensure that a propper
// collection is built.
$collection = $I->collectionBuilder();
$result = $collection->taskFilesystemStack()
->mkdir('a')
->touch('a/a.txt')
->rollback(
$I->taskDeleteDir('a')
)
->taskFilesystemStack()
->mkdir('a/b')
->touch('a/b/b.txt')
->taskFilesystemStack()
->mkdir('a/c')
->touch('a/c/c.txt')
->run();
$I->assertEquals(0, $result->getExitCode(), $result->getMessage());
// All of the tasks created by the builder should be added
// to a collection, and `run()` should run them all.
$I->seeDirFound('a');
$I->seeFileFound('a/a.txt');
$I->seeDirFound('a/b');
$I->seeFileFound('a/b/b.txt');
$I->seeDirFound('a/c');
$I->seeFileFound('a/c/c.txt');
}
public function toUseAWorkingDirWithACollectionBuilder(CliGuy $I)
{
// Run the same test with a working directory. The working
// directory path will point to a temporary directory which
// will be moved into place once the tasks complete.
$collection = $I->collectionBuilder();
$workDirPath = $collection->workDir("build");
$I->assertNotEquals("build", basename($workDirPath));
$result = $collection->taskFilesystemStack()
->mkdir("{$workDirPath}/a")
->touch("{$workDirPath}/a/a.txt")
->taskFilesystemStack()
->mkdir("{$workDirPath}/a/b")
->touch("{$workDirPath}/a/b/b.txt")
->taskFilesystemStack()
->mkdir("{$workDirPath}/a/c")
->touch("{$workDirPath}/a/c/c.txt")
->run();
$I->assertEquals(0, $result->getExitCode(), $result->getMessage());
// All of the tasks created by the builder should be added
// to a collection, and `run()` should run them all.
$I->seeDirFound('build/a');
$I->seeFileFound('build/a/a.txt');
$I->seeDirFound('build/a/b');
$I->seeFileFound('build/a/b/b.txt');
$I->seeDirFound('build/a/c');
$I->seeFileFound('build/a/c/c.txt');
}
public function toRollbackAfterFailureViaACollectionBuilder(CliGuy $I)
{
// This is like the previous test, toRunMultipleTasksViaACollectionBuilder,
// except we force an error at the end, and confirm that the
// rollback function is called.
$collection = $I->collectionBuilder();
$result = $collection->taskFilesystemStack()
->mkdir('j')
->touch('j/j.txt')
->rollback(
$I->taskDeleteDir('j')
)
->taskFilesystemStack()
->mkdir('j/k')
->touch('j/k/k.txt')
->taskFilesystemStack()
->mkdir('j/k/m')
->touch('j/k/m/m.txt')
->taskCopyDir(['doesNotExist' => 'copied'])
->run();
$I->assertEquals(1, $result->getExitCode(), $result->getMessage());
// All of the tasks created by the builder should be added
// to a collection, and `run()` should run them all.
$I->dontSeeFileFound('q/q.txt');
$I->dontSeeFileFound('j/j.txt');
$I->dontSeeFileFound('j/k/k.txt');
$I->dontSeeFileFound('j/k/m/m.txt');
}
public function toRollbackAWorkingDir(CliGuy $I)
{
// Run the same test with a working directory. The working
// directory path will point to a temporary directory which
// will be moved into place once the tasks complete.
$collection = $I->collectionBuilder();
$workDirPath = $collection->workDir("build");
$I->assertNotEquals("build", basename($workDirPath));
$result = $collection->taskFilesystemStack()
->mkdir("{$workDirPath}/a")
->touch("{$workDirPath}/a/a.txt")
->taskFilesystemStack()
->mkdir("{$workDirPath}/a/b")
->touch("{$workDirPath}/a/b/b.txt")
->taskFilesystemStack()
->mkdir("{$workDirPath}/a/c")
->touch("{$workDirPath}/a/c/c.txt")
->taskCopyDir(['doesNotExist' => 'copied'])
->run();
$I->assertEquals(1, $result->getExitCode(), $result->getMessage());
// All of the tasks created by the builder should be added
// to a collection, and `run()` should run them all.
$I->dontSeeFileFound('build/a');
$I->dontSeeFileFound($workDirPath);
}
public function toBuildFilesViaAddIterable(CliGuy $I)
{
$processList = ['cats', 'dogs', 'sheep', 'fish', 'horses', 'cows'];
$collection = $I->collectionBuilder();
$result = $collection
->taskFilesystemStack()
->mkdir('stuff')
->taskForEach($processList)
->withBuilder(
function ($builder, $key, $value) {
return $builder
->taskFilesystemStack()
->touch("stuff/{$value}.txt");
}
)
->run();
$I->assertEquals(0, $result->getExitCode(), $result->getMessage());
$I->seeFileFound('stuff/cats.txt');
$I->seeFileFound('stuff/dogs.txt');
$I->seeFileFound('stuff/sheep.txt');
$I->seeFileFound('stuff/fish.txt');
$I->seeFileFound('stuff/horses.txt');
$I->seeFileFound('stuff/cows.txt');
}
public function toRollbackANestedCollection(CliGuy $I)
{
// This is like the previous test, toRunMultipleTasksViaACollectionBuilder,
// except we force an error at the end, and confirm that the
// rollback function is called.
$collection = $I->collectionBuilder();
$collection->taskFilesystemStack()
->mkdir('j')
->touch('j/j.txt')
->rollback(
$I->taskDeleteDir('j')
)
->taskFilesystemStack()
->mkdir('j/k')
->touch('j/k/k.txt')
->taskFilesystemStack()
->mkdir('j/k/m')
->touch('j/k/m/m.txt');
$result = $I->collectionBuilder()
->taskFilesystemStack()
->mkdir('q')
->touch('q/q.txt')
->addTask($collection)
->taskCopyDir(['doesNotExist' => 'copied'])
->run();
$I->assertEquals(1, $result->getExitCode(), $result->getMessage());
// All of the tasks created by the builder should be added
// to a collection, and `run()` should run them all.
$I->seeFileFound('q/q.txt');
$I->dontSeeFileFound('j/j.txt');
$I->dontSeeFileFound('j/k/k.txt');
$I->dontSeeFileFound('j/k/m/m.txt');
}
public function toCreateDirViaCollection(CliGuy $I)
{
// Set up a collection to add tasks to
$collection = $I->collectionBuilder();
// Set up a filesystem stack
$collection->taskFilesystemStack()
->mkdir('log')
->touch('log/error.txt');
// FilesystemStack has not run yet, so file should not be found.
$I->dontSeeFileFound('log/error.txt');
// Run the task collection; now the files should be present
$collection->run();
$I->seeFileFound('log/error.txt');
$I->seeDirFound('log');
}
public function toUseATmpDirAndConfirmItIsDeleted(CliGuy $I)
{
// Set up a collection to add tasks to
$collection = $I->collectionBuilder();
// Get a temporary directory to work in. Note that we get a
// name back, but the directory is not created until the task
// runs. This technically is not thread-safe, but we create
// a random name, so it is unlikely to conflict.
$tmpPath = $collection->tmpDir();
// Set up a filesystem stack, but use a collection to defer execution
$collection->taskFilesystemStack()
->mkdir("$tmpPath/tmp")
->touch("$tmpPath/tmp/error.txt")
->rename("$tmpPath/tmp", "$tmpPath/log");
// Copy our tmp directory to a location that is not transient
$collection->taskCopyDir([$tmpPath => 'copied']);
// FilesystemStack has not run yet, so no files should be found.
$I->dontSeeFileFound("$tmpPath/tmp/error.txt");
$I->dontSeeFileFound("$tmpPath/log/error.txt");
$I->dontSeeFileFound('copied/log/error.txt');
// Run the task collection
$result = $collection->run();
$I->assertEquals(0, $result->getExitCode(), $result->getMessage());
$I->assertEquals($result['path'], $tmpPath, "Tmp dir result matches accessor.");
// The file 'error.txt' should have been copied into the "copied" dir.
// This also proves that the tmp directory was created.
$I->seeFileFound('copied/log/error.txt');
// $tmpPath should be deleted after $collection->run() completes.
$I->dontSeeFileFound("$tmpPath/tmp/error.txt");
$I->dontSeeFileFound("$tmpPath/log/error.txt");
$I->dontSeeFileFound("$tmpPath");
}
public function toUseATmpDirAndChangeWorkingDirectory(CliGuy $I)
{
// Set up a collection to add tasks to
$collection = $I->collectionBuilder();
$cwd = getcwd();
$tmpPath = $collection->taskTmpDir()
->cwd()
->getPath();
// Set up a filesystem stack, but use a collection to defer execution.
// Note that since we used 'cwd()' above, the relative file paths
// used below will be inside the temporary directory.
$collection->taskFilesystemStack()
->mkdir("log")
->touch("log/error.txt");
// Copy our tmp directory to a location that is not transient
$collection->taskCopyDir(['log' => "$cwd/copied2"]);
// FilesystemStack has not run yet, so no files should be found.
$I->dontSeeFileFound("$tmpPath/log/error.txt");
$I->dontSeeFileFound('$cwd/copied2/log/error.txt');
// Run the task collection
$result = $collection->run();
$I->assertEquals(0, $result->getExitCode(), $result->getMessage());
// The file 'error.txt' should have been copied into the "copied" dir
$I->seeFileFound("$cwd/copied2/error.txt");
// $tmpPath should be deleted after $collection->run() completes.
$I->dontSeeFileFound("$tmpPath/log/error.txt");
// Make sure that 'log' was created in the temporary directory, not
// at the current working directory.
$I->dontSeeFileFound("$cwd/log/error.txt");
// Make sure that our working directory was restored.
$finalWorkingDir = getcwd();
$I->assertEquals($cwd, $finalWorkingDir);
}
public function toCreateATmpFileAndConfirmItIsDeleted(CliGuy $I)
{
// Set up a collection to add tasks to
$collection = $I->collectionBuilder();
// Write to a temporary file. Note that we can get the path
// to the tempoary file that will be created, even though the
// the file is not created until the task collecction runs.
$tmpPath = $collection->taskTmpFile('tmp', '.txt')
->line("This is a test file")
->getPath();
// Copy our tmp directory to a location that is not transient
$collection->taskFilesystemStack()
->copy($tmpPath, 'copied.txt');
// FilesystemStack has not run yet, so no files should be found.
$I->dontSeeFileFound("$tmpPath");
$I->dontSeeFileFound('copied.txt');
// Run the task collection
$result = $collection->run();
$I->assertEquals(0, $result->getExitCode(), $result->getMessage());
// The file 'copied.txt' should have been copied from the tmp file
$I->seeFileFound('copied.txt');
// $tmpPath should be deleted after $collection->run() completes.
$I->dontSeeFileFound("$tmpPath");
}
public function toUseATmpDirWithAlternateSyntax(CliGuy $I)
{
$collection = $I->collectionBuilder();
// This test is equivalent to toUseATmpDirAndConfirmItIsDeleted,
// but uses a different technique to create a collection of tasks.
$tmpPath = $collection->tmpDir();
// Now, rather than creating the tasks with a collection builder,
// which automatically adds the tasks to the collection as they are
// created, we will instead create them individually and then add
// them to the collection via the addTaskList() method.
$result = $collection->addTaskList(
[
$I->taskFilesystemStack()->mkdir("$tmpPath/log")->touch("$tmpPath/log/error.txt"),
$I->taskCopyDir([$tmpPath => 'copied3']),
]
)->run();
// The results of this operation should be the same.
$I->assertEquals(0, $result->getExitCode(), $result->getMessage());
$I->seeFileFound('copied3/log/error.txt');
$I->dontSeeFileFound("$tmpPath/log/error.txt");
}
public function toCreateATmpDirWithoutACollection(CliGuy $I)
{
// Create a temporary directory, using our function name as
// the prefix for the directory name.
$tmpDirTask = $I->taskTmpDir(__FUNCTION__);
$tmpPath = $tmpDirTask->getPath();
$I->dontSeeFileFound($tmpPath);
$tmpDirTask->run();
$I->seeDirFound($tmpPath);
// Creating a temporary directory without a task collection will
// cause the temporary directory to be deleted when the program
// terminates. We can force it to clean up sooner by calling
// TransientManager::complete(); note that this deletes ALL global tmp
// directories, so this is not thread-safe! Useful in tests, though.
Temporary::complete();
$I->dontSeeFileFound($tmpPath);
}
public function toCreateATmpDirUsingShortcut(CliGuy $I)
{
// Create a temporary directory, using our function name as
// the prefix for the directory name.
$tmpPath = $I->shortcutTmpDir(__FUNCTION__);
$I->seeDirFound($tmpPath);
// Creating a temporary directory without a task collection will
// cause the temporary directory to be deleted when the program
// terminates. We can force it to clean up sooner by calling
// TransientManager::complete(); note that this deletes ALL global tmp
// directories, so this is not thread-safe! Useful in tests, though.
Temporary::complete();
$I->dontSeeFileFound($tmpPath);
}
public function toThrowAnExceptionAndConfirmItIsCaught(CliGuy $I)
{
$collection = $I->getContainer()->get('collection');
$collection->addCode(
function () {
throw new \RuntimeException('Error');
}
);
$result = $collection->run();
$I->assertEquals('Error', $result->getMessage());
$I->assertEquals(1, $result->getExitCode());
}
}

View File

@@ -0,0 +1,11 @@
<?php
$I = new CliGuy($scenario);
$I->wantTo('concat files using Concat Task');
$I->amInPath(codecept_data_dir() . 'sandbox');
$I->taskConcat(['a.txt', 'b.txt'])
->to('merged.txt')
->run();
$I->seeFileFound('merged.txt');
$I->seeFileContentsEqual("A\nB\n");

View File

@@ -0,0 +1,10 @@
<?php
$I = new CliGuy($scenario);
$I->wantTo('copy dir with CopyDir task');
$I->amInPath(codecept_data_dir().'sandbox');
$I->taskCopyDir(['box' => 'bin'])
->run();
$I->seeDirFound('bin');
$I->seeFileFound('robo.txt', 'bin');

View File

@@ -0,0 +1,12 @@
<?php
$I = new CliGuy($scenario);
$I->wantTo('overwrite a file with CopyDir task');
$I->amInPath(codecept_data_dir() . 'sandbox');
$I->seeDirFound('some');
$I->seeFileFound('existing_file', 'some');
$I->taskCopyDir(['some' => 'some_destination'])
->run();
$I->seeFileFound('existing_file', 'some_destination/deeply');
$I->openFile('some_destination/deeply/existing_file');
$I->seeInThisFile('some existing file');

View File

@@ -0,0 +1,11 @@
<?php
$I = new CliGuy($scenario);
$I->wantTo('copy dir recursively with CopyDir task');
$I->amInPath(codecept_data_dir() . 'sandbox');
$I->seeDirFound('some/deeply/nested');
$I->seeFileFound('structu.re', 'some/deeply/nested');
$I->taskCopyDir(['some/deeply' => 'some_destination/deeply'])
->run();
$I->seeDirFound('some_destination/deeply/nested');
$I->seeFileFound('structu.re', 'some_destination/deeply/nested');

View File

@@ -0,0 +1,11 @@
<?php
$I = new CliGuy($scenario);
$container = Robo\Robo::getContainer();
$I->wantTo('delete dir with DeleteDirTask');
$I->amInPath(codecept_data_dir());
$I->seeFileFound('robo.txt', 'sandbox');
$I->taskDeleteDir(['sandbox/box'])
->run();
$I->dontSeeFileFound('box', 'sandbox');
$I->dontSeeFileFound('robo.txt', 'sandbox');

View File

@@ -0,0 +1,13 @@
<?php
class ExecCest
{
// tests
public function toExecLsCommand(CliGuy $I)
{
$command = strncasecmp(PHP_OS, 'WIN', 3) == 0 ? 'dir' : 'ls';
$res = $I->taskExec($command)->run();
verify($res->getMessage())->contains('src');
verify($res->getMessage())->contains('codeception.yml');
}
}

View File

@@ -0,0 +1,50 @@
<?php
class FilesystemStackCest
{
public function _before(CliGuy $I)
{
$I->amInPath(codecept_data_dir().'sandbox');
}
public function toCreateDir(CliGuy $I)
{
$I->taskFilesystemStack()
->mkdir('log')
->touch('log/error.txt')
->run();
$I->seeFileFound('log/error.txt');
}
public function toDeleteFile(CliGuy $I)
{
$I->taskFilesystemStack()
->stopOnFail()
->remove('a.txt')
->run();
$I->dontSeeFileFound('a.txt');
}
public function toTestCrossVolumeRename(CliGuy $I)
{
$fsStack = $I->taskFilesystemStack()
->mkdir('log')
->touch('log/error.txt');
$fsStack->run();
// We can't force _rename to run the cross-volume
// code path, so we will directly call the protected
// method crossVolumeRename to test to ensure it works.
// We will get a reference to it via reflection, set
// the reflected method object to public, and then
// call it via reflection.
$class = new ReflectionClass('\Robo\Task\Filesystem\FilesystemStack');
$method = $class->getMethod('crossVolumeRename');
$method->setAccessible(true);
$actualFsStackTask = $fsStack->getCollectionBuilderCurrentTask();
$method->invokeArgs($actualFsStackTask, ['log', 'logfiles']);
$I->dontSeeFileFound('log/error.txt');
$I->seeFileFound('logfiles/error.txt');
}
}

View File

@@ -0,0 +1,14 @@
<?php
$I = new CliGuy($scenario);
$I->wantTo('flatten dir with FlattenDir task');
$I->amInPath(codecept_data_dir().'sandbox');
$I->taskFlattenDir([
'some/deeply/nested/*.re' => 'flattened',
'*.txt' => 'flattened'
])
->run();
$I->seeDirFound('flattened');
$I->seeFileFound('structu.re', 'flattened');
$I->seeFileFound('a.txt', 'flattened');
$I->seeFileFound('b.txt', 'flattened');

View File

@@ -0,0 +1,12 @@
<?php
$I = new CliGuy($scenario);
$I->wantTo('flatten dir with FlattenDir task including parents');
$I->amInPath(codecept_data_dir().'sandbox');
$I->taskFlattenDir('some/deeply/nested/*.re')
->includeParents(array(1,1))
->parentDir('some')
->to('flattened')
->run();
$I->seeDirFound('flattened/deeply/nested');
$I->seeFileFound('structu.re', 'flattened/deeply/nested');

View File

@@ -0,0 +1,11 @@
<?php
class GenTaskCest
{
// tests
public function toTestTaskGeneration(CliGuy $I)
{
$result = $I->taskGenTask('Symfony\Component\Filesystem\Filesystem', 'FilesystemStack')->run();
verify($result->getMessage())->contains('protected function _chgrp($files, $group, $recursive = false)');
}
}

View File

@@ -0,0 +1,86 @@
<?php
namespace Robo;
use \CliGuy;
use Robo\Contract\TaskInterface;
use Robo\Collection\Temporary;
use Robo\Result;
class GenerateMarkdownDocCest
{
public function _before(CliGuy $I)
{
$I->amInPath(codecept_data_dir().'sandbox');
}
public function toGenerateDocumentation(CliGuy $I)
{
$sourceFile = codecept_data_dir() . 'TestedRoboTask.php';
$I->seeFileFound($sourceFile);
include $sourceFile;
$I->assertTrue(class_exists('TestedRoboTask'));
$collection = $I->collectionBuilder();
$taskGenerator = $collection->taskGenDoc("TestedRoboTask.md");
$taskGenerator->filterClasses(function (\ReflectionClass $r) {
return !($r->isAbstract() || $r->isTrait()) && $r->implementsInterface('Robo\Contract\TaskInterface');
})->prepend("# TestedRoboTask Tasks");
$taskGenerator->docClass('TestedRoboTask');
$taskGenerator->filterMethods(
function (\ReflectionMethod $m) {
if ($m->isConstructor() || $m->isDestructor() || $m->isStatic()) {
return false;
}
$undocumentedMethods =
[
'',
'run',
'__call',
'inflect',
'injectDependencies',
'getCommand',
'getPrinted',
'getConfig',
'setConfig',
'logger',
'setLogger',
'setProgressIndicator',
'progressIndicatorSteps',
'setBuilder',
'getBuilder',
'collectionBuilder',
];
return !in_array($m->name, $undocumentedMethods) && $m->isPublic(); // methods are not documented
}
)->processClassSignature(
function ($c) {
return "## " . preg_replace('~Task$~', '', $c->getShortName()) . "\n";
}
)->processClassDocBlock(
function (\ReflectionClass $c, $doc) {
$doc = preg_replace('~@method .*?(.*?)\)~', '* `$1)` ', $doc);
$doc = str_replace('\\'.$c->name, '', $doc);
return $doc;
}
)->processMethodSignature(
function (\ReflectionMethod $m, $text) {
return str_replace('#### *public* ', '* `', $text) . '`';
}
)->processMethodDocBlock(
function (\ReflectionMethod $m, $text) {
return $text ? ' ' . trim(strtok($text, "\n"), "\n") : '';
}
);
$collection->run();
$I->seeFileFound('TestedRoboTask.md');
$contents = file_get_contents('TestedRoboTask.md');
$I->assertContains('A test task file. Used for testig documentation generation.', $contents);
$I->assertContains('taskTestedRoboTask', $contents);
$I->assertContains('Set the destination file', $contents);
}
}

View File

@@ -0,0 +1,57 @@
<?php
$I = new CliGuy($scenario);
$I->wantTo('archive directory and then extract it again with Archive and Extract tasks');
$I->amInPath(codecept_data_dir().'sandbox');
$I->seeDirFound('some/deeply/nested');
$I->seeFileFound('structu.re', 'some/deeply/nested');
$I->seeFileFound('existing_file', 'some/deeply');
// Test a bunch of archive types that we support
foreach (['zip', 'tar', 'tar.gz', 'tar.bz2', 'tgz'] as $archiveType) {
// First, take everything from the folder 'some/deeply' and make
// an archive for it located in 'deep'
$I->taskPack("deeply.$archiveType")
->add(['deep' => 'some/deeply'])
->run();
$I->seeFileFound("deeply.$archiveType");
// We are next going to extract the archive we created, this time
// putting it into a folder called "extracted-$archiveType" (different
// for each archive type we test). We rely on the default behavior
// of our extractor to remove the top-level directory in the archive
// ("deeply").
$I->taskExtract("deeply.$archiveType")
->to("extracted-$archiveType")
->preserveTopDirectory(false) // this is the default
->run();
$I->seeDirFound("extracted-$archiveType");
$I->seeDirFound("extracted-$archiveType/nested");
$I->seeFileFound('structu.re', "extracted-$archiveType/nested");
// Next, we'll extract the same archive again, this time preserving
// the top-level folder.
$I->taskExtract("deeply.$archiveType")
->to("preserved-$archiveType")
->preserveTopDirectory()
->run();
$I->seeDirFound("preserved-$archiveType");
$I->seeDirFound("preserved-$archiveType/deep/nested");
$I->seeFileFound('structu.re', "preserved-$archiveType/deep/nested");
// Make another archive, this time composed of fanciful locations
$I->taskPack("composed.$archiveType")
->add(['a/b/existing_file' => 'some/deeply/existing_file'])
->add(['x/y/z/structu.re' => 'some/deeply/nested/structu.re'])
->run();
$I->seeFileFound("composed.$archiveType");
// Extract our composed archive, and see if the resulting file
// structure matches expectations.
$I->taskExtract("composed.$archiveType")
->to("decomposed-$archiveType")
->preserveTopDirectory()
->run();
$I->seeDirFound("decomposed-$archiveType");
$I->seeDirFound("decomposed-$archiveType/x/y/z");
$I->seeFileFound('structu.re', "decomposed-$archiveType/x/y/z");
$I->seeDirFound("decomposed-$archiveType/a/b");
$I->seeFileFound('existing_file', "decomposed-$archiveType/a/b");
}

View File

@@ -0,0 +1,25 @@
<?php
class ShortcutsCest
{
public function _before(CliGuy $I)
{
$I->amInPath(codecept_data_dir('sandbox'));
}
public function useTheCopyDirShortcut(CliGuy $I)
{
$I->wantTo('copy dir with _copyDir shortcut');
$I->shortcutCopyDir('box', 'bin');
$I->seeDirFound('bin');
$I->seeFileFound('robo.txt', 'bin');
}
public function useTheMirrorDirShortcut(CliGuy $I)
{
$I->wantTo('mirror dir with _mirrorDir shortcut');
$I->shortcutMirrorDir('box', 'bin');
$I->seeDirFound('bin');
$I->seeFileFound('robo.txt', 'bin');
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Robo;
use \CliGuy;
use Robo\Contract\TaskInterface;
use Robo\Collection\Temporary;
use Robo\Result;
class SimulatedCest
{
public function _before(CliGuy $I)
{
$I->amInPath(codecept_data_dir().'sandbox');
}
public function toSimulateDirCreation(CliGuy $I)
{
// Set up a collection to add tasks to
$collection = $I->collectionBuilder();
$collection->simulated(true);
// Set up a filesystem stack
$collection->taskFilesystemStack()
->mkdir('simulatedir')
->touch('simulatedir/error.txt');
// Run the task collection; now the files should be present
$collection->run();
// Nothing should be created in simulated mode
$I->dontSeeFileFound('simulatedir/error.txt');
$I->seeInOutput('[Simulator] Simulating Filesystem\FilesystemStack()');
}
}

View File

@@ -0,0 +1,111 @@
<?php
class WriteFileCest {
public function _before(CliGuy $I)
{
$I->amInPath(codecept_data_dir('sandbox'));
}
public function writeFewLines(CliGuy $I)
{
$I->wantTo('write lines with WriteToFile task');
$I->taskWriteToFile('blogpost.md')
->line('****')
->line('hello world')
->line('****')
->run();
$I->seeFileFound('blogpost.md');
$I->seeFileContentsEqual(<<<HERE
****
hello world
****
HERE
);
}
public function appendToFile(CliGuy $I)
{
$I->taskWriteToFile('a.txt')
->append()
->line('hello world')
->run();
$I->seeFileFound('a.txt');
$I->seeFileContentsEqual(<<<HERE
Ahello world
HERE
);
}
public function testWouldChange(CliGuy $I)
{
$writeTask = $I->taskWriteToFile('a.txt')
->append();
$I->assertEquals(false, $writeTask->wouldChange(), "No changes to test file.");
$writeTask->line('hello world');
$I->assertEquals(true, $writeTask->wouldChange(), "Test file would change.");
}
public function insertFile(CliGuy $I)
{
$I->taskWriteToFile('a.txt')
->line('****')
->textFromFile('b.txt')
->line("C")
->run();
$I->seeFileFound('a.txt');
$I->seeFileContentsEqual(<<<HERE
****
BC
HERE
);
}
public function appendIfMatch(CliGuy $I)
{
$I->wantTo('append lines with WriteToFile task, but only if pattern does not match');
$I->taskWriteToFile('blogpost.md')
->line('****')
->line('hello world')
->line('****')
->appendUnlessMatches('/hello/', 'Should not add this')
->appendUnlessMatches('/goodbye/', 'Should add this')
->appendIfMatches('/hello/', ' and should also add this')
->appendIfMatches('/goodbye/', ' but should not add this')
->appendIfMatches('/should/', '!')
->run();
$I->seeFileFound('blogpost.md');
$I->seeFileContentsEqual(<<<HERE
****
hello world
****
Should add this and should also add this!
HERE
);
}
public function replaceInFile(CliGuy $I)
{
$I->taskReplaceInFile('a.txt')
->from('A')
->to('B')
->run();
$I->seeFileFound('a.txt');
$I->seeFileContentsEqual('B');
}
public function replaceMultipleInFile(CliGuy $I)
{
$I->taskReplaceInFile('box/robo.txt')
->from(array('HELLO', 'ROBO'))
->to(array('Hello ', 'robo.li!'))
->run();
$I->seeFileFound('box/robo.txt');
$I->seeFileContentsEqual('Hello robo.li!');
}
}

View File

@@ -0,0 +1,9 @@
<?php
// Here you can initialize variables that will for your tests
use Robo\Robo;
use Robo\Runner;
use League\Container\Container;
use Symfony\Component\Console\Input\StringInput;
$container = Robo::createDefaultContainer();