From 3876cb9c7886a6301ae0f0643be5e6551c48881f Mon Sep 17 00:00:00 2001 From: Matthias Alt Date: Sun, 18 Dec 2016 21:37:19 +0100 Subject: [PATCH 1/3] every opend file is added to the file-List. with getFileList all written files can be obtained --- src/FileStream.php | 29 ++++++++++++++++++++++++++++- tests/FileStreamTest.php | 29 +++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/FileStream.php b/src/FileStream.php index f25725f..4f87a07 100644 --- a/src/FileStream.php +++ b/src/FileStream.php @@ -45,6 +45,12 @@ class FileStream extends BaseFileStream */ protected $currentFileCount = 0; + /** + * List of Files + * @var array + */ + protected $files = []; + /** * @inheritdoc * @param string|null $header File header @@ -65,13 +71,34 @@ public function __construct($fileName, $header = null, $footer = null, $maxCount } } + /** + * Adds the given Filename to the internal Array + * @param $filename + */ + public function addFile($filename) + { + $this->files[] = $filename; + } + + /** + * Returns the List of written Files + * To get the correct count, all Files have to be closed + * so closeHandle is called + * @return array + */ + public function getFileList() + { + $this->closeHandle(); + return $this->files; + } + /** * @inheritdoc */ protected function openHandle() { parent::openHandle(); - + $this->addFile($this->getFileName()); if ($this->header !== null) { $this->write($this->header, false); } diff --git a/tests/FileStreamTest.php b/tests/FileStreamTest.php index 36ec0b6..0c2a687 100644 --- a/tests/FileStreamTest.php +++ b/tests/FileStreamTest.php @@ -81,4 +81,33 @@ public function testPlaceholderValidation() 3 ); } + + + public function testFilestreamGathersListOfFilenames() + { + $stream = $this->prepareStreamToGenerateAmountOfFiles(3); + + $this->assertCount(3, $stream->getFileList()); + } + + /** + * @param $amount + * @return FileStream + */ + private function prepareStreamToGenerateAmountOfFiles($amount) + { + $stream = new FileStream( + $this->runtimeDir . '/sitemap{count}.xml', + '', + '', + $amount + ); + + foreach ($urls = range(0, $amount * $amount - $amount) as $url) { + $stream->write( + 'https://github.com?page' . $url . '' . PHP_EOL + ); + } + return $stream; + } } From ad181b1ac1ca2ef79451d9bc25272db4377090fe Mon Sep 17 00:00:00 2001 From: Matthias Alt Date: Sun, 18 Dec 2016 21:40:06 +0100 Subject: [PATCH 2/3] it is not necessary to close the active handle --- src/FileStream.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/FileStream.php b/src/FileStream.php index 4f87a07..444a956 100644 --- a/src/FileStream.php +++ b/src/FileStream.php @@ -82,13 +82,10 @@ public function addFile($filename) /** * Returns the List of written Files - * To get the correct count, all Files have to be closed - * so closeHandle is called * @return array */ public function getFileList() { - $this->closeHandle(); return $this->files; } From a1d83236b5eefa09da8b10def88cdd3b51d364d5 Mon Sep 17 00:00:00 2001 From: Matthias Alt Date: Mon, 19 Dec 2016 09:57:37 +0100 Subject: [PATCH 3/3] Method can be protected --- src/FileStream.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FileStream.php b/src/FileStream.php index 444a956..2234b35 100644 --- a/src/FileStream.php +++ b/src/FileStream.php @@ -75,7 +75,7 @@ public function __construct($fileName, $header = null, $footer = null, $maxCount * Adds the given Filename to the internal Array * @param $filename */ - public function addFile($filename) + protected function addFile($filename) { $this->files[] = $filename; }