Skip to content

Commit

Permalink
Merge pull request #3 from solutionDrive/master
Browse files Browse the repository at this point in the history
Adding Feature to build a file-list during writing/splitting
  • Loading branch information
pastuhov committed Feb 17, 2017
2 parents b8a5ac4 + 7a248ee commit 33762d7
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/FileStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -65,13 +71,31 @@ public function __construct($fileName, $header = null, $footer = null, $maxCount
}
}

/**
* Adds the given Filename to the internal Array
* @param $filename
*/
protected function addFile($filename)
{
$this->files[] = $filename;
}

/**
* Returns the List of written Files
* @return array
*/
public function getFileList()
{
return $this->files;
}

/**
* @inheritdoc
*/
protected function openHandle()
{
parent::openHandle();

$this->addFile($this->getFileName());
if ($this->header !== null) {
$this->write($this->header, false);
}
Expand Down
29 changes: 29 additions & 0 deletions tests/FileStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
'<urlset>',
'</urlset>',
$amount
);

foreach ($urls = range(0, $amount * $amount - $amount) as $url) {
$stream->write(
'<url><loc>https://github.com?page' . $url . '</loc></url>' . PHP_EOL
);
}
return $stream;
}
}

0 comments on commit 33762d7

Please sign in to comment.