FileCheckTest::testCheck()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
/* Copyright (C) 2017 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
namespace AdminBundle\Service\TwineImport;
20
21
use DembeloMain\Service\FileHandler;
22
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
23
24
/**
25
 * Class FileCheckTest
26
 */
27
class FileCheckTest extends WebTestCase
28
{
29
    /**
30
     * @var \PHPUnit_Framework_MockObject_MockObject|FileHandler
31
     */
32
    private $fileHandlerMock;
33
34
    /**
35
     * @return void
36
     */
37
    public function setUp(): void
38
    {
39
        $this->fileHandlerMock = $this->createMock(FileHandler::class);
40
    }
41
42
    /**
43
     * @return void php
44
     *
45
     * @throws \Exception
46
     */
47
    public function testCheck(): void
48
    {
49
        $this->fileHandlerMock->method('read')
0 ignored issues
show
Bug introduced by
The method method() does not exist on DembeloMain\Service\FileHandler. ( Ignorable by Annotation )

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

49
        $this->fileHandlerMock->/** @scrutinizer ignore-call */ 
50
                                method('read')

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
50
            ->willReturn('<tw-storydata hurz');
51
52
        $fileCheck = new FileCheck();
53
        $returnValue = $fileCheck->check($this->fileHandlerMock, 'someFileName');
54
        self::assertTrue($returnValue);
55
    }
56
57
    /**
58
     * @return void
59
     *
60
     * @throws \Exception
61
     */
62
    public function testCheckWithLeadingEmptySpaces(): void
63
    {
64
        $this->fileHandlerMock->method('read')
65
            ->willReturn('  '."\n".'<tw-storydata hurz');
66
67
        $fileCheck = new FileCheck();
68
        $returnValue = $fileCheck->check($this->fileHandlerMock, 'someFileName');
69
        self::assertTrue($returnValue);
70
    }
71
72
    /**
73
     * @return void
74
     *
75
     * @expectedException \Exception
76
     *
77
     * @throws \Exception
78
     */
79
    public function testCheckWithTooShortPeekData(): void
80
    {
81
        $this->fileHandlerMock->method('read')
82
            ->willReturn('<tw-storyda');
83
84
        $fileCheck = new FileCheck();
85
        $fileCheck->check($this->fileHandlerMock, 'someFileName');
86
    }
87
88
    /**
89
     * @return void
90
     *
91
     * @expectedException \Exception
92
     *
93
     * @throws \Exception
94
     */
95
    public function testCheckWithWrongPeekData(): void
96
    {
97
        $this->fileHandlerMock->method('read')
98
            ->willReturn('<tw-storrydata ');
99
100
        $fileCheck = new FileCheck();
101
        $fileCheck->check($this->fileHandlerMock, 'someFileName');
102
    }
103
104
    /**
105
     * @return void
106
     *
107
     * @expectedException \Exception
108
     *
109
     * @throws \Exception
110
     */
111
    public function testCheckWithEmptyPeekData(): void
112
    {
113
        $this->fileHandlerMock->method('read')
114
            ->willReturn('');
115
116
        $fileCheck = new FileCheck();
117
        $fileCheck->check($this->fileHandlerMock, 'someFileName');
118
    }
119
120
    /**
121
     * @return void
122
     *
123
     * @expectedException \Exception
124
     *
125
     * @throws \Exception
126
     */
127
    public function testCheckWithOnlyWhitespacePeekData(): void
128
    {
129
        $this->fileHandlerMock->method('read')
130
            ->willReturn(' ');
131
132
        $fileCheck = new FileCheck();
133
        $fileCheck->check($this->fileHandlerMock, 'someFileName');
134
    }
135
}
136