Completed
Pull Request — master (#375)
by Michael
09:39 queued 04:34
created

fgets()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 3
nc 2
nop 0
1
<?php
2
/* Copyright (C) 2016 Michael Giesler
3
 *
4
 * This file is part of Dembelo.
5
 *
6
 * Dembelo is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Affero General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * Dembelo is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU Affero General Public License 3 for more details.
15
 *
16
 * You should have received a copy of the GNU Affero General Public License 3
17
 * along with Dembelo. If not, see <http://www.gnu.org/licenses/>.
18
 */
19
20
/**
21
 * @package AdminBundle\Test
22
 */
23
24
// @codingStandardsIgnoreStart
25
namespace AdminBundle\Model;
26
27
use AdminBundle\Tests\Model\ImportTwineTest;
28
29
/**
30
 * mock function
31
 *
32
 * @param string $filename
33
 * @return bool
34
 */
35
function fopen($filename)
36
{
37
    return strpos($filename, 'readable') !== false;
38
}
39
40
/**
41
 * mock function
42
 */
43
function fclose()
44
{
45
}
46
47
/**
48
 * mock function
49
 *
50
 * @return bool|mixed
51
 */
52
function fread()
53
{
54
    if (empty(ImportTwineTest::$freadStack)) {
55
        return false;
56
    }
57
58
    return array_shift(ImportTwineTest::$freadStack);
59
}
60
61
/**
62
 * mock function
63
 *
64
 * @return bool
65
 */
66
function feof()
67
{
68
    return empty(ImportTwineTest::$freadStack);
69
}
70
71
/**
72
 * @param Resource $parser
73
 * @return void
74
 */
75
function xml_parser_free($parser)
76
{
77
    ImportTwineTest::$parserFreeCalled = true;
78
    \xml_parser_free($parser);
79
}
80
81
namespace AdminBundle\Tests\Model;
82
83
use AdminBundle\Model\ImportTwine;
84
use AdminBundle\Service\TwineImport\FileCheck;
85
use AdminBundle\Service\TwineImport\FileExtractor;
86
use AdminBundle\Service\TwineImport\HitchParser;
87
use DembeloMain\Document\Importfile;
88
use DembeloMain\Document\Textnode;
89
use DembeloMain\Model\Repository\Doctrine\ODM\TextNodeRepository;
90
use DembeloMain\Model\Repository\TextNodeRepositoryInterface;
91
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
92
93
// @codingStandardsIgnoreEnd
94
95
/**
96
 * Class ImportTwineTest
97
 * @package AdminBundle\Tests\Model
98
 */
99
class ImportTwineTest extends WebTestCase
100
{
101
102
    public static $freadStack = [];
103
    public static $parserFreeCalled = false;
104
    private $mocks;
105
106
    /**
107
     * @var ImportTwine
108
     */
109
    private $importTwine;
110
111
    /**
112
     * @var \PHPUnit_Framework_MockObject_MockObject|TextNodeRepositoryInterface
113
     */
114
    private $textnodeRepository;
115
116
    /**
117
     * @var \PHPUnit_Framework_MockObject_MockObject|HitchParser
118
     */
119
    private $hitchParserMock;
120
121
    /**
122
     * @var \PHPUnit_Framework_MockObject_MockObject|FileExtractor
123
     */
124
    private $fileExtractorMock;
125
126
    /**
127
     * @var \PHPUnit_Framework_MockObject_MockObject|FileCheck
128
     */
129
    private $fileCheckMock;
130
131
    /**
132
     * resets some variables
133
     */
134
    public function setUp()
135
    {
136
        self::$freadStack = [];
137
        $this->mocks = [];
138
        self::$parserFreeCalled = false;
139
140
        $this->textnodeRepository = $this->getTextnodeRepositoryMock();
141
        $this->hitchParserMock = $this->createHitchParserMock();
142
        $this->fileExtractorMock = $this->createFileExtractorMock();
143
        $this->fileCheckMock = $this->createFileCheckMock();
144
145
        $this->importTwine = new ImportTwine(
146
            $this->textnodeRepository,
147
            $this->hitchParserMock,
148
            $this->fileExtractorMock,
149
            $this->fileCheckMock
150
        );
151
    }
152
153
    /**
154
     * @expectedException Exception
155
     * @expectedExceptionMessage File 'somefilename_readable' isn't a Twine archive file
156
     */
157 View Code Duplication
    public function testRunWithWrongFileFormat()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
158
    {
159
        $dm = $this->getDmMock();
160
        $importfile = $this->getDummyImportfile();
161
162
        $this->fileCheckMock->expects(self::once())
163
            ->method('check')
164
            ->willThrowException(new \Exception('File \'somefilename_readable\' isn\'t a Twine archive file'));
165
166
        $this->fileExtractorMock->expects(self::any())
167
            ->method('extract')
168
            ->willReturn('readable.extracted');
169
170
        self::$freadStack = ['erste Zeile', 'zweite Zeile'];
171
172
        $this->importTwine->run($importfile);
173
        $dm->expects($this->never())
174
            ->method('persist');
175
        $dm->expects($this->never())
176
            ->method('flush');
177
    }
178
179
    /**
180
     * @expectedException \Exception
181
     * @expectedExceptionMessage File 'somefilename_readable' seems to be empty.
182
     */
183 View Code Duplication
    public function testRunWithEmptyFirstLine()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
184
    {
185
        $dm = $this->getDmMock();
186
        $importfile = $this->getDummyImportfile();
187
188
        $this->fileCheckMock->expects(self::once())
189
            ->method('check')
190
            ->willThrowException(new \Exception('Failed asserting that exception message \'File \'somefilename_readable\' isn\'t a Twine archive file\' contains \'File \'somefilename_readable\' seems to be empty.'));
191
192
        $this->fileExtractorMock->expects(self::any())
193
            ->method('extract')
194
            ->willReturn('readable.extracted');
195
196
        self::$freadStack = [''];
197
198
        $this->importTwine->run($importfile);
199
        $dm->expects($this->never())
200
            ->method('persist');
201
        $dm->expects($this->never())
202
            ->method('flush');
203
    }
204
205
    /**
206
     * tests the run method with correct but incomplete data
207
     *
208
     * @throws \Exception
209
     */
210
    public function testRunWithCorrectButIncompleteData()
211
    {
212
        $dm = $this->getDmMock();
213
        $importfile = $this->getDummyImportfile();
214
215
        $this->fileExtractorMock->expects(self::any())
216
            ->method('extract')
217
            ->willReturn('readable.extracted');
218
219
        self::$freadStack = ['zweite Zeile'];
220
221
        $retVal = $this->importTwine->run($importfile);
222
        $this->assertTrue($retVal);
223
        $dm->expects($this->never())
224
            ->method('persist');
225
        $dm->expects($this->never())
226
            ->method('flush');
227
    }
228
229
    /**
230
     * tests the run method when no textnode is written
231
     *
232
     * @throws \Exception
233
     */
234
    public function testRunButNoTextnodeIsWritten()
235
    {
236
        $importfile = $this->getDummyImportfile();
237
238
        $this->fileExtractorMock->expects(self::any())
239
            ->method('extract')
240
            ->willReturn('readable.extracted');
241
242
        self::$freadStack = [
243
            '<tw-storydata name="someStoryName" startnode="1" creator="Twine" creator-version="2.0.8" ifid="8E30D51C-4980-4161-B57F-B11C752E879A" format="Harlowe" options=""><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style>'."\n",
244
            '<script role="script" id="twine-user-script" type="text/twine-javascript"></script>'."\n",
245
            '<tw-passagedata pid="1" name="someNodeName" tags="Freigegeben ID:foobar" position="104,30">lorem impsum',
246
            'lorem impsum</tw-passagedata></tw-storydata>',
247
        ];
248
249
        $textnode = new Textnode();
250
        $textnode->setId('someTextnodeId');
251
252
        $this->textnodeRepository->expects($this->any())
253
            ->method('find')
254
            ->will($this->returnValue($textnode));
255
256
        $this->textnodeRepository->expects($this->any())
257
            ->method('findByTwineId')
258
            ->willReturn($textnode);
259
260
        $retVal = $this->importTwine->run($importfile);
261
        $this->assertTrue($retVal);
262
        $this->textnodeRepository->expects($this->never())
263
            ->method('save');
264
    }
265
266
    /**
267
     * tests the run method with a single node containing text
268
     *
269
     * @throws \Exception
270
     */
271
    public function testRunWithSingleNodeWithText()
272
    {
273
        $importfile = $this->getDummyImportfile();
274
275
        $this->fileExtractorMock->expects(self::any())
276
            ->method('extract')
277
            ->willReturn('readable.extracted');
278
279
        self::$freadStack = [
280
            '<tw-storydata name="someStoryName" startnode="1" creator="Twine" creator-version="2.0.8" ifid="8E30D51C-4980-4161-B57F-B11C752E879A" format="Harlowe" options=""><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style>'."\n",
281
            '<script role="script" id="twine-user-script" type="text/twine-javascript"></script>'."\n",
282
            '<tw-passagedata pid="1" name="someNodeName1" tags="Freigegeben ID:foobar" position="104,30">lorem ipsum',
283
            'lorem ipsum</tw-passagedata></tw-storydata>',
284
        ];
285
286
        $textnode = new Textnode();
287
        $textnode->setId('someTextnodeId');
288
289
        $this->textnodeRepository->expects($this->any())
290
            ->method('find')
291
            ->willReturn($textnode);
292
293
        $this->textnodeRepository->expects($this->any())
294
            ->method('findByTwineId')
295
            ->willReturn($textnode);
296
297
        $this->textnodeRepository->expects($this->once())
298
            ->method('save')
299
            ->with($this->callback(function ($textnode) {
0 ignored issues
show
Bug introduced by
$this->callback(function(...) { /* ... */ }) of type PHPUnit\Framework\Constraint\Callback is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

299
            ->with(/** @scrutinizer ignore-type */ $this->callback(function ($textnode) {
Loading history...
300
                return $textnode instanceof Textnode
301
                    && $textnode->getText() === "lorem ipsumlorem ipsum";
302
            }));
303
304
        $retVal = $this->importTwine->run($importfile);
305
        $this->assertTrue($retVal);
306
    }
307
308
    /**
309
     * check if exception is thrown when no licensee is available
310
     *
311
     * @expectedException Exception
312
     * @expectedExceptionMessage no licensee available
313
     */
314
    public function testRunWithExceptionWhenNoLicenseeIsAvailable()
315
    {
316
        $importfile = $this->getDummyImportfile(['licenseeId' => null]);
317
318
        $this->importTwine->run($importfile);
319
    }
320
321
    /**
322
     * check if exception is thrown when no licensee is available
323
     *
324
     * @expectedException Exception
325
     * @expectedExceptionMessage no filename available
326
     */
327
    public function testRunWithExceptionWhenNoFilenameIsAvailable()
328
    {
329
        $importfile = $this->getDummyImportfile(['filename' => null]);
330
331
        $this->importTwine->run($importfile);
332
    }
333
334
    /**
335
     * @expectedException Exception
336
     * @expectedExceptionMessage no ID given for Textnode "someNodeName1"
337
     */
338 View Code Duplication
    public function testRunWithTextnodeWithoutTwineID()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
339
    {
340
        $importfile = $this->getDummyImportfile();
341
342
        $this->fileExtractorMock->expects(self::any())
343
            ->method('extract')
344
            ->willReturn('readable.extracted');
345
346
        self::$freadStack = [
347
            '<tw-storydata name="someStoryName" startnode="1" creator="Twine" creator-version="2.0.8" ifid="8E30D51C-4980-4161-B57F-B11C752E879A" format="Harlowe" options=""><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style>'."\n",
348
            '<script role="script" id="twine-user-script" type="text/twine-javascript"></script>'."\n",
349
            '<tw-passagedata pid="1" name="someNodeName1" tags="Freigegeben" position="104,30">lorem ipsum',
350
            'lorem ipsum</tw-passagedata></tw-storydata>',
351
        ];
352
353
        $textnode = new Textnode();
354
355
        $this->textnodeRepository->expects($this->any())
356
            ->method('find')
357
            ->will($this->returnValue($textnode));
358
359
        $this->textnodeRepository->expects($this->never())
360
            ->method('save');
361
362
        $this->importTwine->run($importfile);
363
    }
364
365
    /**
366
     * @expectedException Exception
367
     * @expectedExceptionMessage no ID given for Textnode "someNodeName1"
368
     */
369 View Code Duplication
    public function testRunWithTextnodeWithoutAnyTag()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
370
    {
371
        $importfile = $this->getDummyImportfile();
372
373
        $this->fileExtractorMock->expects(self::any())
374
            ->method('extract')
375
            ->willReturn('readable.extracted');
376
377
        self::$freadStack = [
378
            '<tw-storydata name="someStoryName" startnode="1" creator="Twine" creator-version="2.0.8" ifid="8E30D51C-4980-4161-B57F-B11C752E879A" format="Harlowe" options=""><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style>'."\n",
379
            '<script role="script" id="twine-user-script" type="text/twine-javascript"></script>'."\n",
380
            '<tw-passagedata pid="1" name="someNodeName1" tags="" position="104,30">lorem ipsum',
381
            'lorem ipsum</tw-passagedata></tw-storydata>',
382
        ];
383
384
        $textnode = new Textnode();
385
386
        $this->textnodeRepository->expects($this->any())
387
            ->method('find')
388
            ->will($this->returnValue($textnode));
389
390
        $this->textnodeRepository->expects($this->never())
391
            ->method('save');
392
393
        $this->importTwine->run($importfile);
394
    }
395
396
    /**
397
     * tests identifying a textnode by a twine ID
398
     * @throws \Exception
399
     */
400 View Code Duplication
    public function testRunWithTextnodeWithTwineID()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
401
    {
402
        $importfile = $this->getDummyImportfile();
403
404
        $this->fileExtractorMock->expects(self::any())
405
            ->method('extract')
406
            ->willReturn('readable.extracted');
407
408
        self::$freadStack = [
409
            '<tw-storydata name="someStoryName" startnode="1" creator="Twine" creator-version="2.0.8" ifid="8E30D51C-4980-4161-B57F-B11C752E879A" format="Harlowe" options=""><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style>'."\n",
410
            '<script role="script" id="twine-user-script" type="text/twine-javascript"></script>'."\n",
411
            '<tw-passagedata pid="1" name="someNodeName1" tags="Freigegeben ID:foobar" position="104,30">lorem ipsum',
412
            'lorem ipsum</tw-passagedata></tw-storydata>',
413
        ];
414
415
        $textnode = new Textnode();
416
        $textnode->setId('someTextnodeId');
417
418
        $this->textnodeRepository->expects($this->any())
419
            ->method('find')
420
            ->will($this->returnValue($textnode));
421
422
        $this->textnodeRepository->expects($this->once())
423
            ->method('findByTwineId')
424
            ->with($importfile, 'foobar')
0 ignored issues
show
Bug introduced by
'foobar' of type string is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

424
            ->with($importfile, /** @scrutinizer ignore-type */ 'foobar')
Loading history...
Bug introduced by
$importfile of type DembeloMain\Document\Importfile is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

424
            ->with(/** @scrutinizer ignore-type */ $importfile, 'foobar')
Loading history...
425
            ->willReturn($textnode);
426
427
        $this->importTwine->run($importfile);
428
    }
429
430
    /**
431
     * tests the freeing of xml parser
432
     * @throws \Exception
433
     */
434 View Code Duplication
    public function testParserFree()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
435
    {
436
        $importfile = $this->getDummyImportfile();
437
438
        $this->fileExtractorMock->expects(self::any())
439
            ->method('extract')
440
            ->willReturn('readable.extracted');
441
442
        self::$freadStack = [
443
            '<tw-storydata name="someStoryName" startnode="1" creator="Twine" creator-version="2.0.8" ifid="8E30D51C-4980-4161-B57F-B11C752E879A" format="Harlowe" options=""><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style>'."\n",
444
            '<script role="script" id="twine-user-script" type="text/twine-javascript"></script>'."\n",
445
            '<tw-passagedata pid="1" name="someNodeName1" tags="Freigegeben ID:foobar" position="104,30">lorem ipsum',
446
            'lorem ipsum</tw-passagedata></tw-storydata>',
447
        ];
448
449
        $textnode = new Textnode();
450
        $textnode->setId('someTextnodeId');
451
452
        $this->textnodeRepository->expects($this->any())
453
            ->method('find')
454
            ->will($this->returnValue($textnode));
455
456
        $this->textnodeRepository->expects($this->once())
457
            ->method('findByTwineId')
458
            ->with($importfile, 'foobar')
0 ignored issues
show
Bug introduced by
'foobar' of type string is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

458
            ->with($importfile, /** @scrutinizer ignore-type */ 'foobar')
Loading history...
Bug introduced by
$importfile of type DembeloMain\Document\Importfile is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

458
            ->with(/** @scrutinizer ignore-type */ $importfile, 'foobar')
Loading history...
459
            ->willReturn($textnode);
460
461
        $this->importTwine->run($importfile);
462
463
        $this->assertTrue(self::$parserFreeCalled);
464
    }
465
466
    /**
467
     * tests disabling of a textnode that is no longer found in import file
468
     * @throws \Exception
469
     */
470
    public function testRunWithTextnodeDeletedInImportfile()
471
    {
472
        $importfile = $this->getDummyImportfile();
473
474
        $this->fileExtractorMock->expects(self::any())
475
            ->method('extract')
476
            ->willReturn('readable.extracted');
477
478
        self::$freadStack = [
479
            '<tw-storydata name="someStoryName" startnode="1" creator="Twine" creator-version="2.0.8" ifid="8E30D51C-4980-4161-B57F-B11C752E879A" format="Harlowe" options=""><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style>'."\n",
480
            '<script role="script" id="twine-user-script" type="text/twine-javascript"></script>'."\n",
481
            '<tw-passagedata pid="1" name="someNodeName1" tags="Freigegeben ID:foobar" position="104,30">lorem ipsum',
482
            'lorem ipsum</tw-passagedata></tw-storydata>',
483
        ];
484
485
        $textnode = new Textnode();
486
        $textnode->setId('someTextnodeId');
487
488
        $this->textnodeRepository->expects($this->any())
489
            ->method('find')
490
            ->will($this->returnValue($textnode));
491
492
        $this->textnodeRepository->expects($this->once())
493
            ->method('findByTwineId')
494
            ->with($importfile, 'foobar')
0 ignored issues
show
Bug introduced by
$importfile of type DembeloMain\Document\Importfile is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

494
            ->with(/** @scrutinizer ignore-type */ $importfile, 'foobar')
Loading history...
Bug introduced by
'foobar' of type string is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

494
            ->with($importfile, /** @scrutinizer ignore-type */ 'foobar')
Loading history...
495
            ->will($this->returnValue($textnode));
496
497
        $this->textnodeRepository->expects($this->once())
498
            ->method('disableOrphanedNodes')
499
            ->with($importfile, [$textnode->getId()]);
500
501
        $this->importTwine->run($importfile);
502
    }
503
504
    /**
505
     * @expectedException Exception
506
     * @expectedExceptionMessage There is a 'tw-passagedata' in the Twine archive file 'somefilename_readable' which has a non unique 'id' tag [someTwineId], in node 'someNodeName2'
507
     */
508
    public function testRunWithDuplicateTwineId()
509
    {
510
        $importfile = $this->getDummyImportfile();
511
512
        $this->fileExtractorMock->expects(self::any())
513
            ->method('extract')
514
            ->willReturn('readable.extracted');
515
516
        self::$freadStack = [
517
            '<tw-storydata name="someStoryName" startnode="1" creator="Twine" creator-version="2.0.8" ifid="8E30D51C-4980-4161-B57F-B11C752E879A" format="Harlowe" options=""><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style>'."\n",
518
            '<script role="script" id="twine-user-script" type="text/twine-javascript"></script>'."\n",
519
            '<tw-passagedata pid="1" name="someNodeName1" tags="ID:someTwineId" position="104,30">lorem ipsum',
520
            'lorem ipsum</tw-passagedata>',
521
            '<tw-passagedata pid="2" name="someNodeName2" tags="ID:someTwineId" position="104,30">lorem ipsum',
522
            'lorem ipsum</tw-passagedata>',
523
            '</tw-storydata>',
524
        ];
525
526
        $textnode = new Textnode();
527
528
        $this->textnodeRepository->expects($this->any())
529
            ->method('find')
530
            ->will($this->returnValue($textnode));
531
532
        $this->textnodeRepository->expects($this->once())
533
            ->method('save');
534
535
        $this->importTwine->run($importfile);
536
    }
537
538
    /**
539
     * tests a hitch to another textnode
540
     * @throws \Exception
541
     */
542 View Code Duplication
    public function testRunWithLinkToAnotherTextnode()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
543
    {
544
        $importfile = $this->getDummyImportfile();
545
546
        $this->fileExtractorMock->expects(self::any())
547
            ->method('extract')
548
            ->willReturn('readable.extracted');
549
550
        self::$freadStack = [
551
            '<tw-storydata name="someStoryName" startnode="1" creator="Twine" creator-version="2.0.8" ifid="8E30D51C-4980-4161-B57F-B11C752E879A" format="Harlowe" options=""><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style>'."\n",
552
            '<script role="script" id="twine-user-script" type="text/twine-javascript"></script>'."\n",
553
            '<tw-passagedata pid="1" name="someNodeName1" tags="ID:someTwineId1" position="104,30">lorem ipsum',
554
            'lorem ipsum</tw-passagedata>',
555
            '</tw-storydata>',
556
        ];
557
558
        $textnode1 = new Textnode();
559
        $textnode1->setText('lorem ipsum [[Linkdata->someNodeName2]]');
560
        $textnode1->setId('someId0');
561
562
        $textnode2 = new Textnode();
563
        $textnode2->setId('someId1');
564
565
        $this->hitchParserMock->expects(self::once())
566
            ->method('parseSingleArrowRight')
567
            ->with('Linkdata->someNodeName2')
0 ignored issues
show
Bug introduced by
'Linkdata->someNodeName2' of type string is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

567
            ->with(/** @scrutinizer ignore-type */ 'Linkdata->someNodeName2')
Loading history...
568
            ->willReturn(
569
                [
570
                    'description' => 'some description',
571
                    'textnodeId' => 'someTextnodeId',
572
                    'status' => Textnode::HITCH_STATUS_ACTIVE,
573
                ]
574
            );
575
576
        $this->textnodeRepository->expects($this->any())
577
            ->method('find')
578
            ->will($this->returnValue($textnode1));
579
580
        $this->textnodeRepository->expects($this->any())
581
            ->method('save')
582
            ->willReturnCallback(function ($textnode) {
583
                static $counter = 0;
584
                $textnode->setId('someTextnode'.$counter++);
585
            });
586
587
        $returnValue = $this->importTwine->run($importfile);
588
589
        self::assertTrue($returnValue);
590
        self::assertEquals('<p>lorem ipsum</p>', $textnode1->getText());
591
        self::assertEquals(1, $textnode1->getHitchCount());
592
    }
593
594
    /**
595
     * tests a hitch to another textnode
596
     * @throws \Exception
597
     */
598 View Code Duplication
    public function testRunWithLinkToAnotherTextnodeDoubleArrowRight()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
599
    {
600
        $importfile = $this->getDummyImportfile();
601
602
        $this->fileExtractorMock->expects(self::any())
603
            ->method('extract')
604
            ->willReturn('readable.extracted');
605
606
        self::$freadStack = [
607
            '<tw-storydata name="someStoryName" startnode="1" creator="Twine" creator-version="2.0.8" ifid="8E30D51C-4980-4161-B57F-B11C752E879A" format="Harlowe" options=""><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style>'."\n",
608
            '<script role="script" id="twine-user-script" type="text/twine-javascript"></script>'."\n",
609
            '<tw-passagedata pid="1" name="someNodeName1" tags="ID:someTwineId1" position="104,30">lorem ipsum',
610
            'lorem ipsum</tw-passagedata>',
611
            '</tw-storydata>',
612
        ];
613
614
        $textnode1 = new Textnode();
615
        $textnode1->setText('lorem ipsum [[description1-->textnodeId1]]');
616
        $textnode1->setId('someId0');
617
618
        $this->hitchParserMock->expects(self::once())
619
            ->method('parseDoubleArrowRight')
620
            ->with('description1-->textnodeId1')
0 ignored issues
show
Bug introduced by
'description1-->textnodeId1' of type string is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

620
            ->with(/** @scrutinizer ignore-type */ 'description1-->textnodeId1')
Loading history...
621
            ->willReturn(
622
                [
623
                    'description' => 'description1',
624
                    'textnodeId' => 'textnodeId1',
625
                    'status' => Textnode::HITCH_STATUS_ACTIVE,
626
                ]
627
            );
628
629
        $this->textnodeRepository->expects($this->any())
630
            ->method('find')
631
            ->will($this->returnValue($textnode1));
632
633
        $this->textnodeRepository->expects($this->any())
634
            ->method('save')
635
            ->willReturnCallback(function ($textnode) {
636
                static $counter = 0;
637
                $textnode->setId('someTextnode'.$counter++);
638
            });
639
640
        $returnValue = $this->importTwine->run($importfile);
641
642
        self::assertTrue($returnValue);
643
        self::assertEquals('<p>lorem ipsum</p>', $textnode1->getText());
644
        self::assertEquals(1, $textnode1->getHitchCount());
645
    }
646
647
    /**
648
     * tests a hitch to another textnode
649
     * @throws \Exception
650
     */
651 View Code Duplication
    public function testRunWithLinkToAnotherTextnodeSingleArrowLeft()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
652
    {
653
        $importfile = $this->getDummyImportfile();
654
655
        $this->fileExtractorMock->expects(self::any())
656
            ->method('extract')
657
            ->willReturn('readable.extracted');
658
659
        self::$freadStack = [
660
            '<tw-storydata name="someStoryName" startnode="1" creator="Twine" creator-version="2.0.8" ifid="8E30D51C-4980-4161-B57F-B11C752E879A" format="Harlowe" options=""><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style>'."\n",
661
            '<script role="script" id="twine-user-script" type="text/twine-javascript"></script>'."\n",
662
            '<tw-passagedata pid="1" name="someNodeName1" tags="ID:someTwineId1" position="104,30">lorem ipsum',
663
            'lorem ipsum</tw-passagedata>',
664
            '</tw-storydata>',
665
        ];
666
667
        $textnode1 = new Textnode();
668
        $textnode1->setText('lorem ipsum [[description1<-textnodeId1]]');
669
        $textnode1->setId('someId0');
670
671
        $this->hitchParserMock->expects(self::once())
672
            ->method('parseSingleArrowLeft')
673
            ->with('description1<-textnodeId1')
0 ignored issues
show
Bug introduced by
'description1<-textnodeId1' of type string is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

673
            ->with(/** @scrutinizer ignore-type */ 'description1<-textnodeId1')
Loading history...
674
            ->willReturn(
675
                [
676
                    'description' => 'description1',
677
                    'textnodeId' => 'textnodeId1',
678
                    'status' => Textnode::HITCH_STATUS_ACTIVE,
679
                ]
680
            );
681
682
        $this->textnodeRepository->expects($this->any())
683
            ->method('find')
684
            ->will($this->returnValue($textnode1));
685
686
        $this->textnodeRepository->expects($this->any())
687
            ->method('save')
688
            ->willReturnCallback(function ($textnode) {
689
                static $counter = 0;
690
                $textnode->setId('someTextnode'.$counter++);
691
            });
692
693
        $returnValue = $this->importTwine->run($importfile);
694
695
        self::assertTrue($returnValue);
696
        self::assertEquals('<p>lorem ipsum</p>', $textnode1->getText());
697
        self::assertEquals(1, $textnode1->getHitchCount());
698
    }
699
700
    /**
701
     * tests a hitch to another textnode
702
     * @throws \Exception
703
     */
704 View Code Duplication
    public function testRunWithLinkToAnotherTextnodeSimpleHitch()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
705
    {
706
        $importfile = $this->getDummyImportfile();
707
708
        $this->fileExtractorMock->expects(self::any())
709
            ->method('extract')
710
            ->willReturn('readable.extracted');
711
712
        self::$freadStack = [
713
            '<tw-storydata name="someStoryName" startnode="1" creator="Twine" creator-version="2.0.8" ifid="8E30D51C-4980-4161-B57F-B11C752E879A" format="Harlowe" options=""><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style>'."\n",
714
            '<script role="script" id="twine-user-script" type="text/twine-javascript"></script>'."\n",
715
            '<tw-passagedata pid="1" name="someNodeName1" tags="ID:someTwineId1" position="104,30">lorem ipsum',
716
            'lorem ipsum</tw-passagedata>',
717
            '</tw-storydata>',
718
        ];
719
720
        $textnode1 = new Textnode();
721
        $textnode1->setText('lorem ipsum [[description1]]');
722
        $textnode1->setId('someId0');
723
724
        $this->hitchParserMock->expects(self::once())
725
            ->method('parseSimpleHitch')
726
            ->with('description1')
0 ignored issues
show
Bug introduced by
'description1' of type string is incompatible with the type array expected by parameter $arguments of PHPUnit_Framework_MockOb...nvocationMocker::with(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

726
            ->with(/** @scrutinizer ignore-type */ 'description1')
Loading history...
727
            ->willReturn(
728
                [
729
                    'description' => 'description1',
730
                    'textnodeId' => 'textnodeId1',
731
                    'status' => Textnode::HITCH_STATUS_ACTIVE,
732
                ]
733
            );
734
735
        $this->textnodeRepository->expects($this->any())
736
            ->method('find')
737
            ->will($this->returnValue($textnode1));
738
739
        $this->textnodeRepository->expects($this->any())
740
            ->method('save')
741
            ->willReturnCallback(function ($textnode) {
742
                static $counter = 0;
743
                $textnode->setId('someTextnode'.$counter++);
744
            });
745
746
        $returnValue = $this->importTwine->run($importfile);
747
748
        self::assertTrue($returnValue);
749
        self::assertEquals('<p>lorem ipsum</p>', $textnode1->getText());
750
        self::assertEquals(1, $textnode1->getHitchCount());
751
    }
752
753
    /**
754
     * tests a hitch to another textnode
755
     * @throws \Exception
756
     */
757
    public function testRunWithLineBreakInText()
758
    {
759
        $importfile = $this->getDummyImportfile();
760
761
        $this->fileExtractorMock->expects(self::any())
762
            ->method('extract')
763
            ->willReturn('readable.extracted');
764
765
        self::$freadStack = [
766
            '<tw-storydata name="someStoryName" startnode="1" creator="Twine" creator-version="2.0.8" ifid="8E30D51C-4980-4161-B57F-B11C752E879A" format="Harlowe" options=""><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style>'."\n",
767
            '<script role="script" id="twine-user-script" type="text/twine-javascript"></script>'."\n",
768
            '<tw-passagedata pid="1" name="someNodeName1" tags="ID:someTwineId1" position="104,30">lorem ipsum',
769
            'lorem ipsum</tw-passagedata>',
770
            '</tw-storydata>',
771
        ];
772
773
        $textnode1 = new Textnode();
774
        $textnode1->setText('lorem ipsum' . "\n" . "foo bar");
775
        $textnode1->setId('someId0');
776
777
        $this->textnodeRepository->expects($this->any())
778
            ->method('find')
779
            ->will($this->returnValue($textnode1));
780
781
        $this->textnodeRepository->expects($this->any())
782
            ->method('save')
783
            ->willReturnCallback(function ($textnode) {
784
                static $counter = 0;
785
                $textnode->setId('someTextnode'.$counter++);
786
            });
787
788
        $returnValue = $this->importTwine->run($importfile);
789
790
        self::assertTrue($returnValue);
791
        self::assertEquals('<p>lorem ipsum</p><p>foo bar</p>', $textnode1->getText());
792
    }
793
794
    /**
795
     * tests a hitch to multiple other textnodes
796
     * @throws \Exception
797
     */
798
    public function testRunWithLinkToMultipleOtherTextnodes()
799
    {
800
        $importfile = $this->getDummyImportfile();
801
802
        $this->fileExtractorMock->expects(self::any())
803
            ->method('extract')
804
            ->willReturn('readable.extracted');
805
806
        self::$freadStack = [
807
            '<tw-storydata name="someStoryName" startnode="1" creator="Twine" creator-version="2.0.8" ifid="8E30D51C-4980-4161-B57F-B11C752E879A" format="Harlowe" options=""><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style>'."\n",
808
            '<script role="script" id="twine-user-script" type="text/twine-javascript"></script>'."\n",
809
            '<tw-passagedata pid="1" name="someNodeName1" tags="ID:someTwineId1" position="104,30">lorem ipsum',
810
            'lorem ipsum</tw-passagedata>',
811
            '</tw-storydata>',
812
        ];
813
814
        $textnode1 = new Textnode();
815
        $textnode1->setText('lorem ipsum [[Linkdata->someNodeName2]] [[Linkdata2->someNodeName3]]');
816
        $textnode1->setId('someId0');
817
818
        $textnode2 = new Textnode();
819
        $textnode2->setId('someId1');
820
821
        $textnode3 = new Textnode();
822
        $textnode3->setId('someId2');
823
824
        $this->hitchParserMock->expects(self::any())
825
            ->method('parseSingleArrowRight')
826
            ->willReturnCallback(function ($content, $name) {
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

826
            ->willReturnCallback(function ($content, /** @scrutinizer ignore-unused */ $name) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
827 View Code Duplication
                if ($content !== 'Linkdata->someNodeName2') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
828
                    return [
829
                        'description' => 'some description',
830
                        'textnodeId' => 'someTextnodeId1',
831
                        'status' => Textnode::HITCH_STATUS_ACTIVE,
832
                    ];
833
                }
834 View Code Duplication
                if ($content !== 'Linkdata2->someNodeName3') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
835
                    return [
836
                        'description' => 'some description',
837
                        'textnodeId' => 'someTextnodeId2',
838
                        'status' => Textnode::HITCH_STATUS_ACTIVE,
839
                    ];
840
                }
841
                self:: fail();
842
            });
843
844
        $this->textnodeRepository->expects($this->any())
845
            ->method('find')
846
            ->will($this->returnValue($textnode1));
847
848
        $this->textnodeRepository->expects($this->any())
849
            ->method('save')
850
            ->willReturnCallback(function ($textnode) {
851
                static $counter = 0;
852
                $textnode->setId('someTextnode'.$counter++);
853
            });
854
855
        $returnValue = $this->importTwine->run($importfile);
856
857
        self::assertTrue($returnValue);
858
        self::assertEquals('<p>lorem ipsum</p>', $textnode1->getText());
859
        self::assertEquals(2, $textnode1->getHitchCount());
860
    }
861
862
    /**
863
     * tests run() with setting of metadata
864
     */
865
    public function testRunWithMetadataSetting()
866
    {
867
        $importfile = $this->getDummyImportfile();
868
869
        $this->fileExtractorMock->expects(self::any())
870
            ->method('extract')
871
            ->willReturn('readable.extracted');
872
873
        self::$freadStack = [
874
            '<tw-storydata name="someStoryName" startnode="1" creator="Twine" creator-version="2.0.8" ifid="8E30D51C-4980-4161-B57F-B11C752E879A" format="Harlowe" options=""><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style>'."\n",
875
            '<script role="script" id="twine-user-script" type="text/twine-javascript"></script>'."\n",
876
            '<tw-passagedata pid="1" name="someNodeName1" tags="ID:someTwineId1" position="104,30">lorem ipsum',
877
            'lorem ipsum [[Linkdata->someNodeName2]]</tw-passagedata>',
878
            '<tw-passagedata pid="2" name="someNodeName2" tags="ID:someTwineId2" position="104,30">lorem ipsum',
879
            'lorem ipsum [[metakey>:&lt;metavalue]]</tw-passagedata>',
880
            '</tw-storydata>',
881
        ];
882
883
        $textnode1 = new Textnode();
884
        $textnode1->setText('lorem ipsum [[metakey>:<metavalue]]');
885
        $textnode1->setId('someId0');
886
887
        $this->textnodeRepository->expects($this->any())
888
            ->method('find')
889
            ->will($this->returnValue($textnode1));
890
891
        $this->textnodeRepository->expects($this->any())
892
            ->method('findByTwineId')
893
            ->will($this->returnValue($textnode1));
894
895
        $returnValue = $this->importTwine->run($importfile);
896
        self::assertTrue($returnValue);
897
        $metadata = $textnode1->getMetadata();
898
        self::assertInternalType('array', $metadata);
899
        self::assertArrayHasKey('metakey', $metadata);
900
        self::assertEquals('metavalue', $metadata['metakey']);
901
    }
902
903
    /**
904
     * @expectedException \Exception
905
     * @expectedExceptionMessageRegExp /invalid element.*>:</
906
     */
907 View Code Duplication
    public function testRunWithMetadataSettingForInvalidFormat()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
908
    {
909
        $importfile = $this->getDummyImportfile();
910
911
        $this->fileExtractorMock->expects(self::any())
912
            ->method('extract')
913
            ->willReturn('readable.extracted');
914
915
        self::$freadStack = [
916
            '<tw-storydata name="someStoryName" startnode="1" creator="Twine" creator-version="2.0.8" ifid="8E30D51C-4980-4161-B57F-B11C752E879A" format="Harlowe" options=""><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style>'."\n",
917
            '<script role="script" id="twine-user-script" type="text/twine-javascript"></script>'."\n",
918
            '<tw-passagedata pid="1" name="someNodeName1" tags="ID:someTwineId1" position="104,30">lorem ipsum',
919
            'lorem ipsum [[Linkdata->someNodeName2]]</tw-passagedata>',
920
            '<tw-passagedata pid="2" name="someNodeName2" tags="ID:someTwineId2" position="104,30">lorem ipsum',
921
            'lorem ipsum [[>:&lt;metavalue]]</tw-passagedata>',
922
            '</tw-storydata>',
923
        ];
924
925
        $textnode1 = new Textnode();
926
        $textnode1->setText('lorem ipsum [[>:<metavalue]]');
927
        $textnode1->setId('someId0');
928
929
        $this->textnodeRepository->expects($this->any())
930
            ->method('find')
931
            ->will($this->returnValue($textnode1));
932
933
        $this->textnodeRepository->expects($this->any())
934
            ->method('findByTwineId')
935
            ->will($this->returnValue($textnode1));
936
937
        $this->importTwine->run($importfile);
938
    }
939
940
    /**
941
     * @expectedException \Exception
942
     * @expectedExceptionMessageRegExp /contains the metadata field/
943
     */
944 View Code Duplication
    public function testRunWithMetadataSettingForAnAlreadyExistingMetadataKey()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
945
    {
946
        $importfile = $this->getDummyImportfile();
947
948
        $this->fileExtractorMock->expects(self::any())
949
            ->method('extract')
950
            ->willReturn('readable.extracted');
951
952
        self::$freadStack = [
953
            '<tw-storydata name="someStoryName" startnode="1" creator="Twine" creator-version="2.0.8" ifid="8E30D51C-4980-4161-B57F-B11C752E879A" format="Harlowe" options=""><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style>'."\n",
954
            '<script role="script" id="twine-user-script" type="text/twine-javascript"></script>'."\n",
955
            '<tw-passagedata pid="1" name="someNodeName1" tags="ID:someTwineId1" position="104,30">lorem ipsum',
956
            'lorem ipsum [[Linkdata->someNodeName2]]</tw-passagedata>',
957
            '<tw-passagedata pid="2" name="someNodeName2" tags="ID:someTwineId2" position="104,30">lorem ipsum',
958
            'lorem ipsum [[Autor>:&lt;metavalue]]</tw-passagedata>',
959
            '</tw-storydata>',
960
        ];
961
962
        $textnode1 = new Textnode();
963
        $textnode1->setId('someId0');
964
        $textnode1->setMetadata(['metakey' => 'someValue']);
965
966
        $this->textnodeRepository->expects($this->any())
967
            ->method('find')
968
            ->will($this->returnValue($textnode1));
969
970
        $this->textnodeRepository->expects($this->any())
971
            ->method('findByTwineId')
972
            ->will($this->returnValue($textnode1));
973
974
        $this->importTwine->run($importfile);
975
    }
976
977
    private function getDummyImportfile(array $data = [])
978
    {
979
        $default = [
980
            'filename'   => 'somefilename_readable',
981
            'licenseeId' => 'somelicenseeId',
982
            'author'     => 'someAuthor',
983
            'publisher'  => 'somePublisher',
984
            'id'         => 'someImportFileId',
985
        ];
986
987
        $importfileData = array_merge($default, $data);
988
989
        $importfile = new Importfile();
990
        if (null !== $importfileData['filename']) {
991
            $importfile->setFilename($importfileData['filename']);
992
        }
993
        if (null !== $importfileData['licenseeId']) {
994
            $importfile->setLicenseeId($importfileData['licenseeId']);
995
        }
996
        if (null !== $importfileData['author']) {
997
            $importfile->setAuthor($importfileData['author']);
998
        }
999
        if (null !== $importfileData['publisher']) {
1000
            $importfile->setPublisher($importfileData['publisher']);
1001
        }
1002
        if (null !== $importfileData['id']) {
1003
            $importfile->setId($importfileData['id']);
1004
        }
1005
1006
        return $importfile;
1007
    }
1008
1009
    /**
1010
     * @return \PHPUnit_Framework_MockObject_MockObject|TextNodeRepository
1011
     */
1012
    private function getTextnodeRepositoryMock()
1013
    {
1014
        return $this->getMockBuilder(TextNodeRepository::class)->disableOriginalConstructor()->setMethods(['createQueryBuilder', 'field', 'equals', 'getQuery', 'save', 'find', 'findByTwineId', 'disableOrphanedNodes', 'setHyphenatedText'])->getMock();
1015
    }
1016
1017
    private function getDmMock()
1018
    {
1019
        return $this->getMockBuilder('dmMock')->setMethods(['flush', 'persist', 'find'])->getMock();
1020
    }
1021
1022
    /**
1023
     * @return \PHPUnit_Framework_MockObject_MockObject|HitchParser
1024
     */
1025
    private function createHitchParserMock(): HitchParser
1026
    {
1027
        return $this->createMock(HitchParser::class);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createMock...ort\HitchParser::class) returns the type PHPUnit_Framework_MockObject_MockObject which is incompatible with the type-hinted return AdminBundle\Service\TwineImport\HitchParser.
Loading history...
1028
    }
1029
1030
    /**
1031
     * @return \PHPUnit_Framework_MockObject_MockObject|FileExtractor
1032
     */
1033
    private function createFileExtractorMock(): FileExtractor
1034
    {
1035
        return $this->createMock(FileExtractor::class);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createMock...t\FileExtractor::class) returns the type PHPUnit_Framework_MockObject_MockObject which is incompatible with the type-hinted return AdminBundle\Service\TwineImport\FileExtractor.
Loading history...
1036
    }
1037
1038
    /**
1039
     * @return \PHPUnit_Framework_MockObject_MockObject|FileCheck
1040
     */
1041
    private function createFileCheckMock(): FileCheck
1042
    {
1043
        return $this->createMock(FileCheck::class);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createMock...mport\FileCheck::class) returns the type PHPUnit_Framework_MockObject_MockObject which is incompatible with the type-hinted return AdminBundle\Service\TwineImport\FileCheck.
Loading history...
1044
    }
1045
}
1046