1<?php 2 3/** 4 * Hoa 5 * 6 * 7 * @license 8 * 9 * New BSD License 10 * 11 * Copyright © 2007-2017, Hoa community. All rights reserved. 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions are met: 15 * * Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * * Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * * Neither the name of the Hoa nor the names of its contributors may be 21 * used to endorse or promote products derived from this software without 22 * specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE 28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 * POSSIBILITY OF SUCH DAMAGE. 35 */ 36 37namespace Hoa\Stream\Test\Integration\Filter; 38 39use Hoa\Stream\Filter as SUT; 40use Hoa\Test; 41 42/** 43 * Class \Hoa\Stream\Test\Integration\Filter\Filter. 44 * 45 * Test suite of the filter class. 46 * 47 * @copyright Copyright © 2007-2017 Hoa community 48 * @license New BSD License 49 */ 50class Filter extends Test\Integration\Suite 51{ 52 public function case_append() 53 { 54 $this 55 ->given( 56 $filename = 'hoa://Test/Vfs/Foo?type=file', 57 $content = 'Hello, World!', 58 file_put_contents($filename, $content), 59 $stream = fopen($filename, 'r'), 60 $name = 'string.toupper' 61 ) 62 ->when( 63 SUT::append($stream, $name), 64 $result = stream_get_contents($stream) 65 ) 66 ->then 67 ->string($result) 68 ->isEqualTo(strtoupper($content)); 69 } 70 71 public function case_prepend() 72 { 73 $this 74 ->given( 75 $filename = 'hoa://Test/Vfs/Foo?type=file', 76 $content = 'Hello, World!', 77 file_put_contents($filename, $content), 78 $stream = fopen($filename, 'r'), 79 $name = 'string.toupper' 80 ) 81 ->when( 82 SUT::prepend($stream, $name), 83 $result = stream_get_contents($stream) 84 ) 85 ->then 86 ->string($result) 87 ->isEqualTo(strtoupper($content)); 88 } 89 90 public function case_append_append() 91 { 92 $this 93 ->given( 94 $filename = 'hoa://Test/Vfs/Foo?type=file', 95 $content = 'Hello, World!', 96 file_put_contents($filename, $content), 97 $stream = fopen($filename, 'r'), 98 $name1 = 'string.toupper', 99 $name2 = 'string.tolower' 100 ) 101 ->when( 102 SUT::append($stream, $name1), 103 SUT::append($stream, $name2), 104 $result = stream_get_contents($stream) 105 ) 106 ->then 107 ->string($result) 108 ->isEqualTo(strtolower($content)); 109 } 110 111 public function case_append_prepend() 112 { 113 $this 114 ->given( 115 $filename = 'hoa://Test/Vfs/Foo?type=file', 116 $content = 'Hello, World!', 117 file_put_contents($filename, $content), 118 $stream = fopen($filename, 'r'), 119 $name1 = 'string.toupper', 120 $name2 = 'string.tolower' 121 ) 122 ->when( 123 SUT::append($stream, $name1), 124 SUT::prepend($stream, $name2), 125 $result = stream_get_contents($stream) 126 ) 127 ->then 128 ->string($result) 129 ->isEqualTo(strtoupper($content)); 130 } 131 132 public function case_prepend_prepend() 133 { 134 $this 135 ->given( 136 $filename = 'hoa://Test/Vfs/Foo?type=file', 137 $content = 'Hello, World!', 138 file_put_contents($filename, $content), 139 $stream = fopen($filename, 'r'), 140 $name1 = 'string.toupper', 141 $name2 = 'string.tolower' 142 ) 143 ->when( 144 SUT::prepend($stream, $name1), 145 SUT::prepend($stream, $name2), 146 $result = stream_get_contents($stream) 147 ) 148 ->then 149 ->string($result) 150 ->isEqualTo(strtoupper($content)); 151 } 152 153 public function case_append_1000_filters() 154 { 155 $this 156 ->given( 157 $filename = 'hoa://Test/Vfs/Foo?type=file', 158 $content = 'Hello, World!', 159 file_put_contents($filename, $content), 160 $stream = fopen($filename, 'r'), 161 $name = 'string.toupper' 162 ) 163 ->when(function () use ($stream, $name) { 164 for ($i = 1000; $i >= 0; --$i) { 165 $this->resource(SUT::prepend($stream, $name)); 166 } 167 }) 168 ->when($result = stream_get_contents($stream)) 169 ->then 170 ->string($result) 171 ->isEqualTo(strtoupper($content)); 172 } 173} 174