Code Duplication    Length = 43-47 lines in 2 locations

tests/unit/IO/FileWriterTest.php 2 locations

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