Skip to content

Commit

Permalink
[mms] Add unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Feb 4, 2014
1 parent 8a4f3b0 commit 35bc13a
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 3 deletions.
25 changes: 22 additions & 3 deletions framework/Stream_Wrapper/package.xml
Expand Up @@ -16,8 +16,7 @@
<email>slusarz@horde.org</email>
<active>yes</active>
</lead>
<date>2012-11-22</date>
<time>13:08:40</time>
<date>2014-02-04</date>
<version>
<release>2.1.0</release>
<api>2.1.0</api>
Expand All @@ -28,6 +27,7 @@
</stability>
<license uri="http://www.horde.org/licenses/bsd">BSD-2-Clause</license>
<notes>
* [mms] Add unit tests.
* [mms] Add Horde_Stream_Wrapper_Combine::getStream().
* [mms] Add Horde_Stream_Wrapper_String::getStream().
* [mms] Fix documentation regarding proper license for this package (BSD).
Expand Down Expand Up @@ -55,6 +55,19 @@
</dir> <!-- //lib/Horde/Stream -->
</dir> <!-- //lib/Horde -->
</dir> <!-- //lib -->
<dir name="test">
<dir name="Horde">
<dir name="Stream">
<dir name="Wrapper">
<file name="AllTests.php" role="test" />
<file name="bootstrap.php" role="test" />
<file name="CombineTest.php" role="test" />
<file name="phpunit.xml" role="test" />
<file name="StringTest.php" role="test" />
</dir> <!-- /test/Horde/Stream/Wrapper -->
</dir> <!-- /test/Horde/Stream -->
</dir> <!-- /test/Horde -->
</dir> <!-- /test -->
</dir> <!-- / -->
</contents>
<dependencies>
Expand All @@ -74,6 +87,11 @@
<install as="Horde/Stream/Wrapper/CombineStream.php" name="lib/Horde/Stream/Wrapper/CombineStream.php" />
<install as="Horde/Stream/Wrapper/String.php" name="lib/Horde/Stream/Wrapper/String.php" />
<install as="Horde/Stream/Wrapper/StringStream.php" name="lib/Horde/Stream/Wrapper/StringStream.php" />
<install as="Horde/Stream/Wrapper/AllTests.php" name="test/Horde/Stream/Wrapper/AllTests.php" />
<install as="Horde/Stream/Wrapper/bootstrap.php" name="test/Horde/Stream/Wrapper/bootstrap.php" />
<install as="Horde/Stream/Wrapper/CombineTest.php" name="test/Horde/Stream/Wrapper/CombineTest.php" />
<install as="Horde/Stream/Wrapper/phpunit.xml" name="test/Horde/Stream/Wrapper/phpunit.xml" />
<install as="Horde/Stream/Wrapper/StringTest.php" name="test/Horde/Stream/Wrapper/StringTest.php" />
</filelist>
</phprelease>
<changelog>
Expand Down Expand Up @@ -224,9 +242,10 @@
<stability>
<release>stable</release>
<api>stable</api></stability>
<date>2012-11-22</date>
<date>2014-02-04</date>
<license uri="http://www.horde.org/licenses/bsd">BSD-2-Clause</license>
<notes>
* [mms] Add unit tests.
* [mms] Add Horde_Stream_Wrapper_Combine::getStream().
* [mms] Add Horde_Stream_Wrapper_String::getStream().
* [mms] Fix documentation regarding proper license for this package (BSD).
Expand Down
@@ -0,0 +1,3 @@
<?php
require_once 'Horde/Test/AllTests.php';
Horde_Test_AllTests::init(__FILE__)->run();
51 changes: 51 additions & 0 deletions framework/Stream_Wrapper/test/Horde/Stream/Wrapper/CombineTest.php
@@ -0,0 +1,51 @@
<?php
/**
* Copyright 2009-2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (BSD). If you
* did not receive this file, see http://www.horde.org/licenses/bsd.
*
* @category Horde
* @copyright 2009-2014 Horde LLC
* @license http://www.horde.org/licenses/bsd BSD
* @package Stream_Wrapper
* @subpackage UnitTests
*/

/**
* Tests for the Combine wrapper.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2009-2014 Horde LLC
* @ignore
* @license http://www.horde.org/licenses/bsd BSD
* @package Stream_Wrapper
* @subpackage UnitTests
*/
class Horde_Stream_Wrapper_CombineTest extends PHPUnit_Framework_TestCase
{
public function testUsage()
{
$fp = fopen('php://temp', 'r+');
fwrite($fp, '12345');

$data = array('ABCDE', $fp, 'fghij');

$stream = Horde_Stream_Wrapper_Combine::getStream($data);

$this->assertEquals('ABCDE12345fghij', fread($stream, 1024));
$this->assertEquals(true, feof($stream));
$this->assertEquals(0, fseek($stream, 0));
$this->assertEquals(-1, fseek($stream, 0));
$this->assertEquals(0, ftell($stream));
$this->assertEquals(0, fseek($stream, 5, SEEK_CUR));
$this->assertEquals(5, ftell($stream));
$this->assertEquals(10, fwrite($stream, '0000000000'));
$this->assertEquals(0, fseek($stream, 0, SEEK_END));
$this->assertEquals(20, ftell($stream));
$this->assertEquals(false, feof($stream));

fclose($stream);
}
}
66 changes: 66 additions & 0 deletions framework/Stream_Wrapper/test/Horde/Stream/Wrapper/StringTest.php
@@ -0,0 +1,66 @@
<?php
/**
* Copyright 2008-2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (BSD). If you
* did not receive this file, see http://www.horde.org/licenses/bsd.
*
* @category Horde
* @copyright 2008-2014 Horde LLC
* @license http://www.horde.org/licenses/bsd BSD
* @package Stream_Wrapper
* @subpackage UnitTests
*/

/**
* Tests for the String wrapper.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2008-2014 Horde LLC
* @ignore
* @license http://www.horde.org/licenses/bsd BSD
* @package Stream_Wrapper
* @subpackage UnitTests
*/
class Horde_Stream_Wrapper_StringTest extends PHPUnit_Framework_TestCase
{
public function testUsage()
{
$string = 'ABCDE12345fghij';

$stream = Horde_Stream_Wrapper_String::getStream($string);

$this->assertEquals('ABCDE12345fghij', fread($stream, 1024));
$this->assertEquals(true, feof($stream));
$this->assertEquals(0, fseek($stream, 0));
$this->assertEquals(0, fseek($stream, 0));
$this->assertEquals(0, ftell($stream));
$this->assertEquals(0, fseek($stream, 5, SEEK_CUR));
$this->assertEquals(5, ftell($stream));
$this->assertEquals(10, fwrite($stream, '0000000000'));
$this->assertEquals(0, fseek($stream, 0, SEEK_END));
$this->assertEquals(15, ftell($stream));
$this->assertEquals(false, feof($stream));

fclose($stream);
}

public function testMemoryUsage()
{
$bytes = 1024 * 1024;
$string = str_repeat('*', $bytes);
$memoryUsage = memory_get_usage();

$stream = Horde_Stream_Wrapper_String::getStream($string);
$memoryUsage2 = memory_get_usage();
$this->assertLessThan($memoryUsage + $bytes, $memoryUsage2);

while (!feof($stream)) {
fread($stream, 1024);
}
$memoryUsage3 = memory_get_usage();
$this->assertLessThan($memoryUsage + $bytes, $memoryUsage3);
}

}
@@ -0,0 +1,3 @@
<?php
require_once 'Horde/Test/Bootstrap.php';
Horde_Test_Bootstrap::bootstrap(dirname(__FILE__));
@@ -0,0 +1 @@
<phpunit bootstrap="bootstrap.php"></phpunit>

0 comments on commit 35bc13a

Please sign in to comment.