Skip to content

Commit 0cc55c1

Browse files
committed
unit tests
- add more unit tests - apply fixes to source per unit tests - now 100% coverage
1 parent 2425735 commit 0cc55c1

File tree

10 files changed

+453
-49
lines changed

10 files changed

+453
-49
lines changed

coverage.txt

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,41 @@
11

22

3-
Code Coverage Report:
4-
2018-11-30 01:39:31
5-
6-
Summary:
7-
Classes: 66.67% (12/18)
8-
Methods: 72.09% (31/43)
9-
Lines: 54.21% (116/214)
3+
Code Coverage Report:
4+
2018-12-06 00:19:24
5+
6+
Summary:
7+
Classes: 100.00% (18/18)
8+
Methods: 100.00% (43/43)
9+
Lines: 100.00% (186/186)
1010

1111
\Webhook::PopulatorTrait
1212
Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 11/ 11)
13+
\Webhook::Webhook\Callback
14+
Methods: 100.00% ( 3/ 3) Lines: 100.00% ( 43/ 43)
15+
\Webhook::Webhook\CallbackRule
16+
Methods: 100.00% ( 2/ 2) Lines: 100.00% ( 6/ 6)
17+
\Webhook::Webhook\EventCallbackRule
18+
Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 2/ 2)
1319
\Webhook::Webhook\EventMissingException
1420
Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 2/ 2)
1521
\Webhook::Webhook\InvalidRequestException
16-
Methods: 50.00% ( 1/ 2) Lines: 75.00% ( 3/ 4)
22+
Methods: 100.00% ( 2/ 2) Lines: 100.00% ( 4/ 4)
1723
\Webhook::Webhook\MessageBodyInvalidException
1824
Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 2/ 2)
1925
\Webhook::Webhook\Payload
2026
Methods: 100.00% ( 2/ 2) Lines: 100.00% ( 5/ 5)
2127
\Webhook::Webhook\Request
22-
Methods: 66.67% ( 8/12) Lines: 66.67% ( 34/ 51)
28+
Methods: 100.00% (12/12) Lines: 100.00% ( 51/ 51)
2329
\Webhook::Webhook\SignatureInvalidException
2430
Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 2/ 2)
2531
\Webhook::Webhook\SignatureMissingException
2632
Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 2/ 2)
33+
\Webhook::Webhook\UrlCallbackRule
34+
Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 2/ 2)
2735
\Webhook\Payload::Webhook\Payload\Event
28-
Methods: 100.00% ( 4/ 4) Lines: 100.00% ( 11/ 11)
36+
Methods: 100.00% ( 5/ 5) Lines: 100.00% ( 11/ 11)
2937
\Webhook\Payload::Webhook\Payload\PingEvent
30-
Methods: 100.00% ( 4/ 4) Lines: 100.00% ( 11/ 11)
38+
Methods: 100.00% ( 3/ 3) Lines: 100.00% ( 10/ 10)
3139
\Webhook\Payload::Webhook\Payload\PushEvent
3240
Methods: 100.00% ( 4/ 4) Lines: 100.00% ( 18/ 18)
3341
\Webhook\PayloadData::CommitTrait

src/Callback.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ public function validatePayload(Payload $payload) {
118118
public function __construct(string $hubSecret,callable $callback,CallbackRule ...$CallbackRule) {
119119
$this->_hubSecret = $hubSecret;
120120
$this->_callback = $callback;
121+
121122
foreach($CallbackRule as $v) {
123+
122124
if ($v instanceof UrlCallbackRule) {
123125
$this->_urlRule []= (string) $v;
124126
}

src/Payload.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace Webhook;
33

44
use Webhook\PayloadData\Sender;
5+
use Webhook\PayloadData\Repository;
56

67
abstract class Payload implements Populatable, PopulateListener {
78

@@ -15,6 +16,7 @@ abstract public function getEvent():string;
1516
* @var \Webhook\PayloadData\Sender
1617
*/
1718
public $sender;
19+
1820

1921
use PopulatorTrait;
2022

src/Payload/Event.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
namespace Webhook\Payload;
33

44
use Webhook\Payload;
5-
5+
use Webhook\PayloadData\Repository;
66
class Event extends Payload implements EventProviderInterface {
7+
/**
8+
* @var \Webhook\PayloadData\Repository
9+
*/
10+
public $repository;
711

812
/**
913
* Populates a "generic" Payload <b>Event</b> object corresponding to this event.
@@ -50,19 +54,24 @@ public function __construct($input,string $gitHubEvent) {
5054

5155
$this->_event = $gitHubEvent;
5256

53-
$pubProp = [];
54-
foreach((new \ReflectionObject($input))->getProperties(\ReflectionProperty::IS_PUBLIC) as $v) {
55-
$pubProp[]=$v->getName();
56-
}
57-
unset($v);
57+
// $pubProp = [];
58+
// foreach((new \ReflectionObject($input))->getProperties(\ReflectionProperty::IS_PUBLIC) as $v) {
59+
// $pubProp[]=$v->getName();
60+
// }
61+
// unset($v);
5862

5963
$this->_payloadData = json_decode(json_encode($input),true);
6064

6165

6266
}
6367

6468

65-
69+
public function populateComplete() {
70+
parent::populateComplete();
71+
if (!$this->repository instanceof Repository) {
72+
$this->repository = (new Repository)->populateFromObject($this->repository);
73+
}
74+
}
6675

6776

6877

src/Payload/PingEvent.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Webhook\PayloadData\Hook;
66
use Webhook\PayloadData\PingRepository;
77

8-
class PingEvent extends Payload implements EventProviderInterface {
8+
class PingEvent extends Payload {
99

1010
/**
1111
* @var string The random message generated for this ping event.
@@ -35,13 +35,15 @@ class PingEvent extends Payload implements EventProviderInterface {
3535

3636
const EVENT_NAME = 'ping';
3737

38-
/**
39-
* Populates a "generic" Payload <b>Event</b> object corresponding to this event.
40-
* @return \Webhook\Payload\Event
41-
*/
42-
public function toEvent() : Event {
43-
return new Event($this->input,static::EVENT_NAME);
44-
}
38+
// /**
39+
// * Populates a "generic" Payload <b>Event</b> object corresponding to this event.
40+
// * @return \Webhook\Payload\Event
41+
// */
42+
// public function toEvent() : Event {
43+
// $data = json_decode(json_encode($this));
44+
45+
// return new Event(json_decode(json_encode($this)),static::EVENT_NAME);
46+
// }
4547

4648
/**
4749
* Provides the event name.

0 commit comments

Comments
 (0)