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\Unit\Filter; 38 39use Hoa\Stream as LUT; 40use Mock\Hoa\Stream\Filter\Basic as SUT; 41use Hoa\Test; 42 43/** 44 * Class \Hoa\Stream\Test\Unit\Filter\Basic. 45 * 46 * Test suite of the basic filter class. 47 * 48 * @copyright Copyright © 2007-2017 Hoa community 49 * @license New BSD License 50 */ 51class Basic extends Test\Unit\Suite 52{ 53 public function case_constants() 54 { 55 $this 56 ->integer(SUT::PASS_ON) 57 ->isEqualTo(PSFS_PASS_ON) 58 ->integer(SUT::FEED_ME) 59 ->isEqualTo(PSFS_FEED_ME) 60 ->integer(SUT::FATAL_ERROR) 61 ->isEqualTo(PSFS_ERR_FATAL) 62 ->integer(SUT::FLAG_NORMAL) 63 ->isEqualTo(PSFS_FLAG_NORMAL) 64 ->integer(SUT::FLAG_FLUSH_INC) 65 ->isEqualTo(PSFS_FLAG_FLUSH_INC) 66 ->integer(SUT::FLAG_FLUSH_CLOSE) 67 ->isEqualTo(PSFS_FLAG_FLUSH_CLOSE); 68 } 69 70 public function case_is_a_php_filter() 71 { 72 $this 73 ->when($result = new SUT()) 74 ->then 75 ->object($result) 76 ->isInstanceOf(\php_user_filter::class); 77 } 78 79 public function case_interfaces() 80 { 81 $this 82 ->when($result = new SUT()) 83 ->then 84 ->object($result) 85 ->isInstanceOf(LUT\IStream\Stream::class); 86 } 87 88 public function case_set_name() 89 { 90 $this 91 ->given($filter = new SUT()) 92 ->when($result = $filter->setName('foo')) 93 ->then 94 ->string($result) 95 ->isEqualTo(''); 96 } 97 98 public function case_get_name() 99 { 100 $this 101 ->given( 102 $filter = new SUT(), 103 $name = 'foo', 104 $filter->setName($name) 105 ) 106 ->when($result = $filter->getName()) 107 ->then 108 ->string($result) 109 ->isEqualTo($name); 110 } 111 112 public function case_set_parameters() 113 { 114 $this 115 ->given($filter = new SUT()) 116 ->when($result = $filter->setParameters(['foo', 'bar', 'baz'])) 117 ->then 118 ->string($result) 119 ->isEqualTo(''); 120 } 121 122 public function case_get_parameters() 123 { 124 $this 125 ->given( 126 $filter = new SUT(), 127 $parameters = ['foo', 'bar', 'baz'], 128 $filter->setParameters($parameters) 129 ) 130 ->when($result = $filter->getParameters()) 131 ->then 132 ->array($result) 133 ->isEqualTo($parameters); 134 } 135 136 public function case_get_stream() 137 { 138 $this 139 ->given($filter = new SUT()) 140 ->when($result = $filter->getStream()) 141 ->then 142 ->variable($result) 143 ->isNull(); // Only available when filtering, so `null` is valid. 144 } 145} 146