Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
146 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
framework/Stream_Wrapper/test/Horde/Stream/Wrapper/AllTests.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
require_once 'Horde/Test/AllTests.php'; | ||
Horde_Test_AllTests::init(__FILE__)->run(); |
51 changes: 51 additions & 0 deletions
51
framework/Stream_Wrapper/test/Horde/Stream/Wrapper/CombineTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
66
framework/Stream_Wrapper/test/Horde/Stream/Wrapper/StringTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
framework/Stream_Wrapper/test/Horde/Stream/Wrapper/bootstrap.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
require_once 'Horde/Test/Bootstrap.php'; | ||
Horde_Test_Bootstrap::bootstrap(dirname(__FILE__)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<phpunit bootstrap="bootstrap.php"></phpunit> |