Skip to content

Commit 6c516f8

Browse files
committed
Separate creating files and folders from package() method
1 parent f38f36d commit 6c516f8

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/test/php/com/amazon/aws/lambda/unittest/PackagingTest.class.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ private function cleanup() {
2222
$this->tempDir->unlink();
2323
}
2424

25-
/** Creates package from given source definitions */
26-
private function package(array $definitions): ZipIterator {
25+
/** Creates files and directory from given definitions */
26+
private function create(array $definitions): Path {
2727

2828
// Create sources from definitions
2929
foreach ($definitions as $name => $definition) {
@@ -38,12 +38,18 @@ private function package(array $definitions): ZipIterator {
3838
}
3939
}
4040

41+
return new Path($this->tempDir);
42+
}
43+
44+
/** Creates package from given sources */
45+
private function package(Sources $sources): ZipIterator {
46+
4147
// Run packaging command
4248
$target= new Path($this->tempDir, 'test.zip');
4349
$out= Console::$out->stream();
4450
Console::$out->redirect(new MemoryOutputStream());
4551
try {
46-
$cmd= new PackageLambda($target, new Sources(new Path($this->tempDir), array_keys($definitions)));
52+
$cmd= new PackageLambda($target, $sources);
4753
$cmd->run();
4854
} finally {
4955
Console::$out->redirect($out);
@@ -54,7 +60,7 @@ private function package(array $definitions): ZipIterator {
5460

5561
#[Test]
5662
public function single_file() {
57-
$zip= $this->package(['file.txt' => ['file', 'Test']]);
63+
$zip= $this->package(new Sources($this->create(['file.txt' => ['file', 'Test']]), ['file.txt']));
5864

5965
$file= $zip->next();
6066
Assert::equals('file.txt', $file->getName());
@@ -63,7 +69,7 @@ public function single_file() {
6369

6470
#[Test]
6571
public function single_directory() {
66-
$zip= $this->package(['src' => ['dir', 0755]]);
72+
$zip= $this->package(new Sources($this->create(['src' => ['dir', 0755]]), ['src']));
6773

6874
$dir= $zip->next();
6975
Assert::equals('src'.DIRECTORY_SEPARATOR, $dir->getName());
@@ -72,10 +78,11 @@ public function single_directory() {
7278

7379
#[Test]
7480
public function file_inside_directory() {
75-
$zip= $this->package([
81+
$path= $this->create([
7682
'src' => ['dir', 0755],
7783
'src/file.txt' => ['file', 'Test']
7884
]);
85+
$zip= $this->package(new Sources($path, ['src']));
7986

8087
$dir= $zip->next();
8188
Assert::equals('src'.DIRECTORY_SEPARATOR, $dir->getName());

0 commit comments

Comments
 (0)