|
1
|
|
|
<?php
|
|
2
|
|
|
|
|
3
|
|
|
namespace Radowoj\Yaah;
|
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase;
|
|
6
|
|
|
use Radowoj\Yaah\Auction;
|
|
7
|
|
|
|
|
8
|
|
|
class AuctionTest extends TestCase
|
|
9
|
|
|
{
|
|
10
|
|
|
|
|
11
|
|
|
/**
|
|
12
|
|
|
* @expectedException InvalidArgumentException
|
|
13
|
|
|
* @expectedExceptionMessage Photo files limit exceeded, 8 allowed, 9 given
|
|
14
|
|
|
*/
|
|
15
|
|
|
public function testExceptionOnTooManyPhotos()
|
|
16
|
|
|
{
|
|
17
|
|
|
$auction = new Auction();
|
|
18
|
|
|
$auction->setPhotos([
|
|
19
|
|
|
'maximum', 'number', 'of', 'photos', 'is', 'eight', 'so', 'test', 'nine'
|
|
20
|
|
|
]);
|
|
21
|
|
|
}
|
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
protected function prepareTestAuction()
|
|
25
|
|
|
{
|
|
26
|
|
|
return new Auction([
|
|
27
|
|
|
1 => 'test string',
|
|
28
|
|
|
2 => 42,
|
|
29
|
|
|
3 => '05-03-2017',
|
|
30
|
|
|
4 => 12.34,
|
|
31
|
|
|
]);
|
|
32
|
|
|
}
|
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
protected function checkTestAuctionFields(array $fields)
|
|
36
|
|
|
{
|
|
37
|
|
|
$testString = array_shift($fields);
|
|
38
|
|
|
$this->assertArrayHasKey('fvalueString', $testString);
|
|
39
|
|
|
$this->assertSame('test string', $testString['fvalueString']);
|
|
40
|
|
|
|
|
41
|
|
|
$testInt = array_shift($fields);
|
|
42
|
|
|
$this->assertArrayHasKey('fvalueInt', $testInt);
|
|
43
|
|
|
$this->assertSame(42, $testInt['fvalueInt']);
|
|
44
|
|
|
|
|
45
|
|
|
$testDate = array_shift($fields);
|
|
46
|
|
|
$this->assertArrayHasKey('fvalueDate', $testDate);
|
|
47
|
|
|
$this->assertSame('05-03-2017', $testDate['fvalueDate']);
|
|
48
|
|
|
|
|
49
|
|
|
$testFloat = array_shift($fields);
|
|
50
|
|
|
$this->assertArrayHasKey('fvalueFloat', $testFloat);
|
|
51
|
|
|
$this->assertSame(12.34, $testFloat['fvalueFloat']);
|
|
52
|
|
|
}
|
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
public function testApiRepresentationWithoutPhotos()
|
|
56
|
|
|
{
|
|
57
|
|
|
$auction = $this->prepareTestAuction();
|
|
58
|
|
|
|
|
59
|
|
|
$apiRepresentation = $auction->toApiRepresentation();
|
|
60
|
|
|
|
|
61
|
|
|
$this->assertArrayHasKey('fields', $apiRepresentation);
|
|
62
|
|
|
$this->assertEquals(4, count($apiRepresentation['fields']));
|
|
63
|
|
|
|
|
64
|
|
|
$this->checkTestAuctionFields($apiRepresentation['fields']);
|
|
65
|
|
|
}
|
|
66
|
|
|
|
|
67
|
|
|
|
|
68
|
|
View Code Duplication |
public function testApiRepresentationWithPhotos()
|
|
|
|
|
|
|
69
|
|
|
{
|
|
70
|
|
|
$auction = $this->prepareTestAuction();
|
|
71
|
|
|
|
|
72
|
|
|
$auction->setPhotos([
|
|
73
|
|
|
__DIR__ . '/i.am.a.photo.file.txt'
|
|
74
|
|
|
]);
|
|
75
|
|
|
|
|
76
|
|
|
$apiRepresentation = $auction->toApiRepresentation();
|
|
77
|
|
|
|
|
78
|
|
|
$this->assertArrayHasKey('fields', $apiRepresentation);
|
|
79
|
|
|
$this->assertEquals(5, count($apiRepresentation['fields']));
|
|
80
|
|
|
|
|
81
|
|
|
$this->checkTestAuctionFields($apiRepresentation['fields']);
|
|
82
|
|
|
}
|
|
83
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
/**
|
|
86
|
|
|
* @expectedException Radowoj\Yaah\Exception
|
|
87
|
|
|
* @expectedExceptionMessage Photo file is not readable
|
|
88
|
|
|
*/
|
|
89
|
|
View Code Duplication |
public function testApiRepresentationWithInvalidPhotos()
|
|
|
|
|
|
|
90
|
|
|
{
|
|
91
|
|
|
$auction = $this->prepareTestAuction();
|
|
92
|
|
|
|
|
93
|
|
|
$auction->setPhotos([
|
|
94
|
|
|
__DIR__ . '/i.am.not.a.photo.file.txt'
|
|
95
|
|
|
]);
|
|
96
|
|
|
|
|
97
|
|
|
$apiRepresentation = $auction->toApiRepresentation();
|
|
98
|
|
|
|
|
99
|
|
|
$this->assertArrayHasKey('fields', $apiRepresentation);
|
|
100
|
|
|
$this->assertEquals(5, count($apiRepresentation['fields']));
|
|
101
|
|
|
|
|
102
|
|
|
$fields = $apiRepresentation['fields'];
|
|
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
$this->checkTestAuctionFields($apiRepresentation['fields']);
|
|
105
|
|
|
}
|
|
106
|
|
|
|
|
107
|
|
|
}
|
|
108
|
|
|
|
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.