|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Unit; |
| 4 | + |
| 5 | +use Autopilot\AutopilotContact; |
| 6 | +use Autopilot\AutopilotManager; |
| 7 | +use GuzzleHttp\Client; |
| 8 | +use Phake; |
| 9 | +use Psr\Http\Message\ResponseInterface; |
| 10 | +use Psr\Http\Message\StreamInterface; |
| 11 | + |
| 12 | +/** |
| 13 | + * Class AutopilotManagerTest |
| 14 | + */ |
| 15 | +class AutopilotManagerTest extends \PHPUnit_Framework_TestCase |
| 16 | +{ |
| 17 | + /** |
| 18 | + * @var AutopilotManager |
| 19 | + */ |
| 20 | + protected $manager; |
| 21 | + |
| 22 | + protected $stream; |
| 23 | + |
| 24 | + /** |
| 25 | + * Set up the test |
| 26 | + */ |
| 27 | + public function setUp() |
| 28 | + { |
| 29 | + $this->stream = Phake::mock(StreamInterface::CLASS); |
| 30 | + $response = Phake::mock(ResponseInterface::CLASS); |
| 31 | + Phake::when($response)->getBody()->thenReturn($this->stream); |
| 32 | + $client = Phake::mock(Client::CLASS); |
| 33 | + Phake::when($client)->post(Phake::anyParameters())->thenReturn($response); |
| 34 | + Phake::when($client)->get(Phake::anyParameters())->thenReturn($response); |
| 35 | + |
| 36 | + $this->manager = new AutopilotManager('foo', null, $client); |
| 37 | + } |
| 38 | + |
| 39 | + public function testGetContact() |
| 40 | + { |
| 41 | + Phake::when($this->stream)->getContents()->thenReturn(json_encode([ |
| 42 | + |
| 43 | + 'created_at' => "2017-02-03T16:26:54.000Z", |
| 44 | + 'first_visit_at' => "2017-01-12T10:08:10.761Z", |
| 45 | + 'anywhere_page_visits' => [ |
| 46 | + '//fr/sites/dashboard' => true, |
| 47 | + '//fr' => true, |
| 48 | + ], |
| 49 | + 'updated_at' => "2017-02-08T15:33:40.000Z", |
| 50 | + 'anywhere_utm' => [], |
| 51 | + 'MailingCity' => "Paris", |
| 52 | + 'MailingState' => "Ile-de-farnce", |
| 53 | + 'MailingCountry' => "France", |
| 54 | + 'Company' => "Baz industrie", |
| 55 | + 'Title' => "Baz system", |
| 56 | + 'LinkedIn' => "https://www.linkedin.com/in/foo-bar-609467", |
| 57 | + 'NumberOfEmployees' => "10001", |
| 58 | + 'employeesRange' => [ |
| 59 | + 'min' => 10001, |
| 60 | + ], |
| 61 | + 'Industry' => "Information Technology and Services", |
| 62 | + 'Name' => "Foo Bar", |
| 63 | + 'company_priority' => false, |
| 64 | + 'LastName' => "Bar", |
| 65 | + 'FirstName' => "foo", |
| 66 | + 'Salutation' => "Mr.", |
| 67 | + 'lists' => [ |
| 68 | + 0 => "contactlist_C1A0F558-BB05-4C18-82C6-6347854F80A6", |
| 69 | + 1 => "contactlist_8099FCD5-244B-44DC-9D6F-5A2F6F7ADBF8", |
| 70 | + ], |
| 71 | + 'contact_id' => "person_0F17B343-EBA9-4721-AF44-96CE0EEDA103", |
| 72 | + ])); |
| 73 | + |
| 74 | + $contact = $this->manager->getContact('foo'); |
| 75 | + |
| 76 | + $this->assertInstanceOf(AutopilotContact::CLASS, $contact); |
| 77 | + $this->assertSame('person_0F17B343-EBA9-4721-AF44-96CE0EEDA103', $contact->getFieldValue('contact_id')); |
| 78 | + } |
| 79 | +} |
0 commit comments