@@ 124-170 (lines=47) @@ | ||
121 | return $stream; |
|
122 | } |
|
123 | ||
124 | public function testInsertAll() |
|
125 | { |
|
126 | $data = [ |
|
127 | ['a', 'b', 'c', 'd'], |
|
128 | ['e', 'f', 'g', 'h'], |
|
129 | ]; |
|
130 | ||
131 | $stream = $this->getStream(); |
|
132 | ||
133 | $file = m::mock(FileNodeInterface::class, NodeStreamInterface::class); |
|
134 | $file->shouldReceive('getStream') |
|
135 | ->with('a+') |
|
136 | ->andReturn($stream); |
|
137 | ||
138 | $format = m::mock(CsvFormat::class)->makePartial(); |
|
139 | $formatter = m::mock(FormatterInterface::class); |
|
140 | $factory = m::mock(FormatterFactoryInterface::class); |
|
141 | $factory->shouldReceive('getFormatter') |
|
142 | ->with($format) |
|
143 | ->andReturn($formatter); |
|
144 | $writer = new FileWriter($file, $format, $factory); |
|
145 | ||
146 | $formatter->shouldReceive('format') |
|
147 | ->with(['a', 'b', 'c', 'd']) |
|
148 | ->andReturn('first line'); |
|
149 | $formatter->shouldReceive('format') |
|
150 | ->with(['e', 'f', 'g', 'h']) |
|
151 | ->andReturn('second line'); |
|
152 | $formatter->shouldReceive('getInitialBlock') |
|
153 | ->andReturn('initial' . "\n"); |
|
154 | $formatter->shouldReceive('getClosingBlock') |
|
155 | ->andReturn("\n" . 'close'); |
|
156 | $formatter->shouldReceive('getRowSeparator') |
|
157 | ->andReturn("\n"); |
|
158 | ||
159 | $expected = <<<CSV |
|
160 | initial |
|
161 | first line |
|
162 | second line |
|
163 | close |
|
164 | CSV; |
|
165 | ||
166 | $writer->insertAll($data); |
|
167 | ||
168 | $stream->rewind(); |
|
169 | static::assertEquals($expected, $stream->getContents()); |
|
170 | } |
|
171 | ||
172 | public function testInsertOne() |
|
173 | { |
|
@@ 172-214 (lines=43) @@ | ||
169 | static::assertEquals($expected, $stream->getContents()); |
|
170 | } |
|
171 | ||
172 | public function testInsertOne() |
|
173 | { |
|
174 | $stream = $this->getStream(); |
|
175 | ||
176 | $file = m::mock(FileNodeInterface::class, NodeStreamInterface::class); |
|
177 | $file->shouldReceive('getStream') |
|
178 | ->with('a+') |
|
179 | ->andReturn($stream); |
|
180 | ||
181 | $format = m::mock(CsvFormat::class)->makePartial(); |
|
182 | $formatter = m::mock(FormatterInterface::class); |
|
183 | $factory = m::mock(FormatterFactoryInterface::class); |
|
184 | $factory->shouldReceive('getFormatter') |
|
185 | ->with($format) |
|
186 | ->andReturn($formatter); |
|
187 | $writer = new FileWriter($file, $format, $factory); |
|
188 | ||
189 | $formatter->shouldReceive('format') |
|
190 | ->with(['a', 'b', 'c', 'd']) |
|
191 | ->andReturn('first line'); |
|
192 | $formatter->shouldReceive('format') |
|
193 | ->with(['e', 'f', 'g', 'h']) |
|
194 | ->andReturn('second line'); |
|
195 | $formatter->shouldReceive('getInitialBlock') |
|
196 | ->andReturn('initial' . "\n"); |
|
197 | $formatter->shouldReceive('getClosingBlock') |
|
198 | ->andReturn("\n" . 'close'); |
|
199 | $formatter->shouldReceive('getRowSeparator') |
|
200 | ->andReturn("\n"); |
|
201 | ||
202 | $expected = <<<CSV |
|
203 | initial |
|
204 | first line |
|
205 | second line |
|
206 | close |
|
207 | CSV; |
|
208 | ||
209 | $writer->insertOne(['a', 'b', 'c', 'd']); |
|
210 | $writer->insertOne(['e', 'f', 'g', 'h']); |
|
211 | ||
212 | $stream->rewind(); |
|
213 | static::assertEquals($expected, $stream->getContents()); |
|
214 | } |
|
215 | } |
|
216 |