Skip to content

Commit b1ede71

Browse files
committed
Modifications needed for autotesting, initial autotesting add
1 parent ee73f1d commit b1ede71

38 files changed

+2241
-95
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
# Connect PHP SDK
44

5+
[![Build Status](https://travis-ci.org/apsconnect/connect-sdk.svg?branch=master)](https://travis-ci.org/apsconnect/connect-sdk) [![Latest Stable Version](https://poser.pugx.org/apsconnect/connect-sdk/v/stable)](https://packagist.org/packages/apsconnect/connect-sdk) [![License](https://poser.pugx.org/apsconnect/connect-sdk/license)](https://packagist.org/packages/apsconnect/connect-sdk)
6+
57
## Getting Started
68
Connect PHP SDK allows an easy and fast integration with [Connect](http://connect.cloud.im/) fulfillment API. Thanks to it you can automate the fulfillment of orders generated by your products.
79

composer.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,23 @@
77
"php": ">=5.6.0",
88
"ext-curl": "*",
99
"ext-json": "*",
10-
"ext-Reflection": "*"
10+
"doctrine/inflector": "^1.1.0",
11+
"psr/container": "^1.0.0",
12+
"psr/log": "^1.0.0",
13+
"pimple/pimple": "^3.0"
14+
},
15+
"require-dev": {
16+
"phpunit/phpunit": "^5.7",
17+
"mockery/mockery": "^0.9"
1118
},
1219
"autoload": {
1320
"psr-4": {
1421
"Connect\\": "src/"
1522
}
23+
},
24+
"autoload-dev": {
25+
"psr-4": {
26+
"Test\\": "tests/"
27+
}
1628
}
1729
}

coverage.xml

Lines changed: 710 additions & 0 deletions
Large diffs are not rendered by default.

examples/config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"apiKey": "XXX:YYY",
3-
"apiEndpoint": "https://host/public/v1",
3+
"apiEndpoint": "http://localhost:8000/",
44
"logLevel": "info",
55
"timeout": 10,
6-
"sslVerifyHost": true
6+
"sslVerifyHost": false
77
}

phpunit.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<phpunit bootstrap="vendor/autoload.php" verbose="true" stopOnError="true" stopOnFailure="false">
2+
<filter>
3+
<whitelist processUncoveredFilesFromWhitelist="true">
4+
<directory suffix=".php">src</directory>
5+
</whitelist>
6+
</filter>
7+
<logging>
8+
<log type="testdox-text" target="php://stdout" showUncoveredFiles="false"/>
9+
<log type="coverage-html" target="tmp/report" lowUpperBound="35" highLowerBound="70"/>
10+
<log type="coverage-clover" target="coverage.xml"/>
11+
</logging>
12+
<listeners>
13+
<listener class="\Mockery\Adapter\Phpunit\TestListener"
14+
file="vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php">
15+
</listener>
16+
</listeners>
17+
<testsuites>
18+
<testsuite name="Configuration">
19+
<file>tests/Unit/ConfigurationTest.php</file>
20+
</testsuite>
21+
<testsuite name="Application">
22+
<file>tests/Unit/AppTest.php</file>
23+
</testsuite>
24+
<testsuite name="Models">
25+
<file>tests/Unit/ModelTest.php</file>
26+
<file>tests/Unit/ParamTest.php</file>
27+
</testsuite>
28+
</testsuites>
29+
</phpunit>

src/Asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Class Asset
1313
* @package Connect
1414
*/
15-
class Asset
15+
class Asset extends Model
1616
{
1717
public $id;
1818
public $external_id;

src/Config.php

Lines changed: 74 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -8,113 +8,122 @@
88

99
namespace Connect;
1010

11-
class Config
11+
/**
12+
* Class Config
13+
* @property string $apiKey
14+
* @property string $apiEndpoint
15+
* @package Connect
16+
*/
17+
class Config extends Model
1218
{
1319
/**
14-
* @var - string Connect QuickStart API Key
20+
* Connect QuickStart API Key
21+
* @var string
1522
*/
16-
public $apiKey;
23+
protected $apiKey;
1724

1825
/**
19-
* @var string - Connect QuickStart API Endpoint URI
26+
* Connect QuickStart API Endpoint URI
27+
* @var string
2028
*/
21-
public $apiEndpoint;
29+
protected $apiEndpoint;
2230

2331
/**
24-
* @var array of strings - list of products to work with
32+
* List of products to work with
33+
* @var string[]
2534
*/
2635
public $products;
2736

2837
/**
29-
* @var int - logLevel - what messages to write to log
38+
* What messages to write to log (legacy)
39+
* @var int
40+
*/
41+
public $logLevel = 2;
42+
43+
/**
44+
* Enable the debug mode
45+
* @var bool
3046
*/
31-
public $logLevel = LoggerInterface::LEVEL_INFO;
47+
public $debug = false;
3248

3349
/**
34-
* @var int - network interaction timeout, seconds
50+
* Network interaction timeout, seconds
51+
* @var int
3552
*/
3653
public $timeout = 50;
3754

3855
/**
39-
* @var bool - do we need to verify SSL certificate of server
56+
* Do we need to verify SSL certificate of server
57+
* @var bool
4058
*/
4159
public $sslVerifyHost = true;
4260

61+
4362
/**
44-
* @param mixed $config -
63+
* List of runtime providers
64+
* @var array
65+
*/
66+
protected $providers = [
67+
'curl' => '\Connect\RuntimeProvider\CurlProvider',
68+
'logger' => '\Connect\RuntimeProvider\LoggerProvider'
69+
];
70+
71+
/**
72+
* @param array|object|string $source
4573
* array -> has pairs of key/value to fill in config
4674
* string -> path to file to read config from
75+
*
4776
* @throws ConfigException
4877
* @throws ConfigPropertyInvalid
4978
* @throws \ReflectionException
5079
*/
51-
public function __construct($config)
80+
public function __construct($source)
5281
{
53-
if (is_string($config)) {
54-
try {
55-
$txt = file_get_contents($config);
56-
} catch (\Exception $e) {
57-
throw new ConfigException("Can't read file $config: " . $e->getMessage());
58-
}
59-
60-
try {
61-
$config = json_decode($txt, true);
62-
} catch (\Exception $e) {
63-
throw new ConfigException("Can't parse JSON in file $config: " . $e->getMessage());
64-
}
65-
}
82+
switch (gettype($source)) {
83+
case 'string':
6684

67-
if (!is_array($config)) {
68-
throw new ConfigException("Invalid argument for \\Connect\\Config class constructor: " . gettype($config));
69-
}
70-
71-
$ref = new \ReflectionClass($this);
72-
foreach ($ref->getProperties() as $prop) {
73-
$name = $prop->getName();
74-
75-
if (!isset($config[$name])) {
76-
continue;
77-
}
78-
79-
$value = $config[$name];
80-
81-
if ($name == 'products') {
82-
$prop->setValue($this, is_array($value) ? $value : array($value));
83-
} elseif ($name == 'logLevel') {
84-
$found = false;
85-
foreach (LoggerInterface::LEVELS as $k => $v) {
86-
if (strtoupper($value) == $v) {
87-
$prop->setValue($this, $k);
88-
$found = true;
89-
}
90-
}
91-
if (!$found) {
92-
throw new ConfigPropertyInvalid('Unknown log level', $name, $value);
85+
if (!is_readable($source)) {
86+
throw new ConfigException("Can't read file $source");
9387
}
94-
} elseif ($name == "sslVerifyHost") {
95-
if (!is_bool($value)) {
96-
throw new ConfigPropertyInvalid('Should be boolean', $name, $value);
88+
$source = json_decode(file_get_contents($source), true);
89+
if (!isset($source)) {
90+
throw new ConfigException("Can't parse JSON config file.");
9791
}
98-
$prop->setValue($this, $value);
99-
} else {
100-
$prop->setValue($this, $value);
101-
}
92+
break;
93+
case 'array':
94+
case 'object':
95+
break;
96+
default :
97+
throw new ConfigException("Invalid argument for \\Connect\\Config class constructor: " . gettype($source));
10298
}
99+
100+
parent::__construct($source);
103101
}
104102

105103
/**
106-
* Validate configuration
104+
* Validate and set the API Key property
105+
* @param $value
107106
* @throws ConfigPropertyMissed
108107
*/
109-
public function validate()
108+
public function setApiKey($value)
110109
{
111-
if (!isset($this->apiKey)) {
112-
throw new ConfigPropertyMissed('apiKey');
110+
if (empty($value)) {
111+
throw new ConfigPropertyMissed("Missing required property apiKey.");
113112
}
113+
$this->apiKey = trim($value);
114+
}
114115

115-
if (!isset($this->apiEndpoint)) {
116-
throw new ConfigPropertyMissed('apiEndpoint');
116+
/**
117+
* Validate and set the API Endpoint property
118+
* @param $value
119+
* @throws ConfigPropertyMissed
120+
*/
121+
public function setApiEndpoint($value)
122+
{
123+
if (empty($value)) {
124+
throw new ConfigPropertyMissed("Missing required property apiEndpoint.");
117125
}
118126

127+
$this->apiEndpoint = trim($value);
119128
}
120-
}
129+
}

src/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Class Connection
1313
* @package Connect
1414
*/
15-
class Connection
15+
class Connection extends Model
1616
{
1717
public $id;
1818
public $name;

src/Contact.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Class Contact
1313
* @package Connect
1414
*/
15-
class Contact
15+
class Contact extends Model
1616
{
1717
public $email;
1818
public $first_name;

src/ContactInfo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Class ContactInfo
1313
* @package Connect
1414
*/
15-
class ContactInfo
15+
class ContactInfo extends Model
1616
{
1717
public $address_line1;
1818
public $address_line2;

0 commit comments

Comments
 (0)