-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathMocksCallingAllPapers.php
61 lines (46 loc) · 1.57 KB
/
MocksCallingAllPapers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace Tests;
use App\CallingAllPapers\Client;
use App\CallingAllPapers\Event;
use Exception;
use Mockery;
use stdClass;
trait MocksCallingAllPapers
{
protected $eventId = 'abcdef1234567890abcdef1234567890abcdef122017';
protected $eventStub;
public function mockClient($event = null)
{
if (! $event) {
$event = $this->eventStub;
}
$mockClient = Mockery::mock(Client::class);
$mockClient->shouldReceive('getEvents')->andReturn([$event]);
app()->instance(Client::class, $mockClient);
return $mockClient;
}
public function mockClientWithError()
{
$mockClient = Mockery::mock(Client::class);
$mockClient->shouldReceive('getEvents')
->andThrow(Exception::class, 'Test exception');
app()->instance(Client::class, $mockClient);
return $mockClient;
}
public function stubEvent()
{
$_rel = new stdClass;
$_rel->cfp_uri = "v1/cfp/{$this->eventId}";
$event = new stdClass;
$event->_rel = $_rel;
$event->name = 'ABC conference';
$event->description = 'The greatest conference ever.';
$event->eventUri = 'https://www.example.com/';
$event->uri = 'https://cfp.example.com/';
$event->dateCfpStart = '2017-08-20T00:00:00-04:00';
$event->dateCfpEnd = '2017-09-22T00:00:00-04:00';
$event->dateEventStart = '2017-10-20T00:00:00-04:00';
$event->dateEventEnd = '2017-12-22T00:00:00-04:00';
$this->eventStub = Event::createFromApiObject($event);
}
}