Skip to content

Commit 3f8003d

Browse files
committed
replace not working tests using api
1 parent 9306714 commit 3f8003d

7 files changed

+421
-312
lines changed

Tests/Unit/AutopilotManagerTest.php

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
'Email' => "[email protected]",
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+
}

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"require-dev": {
2020
"codeception/codeception": "~2.1",
2121
"codeception/aspect-mock": "dev-master",
22-
"vlucas/phpdotenv": "~2.2"
22+
"phpunit/phpunit": "~5.7",
23+
"phake/phake": "~2.3"
2324
},
2425
"suggest": {
2526
"vlucas/phpdotenv": "Allows secrets to be loaded from .env files."

phpunit.xml.dist

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
4+
<phpunit
5+
backupGlobals = "false"
6+
backupStaticAttributes = "false"
7+
colors = "true"
8+
convertErrorsToExceptions = "true"
9+
convertNoticesToExceptions = "true"
10+
convertWarningsToExceptions = "true"
11+
processIsolation = "false"
12+
stopOnFailure = "false"
13+
syntaxCheck = "false"
14+
bootstrap = "vendor/autoload.php">
15+
16+
<testsuites>
17+
<testsuite name="unit">
18+
<directory>Tests</directory>
19+
</testsuite>
20+
</testsuites>
21+
22+
<filter>
23+
<blacklist>
24+
<directory suffix=".php">./vendor/</directory>
25+
</blacklist>
26+
</filter>
27+
28+
<!--<logging>-->
29+
<!--<log type="coverage-clover" target="build/logs/clover.xml"/>-->
30+
<!--</logging>-->
31+
32+
</phpunit>

src/AutopilotContact.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public function fill(array $options = [])
176176
}
177177
} elseif ($key === 'lists') {
178178
$this->lists = $value;
179-
} else {
179+
} elseif (!is_array($value)) {
180180
$field = new AutopilotField($key, $value);
181181
$this->fields[$field->getName()] = $field;
182182
}

src/AutopilotManager.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ class AutopilotManager
3636
* @param string $apiHost
3737
* Autopilot host URI.
3838
*/
39-
public function __construct($apiKey, $apiHost = null)
39+
public function __construct($apiKey, $apiHost = null, Client $client = null)
4040
{
4141
$this->apiKey = $apiKey;
4242

4343
// instantiate client
44-
$this->client = new Client([
44+
$this->client = (null !== $client)? $client: new Client([
4545
'base_uri' => $apiHost ?: 'https://api2.autopilothq.com/v1/',
4646
]);
4747
}

tests/_bootstrap.php

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<?php
22
// This is global bootstrap for autoloading
33

4-
// load configs from env file
5-
Dotenv::load(__DIR__ . '/..');
6-
74
// register mocker
85
$kernel = \AspectMock\Kernel::getInstance();
96
$kernel->init([

0 commit comments

Comments
 (0)