Skip to content

Commit 113558e

Browse files
authored
Merge pull request #14 from ingrammicro/autotesting
Autotesting
2 parents ee73f1d + 3a71b67 commit 113558e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+4166
-586
lines changed

.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/CHANGELOG.md export-ignore
2+
/.gitattributes export-ignore
3+
/.travis.yml export-ignore
4+
/phpunit.xml export-ignore
5+
/examples export-ignore
6+
/tests export-ignore
7+
/assets export-ignore

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,7 @@ fabric.properties
223223

224224
# composer
225225
/vendor
226-
composer.lock
226+
composer.lock
227+
228+
# codecov
229+
coverage.xml

.travis.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
language: php
2+
3+
php:
4+
- '5.6'
5+
- '7.0'
6+
- '7.1'
7+
- '7.2'
8+
9+
install:
10+
- composer install
11+
12+
script:
13+
- ./vendor/bin/phpunit -c ./phpunit.xml
14+
15+
after_success:
16+
- bash <(curl -s https://codecov.io/bash)

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Connect PHP fulfillment SDK Change Log
22

3+
## 1.1.0
4+
- Added autotesting coverage
5+
- Introduced new FulfillmentAutomation interface instead of former RequestsProcessor
6+
- Removed php Reflection as performance improvement
7+
- New Model system
8+
- Added Guzzle as defult http client
39
## 1.0.4
410
- Deprecation of var for public on accessible variables to be compilant with latest standards
511
- moved to psr-4 instead of psr-1

README.md

Lines changed: 19 additions & 20 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.com/ingrammicro/connect-php-sdk.svg?branch=master)](https://travis-ci.com/ingrammicro/connect-php-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) [![codecov](https://codecov.io/gh/ingrammicro/connect-php-sdk/branch/master/graph/badge.svg)](https://codecov.io/gh/ingrammicro/connect-php-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

@@ -29,13 +31,17 @@ Your code may use any scheduler to execute, from a simple cron to a cloud schedu
2931
Connect PHP SDK is available on [Packagist](https://packagist.org/packages/apsconnect/connect-sdk) (using semantic versioning), and installation via [Composer](https://getcomposer.org) is the recommended way to install Connect PHP SDK. Just add this line to your `composer.json` file:
3032

3133
```json
32-
"apsconnect/connect-sdk": "~1.0"
34+
{
35+
"require": {
36+
"apsconnect/connect-sdk": "^1.0"
37+
}
38+
}
3339
```
3440

3541
or run
3642

3743
```sh
38-
composer require apsconnect/connect-sdk
44+
composer require apsconnect/connect-sdk --no-dev --prefer-dist --classmap-authoritative
3945
```
4046

4147
Note that the `vendor` folder and the `vendor/autoload.php` script are generated by Composer
@@ -50,32 +56,25 @@ require_once "vendor/autoload.php";
5056
/**
5157
* Class ProductRequests
5258
*/
53-
class ProductRequests extends \Connect\RequestsProcessor
59+
class ProductRequests extends \Connect\FulfillmentAutomation
5460
{
55-
/**
56-
* ProductRequests constructor.
57-
* @param $config
58-
* @throws ReflectionException
59-
* @throws \Connect\ConfigException
60-
* @throws \Connect\ConfigPropertyInvalid
61-
* @throws \Connect\ConfigPropertyMissed
62-
*/
63-
function __construct($config)
64-
{
65-
parent::__construct($config);
66-
}
61+
6762

6863
/**
6964
* @param \Connect\Request $request
7065
* @return string|void
66+
* @return \Connect\ActivationTemplateResponse
67+
* @return \Connect\ActivationTileResponse
7168
* @throws Exception
7269
* @throws \Connect\Exception
7370
* @throws \Connect\Fail
7471
* @throws \Connect\Skip
72+
* @throws \Connect\Inquire
7573
*/
76-
function processRequest($request)
74+
75+
public function processRequest($request)
7776
{
78-
Connect\Logger::get()->info("Processing Request: " . $request->id . " for asset: " . $request->asset->id);
77+
$this->logger->info("Processing Request: " . $request->id . " for asset: " . $request->asset->id);
7978
switch ($request->type) {
8079
case "purchase":
8180
if($request->asset->params['email']->value == ""){
@@ -85,7 +84,7 @@ class ProductRequests extends \Connect\RequestsProcessor
8584
}
8685
foreach ($request->asset->items as $item) {
8786
if ($item->quantity > 1000000) {
88-
Connect\Logger::get()->info("Is Not possible to purchase product " . $item->id . " more than 1000000 time, requested: " . $item->quantity);
87+
$this->logger->info("Is Not possible to purchase product " . $item->id . " more than 1000000 time, requested: " . $item->quantity);
8988
throw new \Connect\Fail("Is Not possible to purchase product " . $item->id . " more than 1000000 time, requested: " . $item->quantity);
9089
}
9190
else {
@@ -112,11 +111,11 @@ class ProductRequests extends \Connect\RequestsProcessor
112111

113112
//Main Code Block
114113
try {
115-
$apiConfig = array(
114+
$apiConfig = new \Connect\Config([
116115
'apiKey' => 'Key_Available_in_ui',
117116
'apiEndpoint' => 'https://api.connect.cloud.im/public/v1',
118117
'products' => 'CN-631-322-641' #Optional value
119-
);
118+
]);
120119
$requests = new ProductRequests($apiConfig);
121120
$requests->process();
122121

composer.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,24 @@
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+
"guzzlehttp/guzzle": "~6.0"
15+
},
16+
"require-dev": {
17+
"phpunit/phpunit": "^5.7",
18+
"mockery/mockery": "^0.9"
1119
},
1220
"autoload": {
1321
"psr-4": {
1422
"Connect\\": "src/"
1523
}
24+
},
25+
"autoload-dev": {
26+
"psr-4": {
27+
"Test\\": "tests/"
28+
}
1629
}
1730
}

examples/config.json

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

examples/example.php

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@
55

66
class MyAppRequests extends \Connect\RequestsProcessor
77
{
8-
public function __construct()
9-
{
10-
parent::__construct('config.json');
11-
}
128

139
public function processRequest($req)
1410
{
15-
1611
$req->asset->tiers['customer']->name;
1712
$req->asset->tiers['tier1']->name;
1813

@@ -22,7 +17,7 @@ public function processRequest($req)
2217

2318
$p1 = $req->asset->params['param_a']->error('xxxx');
2419

25-
$p2 = new \Connect\Param('param_b', 'true');
20+
$p2 = new \Connect\Param(['param_b' => true]);
2621
$req->requestProcessor->updateParameters($req, [$p1, $p2]);
2722

2823
foreach ($req->asset->items as $item) {
@@ -49,16 +44,6 @@ public function processRequest($req)
4944

5045
$req->asset->params['param_a'];
5146

52-
// if (!isset($req->asset->params['param_a']))
53-
// throw new \Connect\Inquire(array( 'param_a' => 'ActivationID should be set' ));
54-
// throw new \Connect\Inquire(array(
55-
// $req->asset->params['param_a']->error('xxxx'),
56-
// $req->asset->params['param_b']->error('yyyy')->value('default')
57-
// ));
58-
59-
// if (!isset($req->asset->params['param_b']))
60-
// throw new \Connect\Fail(array( 'param_b' => 'Your activation code is already used' ));
61-
6247
throw new \Connect\Skip();
6348

6449
return "activation succeeded";
@@ -71,14 +56,8 @@ public function processRequest($req)
7156
$rp = new MyAppRequests();
7257
$rp->process();
7358

74-
// throw new Exception('Some unexpected error happened');
75-
7659
} catch (Exception $e) {
77-
7860
\Connect\Logger::get()->error($e->getMessage());
79-
// Dump to log all level records
8061
\Connect\Logger::get()->dump();
8162
}
8263

83-
// $rlist = $rp->listRequests(array('status' => 'inquiring'));
84-
// print_r($rlist);

phpunit.xml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<phpunit bootstrap="vendor/autoload.php" verbose="true" stopOnError="true" stopOnFailure="true">
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="ContactInfo">
19+
<file>tests/Unit/ContactInfoTest.php</file>
20+
</testsuite>
21+
<testsuite name="Fail">
22+
<file>tests/Unit/FailTest.php</file>
23+
</testsuite>
24+
<testsuite name="Inquire">
25+
<file>tests/Unit/InquireTest.php</file>
26+
</testsuite>
27+
<testsuite name="Message">
28+
<file>tests/Unit/MessageTest.php</file>
29+
</testsuite>
30+
<testsuite name="Skip">
31+
<file>tests/Unit/SkipTest.php</file>
32+
</testsuite>
33+
<testsuite name="ActivationTemplateResponse">
34+
<file>tests/Unit/ActivationTemplateResponseTest.php</file>
35+
</testsuite>
36+
<testsuite name="Logger">
37+
<file>tests/Unit/Logger/LogRecordTest.php</file>
38+
<file>tests/Unit/Logger/LogSessionTest.php</file>
39+
<file>tests/Unit/LoggerTest.php</file>
40+
</testsuite>
41+
<testsuite name="ActivationTileResponse">
42+
<file>tests/Unit/ActivationTileResponseTest.php</file>
43+
</testsuite>
44+
<testsuite name="RequestTest">
45+
<file>tests/Unit/RequestTest.php</file>
46+
</testsuite>
47+
<testsuite name="Configuration">
48+
<file>tests/Unit/ConfigurationTest.php</file>
49+
</testsuite>
50+
<testsuite name="Application">
51+
<file>tests/Unit/FulfillmentAutomationTest.php</file>
52+
</testsuite>
53+
<testsuite name="Models">
54+
<file>tests/Unit/ModelTest.php</file>
55+
<file>tests/Unit/ParamTest.php</file>
56+
</testsuite>
57+
</testsuites>
58+
</phpunit>

src/Asset.php

Lines changed: 3 additions & 3 deletions
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;
@@ -33,12 +33,12 @@ class Asset
3333
public $items;
3434

3535
/**
36-
* @var Param{id}
36+
* @var Param[]
3737
*/
3838
public $params;
3939

4040
/**
41-
* @var Tier{}
41+
* @var Tiers
4242
*/
4343
public $tiers;
4444
}

0 commit comments

Comments
 (0)