Completed
Push — master ( f165f0...a36629 )
by Aimeos
09:56 queued 02:40
created

LaravelTest::testReads()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 12
rs 9.4286
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace Aimeos\MW\Filesystem;
4
5
6
class LaravelTest extends \PHPUnit_Framework_TestCase
7
{
8
	private $mock;
9
	private $object;
10
11
12
	protected function setUp()
13
	{
14
		if( !interface_exists( '\\Illuminate\\Contracts\\Filesystem\\Filesystem' ) ) {
15
			$this->markTestSkipped( 'Install Laravel framework first' );
16
		}
17
18
		$this->mock = $this->getMockBuilder( '\\Illuminate\\Contracts\\Filesystem\\Filesystem' )
19
			->disableOriginalConstructor()
20
			->getMock();
21
22
		$this->object = new \Aimeos\MW\Filesystem\Laravel( $this->mock );
23
	}
24
25
26
	protected function tearDown()
27
	{
28
		unset( $this->object );
29
	}
30
31
32 View Code Duplication
	public function testIsdir()
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...
33
	{
34
		$this->mock->expects( $this->once() )->method( 'directories' )
35
			->will( $this->returnValue( array( 't', 'test', 'es' ) ) );
36
37
		$this->assertTrue( $this->object->isdir( 'test' ) );
38
	}
39
40
41 View Code Duplication
	public function testIsdirFalse()
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...
42
	{
43
		$this->mock->expects( $this->once() )->method( 'directories' )
44
			->will( $this->returnValue( array( 't', 'es' ) ) );
45
46
		$this->assertFalse( $this->object->isdir( 'test' ) );
47
	}
48
49
50
	public function testMkdir()
51
	{
52
		$this->mock->expects( $this->once() )->method( 'makeDirectory' );
53
54
		$this->object->mkdir( 'test' );
55
	}
56
57
58
	public function testRmdir()
59
	{
60
		$this->mock->expects( $this->once() )->method( 'deleteDirectory' );
61
62
		$this->object->rmdir( 'test' );
63
	}
64
65
66
	public function testScan()
67
	{
68
		$list = array( 't', 'es', 'st' );
69
70
		$this->mock->expects( $this->once() )->method( 'directories' )
71
			->will( $this->returnValue( array( 't', 'es' ) ) );
72
73
		$this->mock->expects( $this->once() )->method( 'files' )
74
			->will( $this->returnValue( array( 'st' ) ) );
75
76
		$result = $this->object->scan();
77
78
		$this->assertInternalType( 'array', $result );
79
80
		foreach( $result as $entry ) {
81
			$this->assertTrue( in_array( $entry, $list ) );
82
		}
83
	}
84
85
86 View Code Duplication
	public function testSize()
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...
87
	{
88
		$this->mock->expects( $this->once() )->method( 'size' )
89
			->will( $this->returnValue( 4 ) );
90
91
		$result = $this->object->size( 'test' );
92
93
		$this->assertEquals( 4, $result );
94
	}
95
96
97 View Code Duplication
	public function testTime()
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...
98
	{
99
		$this->mock->expects( $this->once() )->method( 'lastModified' )
100
			->will( $this->returnValue( 1 ) );
101
102
		$result = $this->object->time( 'test' );
103
104
		$this->assertGreaterThan( 0, $result );
105
	}
106
107
108
	public function testRm()
109
	{
110
		$this->mock->expects( $this->once() )->method( 'delete' );
111
112
		$this->object->rm( 'test' );
113
	}
114
115
116 View Code Duplication
	public function testHas()
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...
117
	{
118
		$this->mock->expects( $this->once() )->method( 'exists' )
119
			->will( $this->returnValue( true ) );
120
121
		$result = $this->object->has( 'test' );
122
123
		$this->assertTrue( $result );
124
	}
125
126
127 View Code Duplication
	public function testHasFalse()
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...
128
	{
129
		$this->mock->expects( $this->once() )->method( 'exists' )
130
			->will( $this->returnValue( false ) );
131
132
		$result = $this->object->has( 'test' );
133
134
		$this->assertFalse( $result );
135
	}
136
137
138 View Code Duplication
	public function testRead()
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...
139
	{
140
		$this->mock->expects( $this->once() )->method( 'get' )
141
			->will( $this->returnValue( 'test' ) );
142
143
		$result = $this->object->read( 'file' );
144
145
		$this->assertEquals( 'test', $result );
146
	}
147
148
149
	public function testReadException()
150
	{
151
		$this->mock->expects( $this->once() )->method( 'get' )
152
			->will( $this->throwException( new \Exception() ) );
153
154
		$this->setExpectedException( '\Aimeos\MW\Filesystem\Exception' );
155
		$this->object->read( 'readinvalid' );
156
	}
157
158
159
	public function testReads()
160
	{
161
		$this->mock->expects( $this->once() )->method( 'get' )
162
			->will( $this->returnValue( 'test' ) );
163
164
		$handle = $this->object->reads( 'file' );
165
166
		$this->assertInternalType( 'resource', $handle );
167
		$this->assertEquals( 'test', fgets( $handle ) );
168
169
		fclose( $handle );
170
	}
171
172
173
	public function testReadsException()
174
	{
175
		$this->mock->expects( $this->once() )->method( 'get' )
176
			->will( $this->throwException( new \Exception() ) );
177
178
		$this->setExpectedException( '\Aimeos\MW\Filesystem\Exception' );
179
		$this->object->reads( 'readinvalid' );
180
	}
181
182
183
	public function testWrite()
184
	{
185
		$this->mock->expects( $this->once() )->method( 'put' );
186
187
		$this->object->write( 'file', 'test' );
188
	}
189
190
191 View Code Duplication
	public function testWriteException()
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...
192
	{
193
		$this->mock->expects( $this->once() )->method( 'put' )
194
			->will( $this->throwException( new \Exception() ) );
195
196
		$this->setExpectedException( '\Aimeos\MW\Filesystem\Exception' );
197
		$this->object->write( '', 'test' );
198
	}
199
200
201
	public function testWrites()
202
	{
203
		$this->mock->expects( $this->once() )->method( 'put' );
204
205
		$handle = fopen( __FILE__, 'r' );
206
207
		$this->object->writes( 'file', $handle );
208
209
		fclose( $handle );
210
	}
211
212
213 View Code Duplication
	public function testWritesException()
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...
214
	{
215
		$this->mock->expects( $this->once() )->method( 'put' )
216
			->will( $this->throwException( new \Exception() ) );
217
218
		$handle = fopen( __FILE__, 'r' );
219
220
		$this->setExpectedException( '\Aimeos\MW\Filesystem\Exception' );
221
		$this->object->writes( 'file', $handle );
222
	}
223
224
225
	public function testWritesException2()
226
	{
227
		$this->setExpectedException( '\Aimeos\MW\Filesystem\Exception' );
228
		$this->object->writes( 'file', null );
229
	}
230
231
232
	public function testMove()
233
	{
234
		$this->mock->expects( $this->once() )->method( 'move' );
235
236
		$this->object->move( 'file1', 'file2' );
237
	}
238
239
240
	public function testCopy()
241
	{
242
		$this->mock->expects( $this->once() )->method( 'copy' );
243
244
		$this->object->copy( 'file1', 'file2' );
245
	}
246
}
247