88% of 147OPs |
84% of 19Lines |
75% of 24Branches |
82% of 11Paths |
Method | OPs | OPs % | Lines | Line % | Branches | Branches % | Paths | Path % |
---|---|---|---|---|---|---|---|---|
mageekguy\atoum\asserters\hash::__get() | 47 | 64% | 9 | 67% | 15 | 67% | 5 | 80% |
mageekguy\atoum\asserters\hash::isSha1() | 12 | 100% | 1 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\asserters\hash::isSha256() | 12 | 100% | 1 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\asserters\hash::isSha512() | 12 | 100% | 1 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\asserters\hash::isMd5() | 12 | 100% | 1 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\asserters\hash::isHash() | 52 | 100% | 6 | 100% | 5 | 80% | 2 | 50% |
# | |
---|---|
1 |
<?php |
2 |
|
3 |
namespace mageekguy\atoum\asserters; |
4 |
|
5 |
use |
6 |
mageekguy\atoum\asserters |
7 |
; |
8 |
|
9 |
class hash extends asserters\phpString |
10 |
{ |
11 |
public function __get($asserter)67% |
12 |
{ |
13 |
switch (strtolower($asserter)) |
14 |
{ |
15 |
case 'issha1': |
16 |
case 'issha256': |
17 |
case 'issha512': |
18 |
case 'ismd5': |
19 |
return $this->{$asserter}(); |
20 |
|
21 |
default: |
22 |
return parent::__get($asserter); |
23 |
} |
24 |
} |
25 |
|
26 |
public function isSha1($failMessage = null)100% |
27 |
{ |
28 |
return $this->isHash(40, $failMessage); |
29 |
} |
30 |
|
31 |
public function isSha256($failMessage = null)100% |
32 |
{ |
33 |
return $this->isHash(64, $failMessage); |
34 |
} |
35 |
|
36 |
public function isSha512($failMessage = null)100% |
37 |
{ |
38 |
return $this->isHash(128, $failMessage); |
39 |
} |
40 |
|
41 |
public function isMd5($failMessage = null)100% |
42 |
{ |
43 |
return $this->isHash(32, $failMessage); |
44 |
} |
45 |
|
46 |
protected function isHash($length, $failMessage = null)100% |
47 |
{ |
48 |
if (strlen($this->valueIsSet()->value) === $length) |
49 |
{ |
50 |
$this->matches('/^[a-fA-F0-9]+$/', $failMessage ?: $this->_('%s does not match given pattern', $this)); |
51 |
} |
52 |
else |
53 |
{ |
54 |
$this->fail($failMessage ?: $this->_('%s should be a string of %d characters', $this, $length)); |
55 |
} |
56 |
|
57 |
return $this; |
58 |
} |
59 |
} |