| @@ 15-49 (lines=35) @@ | ||
| 12 | $I->amInPath(codecept_data_dir().'sandbox'); |
|
| 13 | } |
|
| 14 | ||
| 15 | public function toRunMultipleTasksViaACollectionBuilder(CliGuy $I) |
|
| 16 | { |
|
| 17 | // This tests creating multiple tasks in a single builder, |
|
| 18 | // which implicitly adds them to a collection. To keep things |
|
| 19 | // simple, we are only going to use taskFilesystemStack. It |
|
| 20 | // would be possible, of course, to do these operations with |
|
| 21 | // a single FilesystemStack, but our goal is to test creating |
|
| 22 | // multiple tasks with a builder, and ensure that a propper |
|
| 23 | // collection is built. |
|
| 24 | $collection = $I->collectionBuilder(); |
|
| 25 | $result = $collection->taskFilesystemStack() |
|
| 26 | ->mkdir('a') |
|
| 27 | ->touch('a/a.txt') |
|
| 28 | ->rollback( |
|
| 29 | $I->taskDeleteDir('a') |
|
| 30 | ) |
|
| 31 | ->taskFilesystemStack() |
|
| 32 | ->mkdir('a/b') |
|
| 33 | ->touch('a/b/b.txt') |
|
| 34 | ->taskFilesystemStack() |
|
| 35 | ->mkdir('a/c') |
|
| 36 | ->touch('a/c/c.txt') |
|
| 37 | ->run(); |
|
| 38 | ||
| 39 | $I->assertEquals(0, $result->getExitCode(), $result->getMessage()); |
|
| 40 | ||
| 41 | // All of the tasks created by the builder should be added |
|
| 42 | // to a collection, and `run()` should run them all. |
|
| 43 | $I->seeDirFound('a'); |
|
| 44 | $I->seeFileFound('a/a.txt'); |
|
| 45 | $I->seeDirFound('a/b'); |
|
| 46 | $I->seeFileFound('a/b/b.txt'); |
|
| 47 | $I->seeDirFound('a/c'); |
|
| 48 | $I->seeFileFound('a/c/c.txt'); |
|
| 49 | } |
|
| 50 | ||
| 51 | public function toUseAWorkingDirWithACollectionBuilder(CliGuy $I) |
|
| 52 | { |
|
| @@ 82-111 (lines=30) @@ | ||
| 79 | $I->seeFileFound('build/a/c/c.txt'); |
|
| 80 | } |
|
| 81 | ||
| 82 | public function toRollbackAfterFailureViaACollectionBuilder(CliGuy $I) |
|
| 83 | { |
|
| 84 | // This is like the previous test, toRunMultipleTasksViaACollectionBuilder, |
|
| 85 | // except we force an error at the end, and confirm that the |
|
| 86 | // rollback function is called. |
|
| 87 | $collection = $I->collectionBuilder(); |
|
| 88 | $result = $collection->taskFilesystemStack() |
|
| 89 | ->mkdir('j') |
|
| 90 | ->touch('j/j.txt') |
|
| 91 | ->rollback( |
|
| 92 | $I->taskDeleteDir('j') |
|
| 93 | ) |
|
| 94 | ->taskFilesystemStack() |
|
| 95 | ->mkdir('j/k') |
|
| 96 | ->touch('j/k/k.txt') |
|
| 97 | ->taskFilesystemStack() |
|
| 98 | ->mkdir('j/k/m') |
|
| 99 | ->touch('j/k/m/m.txt') |
|
| 100 | ->taskCopyDir(['doesNotExist' => 'copied']) |
|
| 101 | ->run(); |
|
| 102 | ||
| 103 | $I->assertEquals(1, $result->getExitCode(), $result->getMessage()); |
|
| 104 | ||
| 105 | // All of the tasks created by the builder should be added |
|
| 106 | // to a collection, and `run()` should run them all. |
|
| 107 | $I->dontSeeFileFound('q/q.txt'); |
|
| 108 | $I->dontSeeFileFound('j/j.txt'); |
|
| 109 | $I->dontSeeFileFound('j/k/k.txt'); |
|
| 110 | $I->dontSeeFileFound('j/k/m/m.txt'); |
|
| 111 | } |
|
| 112 | ||
| 113 | public function toRollbackAWorkingDir(CliGuy $I) |
|
| 114 | { |
|