1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* MIT License |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2016 Bernardo Secades |
7
|
|
|
* |
8
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
9
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
10
|
|
|
* in the Software without restriction, including without limitation the rights |
11
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
12
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
13
|
|
|
* furnished to do so, subject to the following conditions: |
14
|
|
|
* |
15
|
|
|
* The above copyright notice and this permission notice shall be included in all |
16
|
|
|
* copies or substantial portions of the Software. |
17
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
20
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
22
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
23
|
|
|
* SOFTWARE. |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
namespace BernardoSecades\Packagist\SecurityChecker\Tests\Unit\ValueObject; |
27
|
|
|
|
28
|
|
|
use BernardoSecades\Packagist\SecurityChecker\ValueObject\Package; |
29
|
|
|
use BernardoSecades\Packagist\SecurityChecker\Exception\Packagist\NotFollowSemanticVersioningException; |
30
|
|
|
|
31
|
|
|
class PackageTest extends \PHPUnit_Framework_TestCase |
32
|
|
|
{ |
33
|
|
|
/** @var Package */ |
34
|
|
|
protected $package; |
35
|
|
|
|
36
|
|
|
protected function setUp() |
37
|
|
|
{ |
38
|
|
|
$this->package = new Package(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testLoadDataFromArray() |
42
|
|
|
{ |
43
|
|
|
$this->package->fromArray($this->getDataWithSemanticVersioning()); |
44
|
|
|
|
45
|
|
|
$this->assertEquals('vendor/package', $this->package->getName()); |
46
|
|
|
$this->assertEquals('description', $this->package->getDescription()); |
47
|
|
|
$this->assertEquals('v1.5.7', $this->package->getVersion()); |
48
|
|
|
$this->assertEquals('1.5.7.0', $this->package->getVersionNormalized()); |
49
|
|
|
$this->assertEquals('https://github.com/vendor/package', $this->package->getUrl()); |
50
|
|
|
$this->assertEquals('library', $this->package->getType()); |
51
|
|
|
$this->assertEquals('v1.5.8', $this->package->getVersionWithNextPatchVersion()); |
52
|
|
|
$this->assertFalse($this->package->hasBug()); |
53
|
|
|
$this->assertFalse($this->package->hasPackagist()); |
54
|
|
|
$this->assertTrue($this->package->supportSemanticVersioning()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testNoSemanticVersioningException() |
58
|
|
|
{ |
59
|
|
|
$this->expectException(NotFollowSemanticVersioningException::class); |
60
|
|
|
$this->package->fromArray($this->getDataWithoutSemanticVersioning()); |
61
|
|
|
$this->package->getVersionWithNextPatchVersion(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return array |
66
|
|
|
*/ |
67
|
|
View Code Duplication |
protected function getDataWithSemanticVersioning() |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
return [ |
70
|
|
|
'name' => 'vendor/package', |
71
|
|
|
'description' => 'description', |
72
|
|
|
'version' => 'v1.5.7', |
73
|
|
|
'version_normalized' => '1.5.7.0', |
74
|
|
|
'source' => [ |
75
|
|
|
'type' => 'git', |
76
|
|
|
'url' => 'https://github.com/vendor/package', |
77
|
|
|
], |
78
|
|
|
'type' => 'library', |
79
|
|
|
]; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return array |
84
|
|
|
*/ |
85
|
|
View Code Duplication |
protected function getDataWithoutSemanticVersioning() |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
return [ |
88
|
|
|
'name' => 'vendor/package', |
89
|
|
|
'description' => 'description', |
90
|
|
|
'version' => 'v0.9', |
91
|
|
|
'version_normalized' => '0.9.0.0', |
92
|
|
|
'source' => [ |
93
|
|
|
'type' => 'git', |
94
|
|
|
'url' => 'https://github.com/vendor/package', |
95
|
|
|
], |
96
|
|
|
'type' => 'library', |
97
|
|
|
]; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
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.