1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Fracture\Http; |
5
|
|
|
|
6
|
|
|
use Exception; |
7
|
|
|
use ReflectionClass; |
8
|
|
|
use PHPUnit_Framework_TestCase; |
9
|
|
|
|
10
|
|
|
class UploadedFileBuilderTest extends PHPUnit_Framework_TestCase |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @dataProvider provideInput |
15
|
|
|
* |
16
|
|
|
* @covers Fracture\Http\UploadedFileBuilder::create |
17
|
|
|
*/ |
18
|
|
|
public function testInitializationOfInstance($input) |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
$builder = $this->getMock('Fracture\Http\UploadedFileBuilder', ['buildInstance']); |
22
|
|
|
$builder->expects($this->once()) |
23
|
|
|
->method('buildInstance') |
24
|
|
|
->with($this->equalTo($input)) |
25
|
|
|
->will($this->returnValue(new UploadedFile($input))); |
26
|
|
|
|
27
|
|
|
$builder->create($input); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @dataProvider provideInput |
34
|
|
|
* |
35
|
|
|
* @covers Fracture\Http\UploadedFileBuilder::create |
36
|
|
|
*/ |
37
|
|
|
public function testPreparationOfInstance($input) |
38
|
|
|
{ |
39
|
|
|
|
40
|
|
|
$response = $this->getMock('Fracture\Http\UploadedFile', ['prepare'], ['params' => $input]); |
41
|
|
|
$response->expects($this->once()) |
42
|
|
|
->method('prepare'); |
43
|
|
|
|
44
|
|
|
$builder = $this->getMock('Fracture\Http\UploadedFileBuilder', ['buildInstance']); |
45
|
|
|
$builder->expects($this->once()) |
46
|
|
|
->method('buildInstance') |
47
|
|
|
->with($this->equalTo($input)) |
48
|
|
|
->will($this->returnValue($response)); |
49
|
|
|
|
50
|
|
|
$instance = $builder->create($input); |
51
|
|
|
|
52
|
|
|
$this->assertInstanceOf('Fracture\Http\UploadedFile', $instance); |
53
|
|
|
$this->assertEquals($response, $instance); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @dataProvider provideInput |
59
|
|
|
* |
60
|
|
|
* @covers Fracture\Http\UploadedFileBuilder::create |
61
|
|
|
* @covers Fracture\Http\UploadedFileBuilder::buildInstance |
62
|
|
|
*/ |
63
|
|
|
public function testUnalteredBuilder($input) |
64
|
|
|
{ |
65
|
|
|
$builder = new UploadedFileBuilder; |
66
|
|
|
$instance = $builder->create($input); |
67
|
|
|
|
68
|
|
|
$this->assertInstanceOf('Fracture\Http\UploadedFile', $instance); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
public function provideInput() |
73
|
|
|
{ |
74
|
|
|
return [ |
75
|
|
|
[ |
76
|
|
|
'input' => [ |
77
|
|
|
'name' => 'simple.png', |
78
|
|
|
'type' => 'image/png', |
79
|
|
|
'tmp_name' => FIXTURE_PATH . '/files/simple.png', |
80
|
|
|
'error' => 0, |
81
|
|
|
'size' => 74, |
82
|
|
|
], |
83
|
|
|
], |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|