Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor tests #26

Merged
merged 11 commits into from
Feb 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# EditorConfig: http://EditorConfig.org

root = true

[*]
end_of_line = lf
charset = utf-8
indent_style = space
indent_size = 2
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: php
php:
- '7.1'
before_install:
- composer install
script:
- composer tests
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Iugu para PHP

[![Build status](https://img.shields.io/travis/iugu/iugu-php.svg)](https://travis-ci.org/iugu/iugu-php)

## Requisitos

* PHP 5.4+
Expand Down Expand Up @@ -53,7 +55,7 @@ Acesse [iugu.com/documentacao](http://iugu.com/documentacao) para referência

## Testes

Instale as dependências. Iugu-PHP utiliza SimpleTest.
Instale as dependências:

```
composer update
Expand All @@ -62,5 +64,6 @@ composer update
Execute a comitiva de testes:

```
php ./test/Iugu.php
composer tests
```

22 changes: 13 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"description": "iugu PHP Library",
"homepage": "https://iugu.com",
"keywords": [
"iugu",
"pagamentos",
"api"
"iugu",
"pagamentos",
"api"
],
"license": "MIT",
"authors": [
Expand All @@ -15,15 +15,19 @@
}
],
"require": {
"php": ">=5.4",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*"
"php": ">=5.4",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*"
},
"require-dev": {
"simpletest/simpletest": "1.1.5"
"phpunit/phpunit": "^6",
"php-vcr/php-vcr": "^1.4"
},
"autoload": {
"classmap": ["lib/Iugu/"]
"classmap": ["lib/Iugu/"]
},
"scripts": {
"tests": "./vendor/bin/phpunit --colors tests"
}
}
22 changes: 11 additions & 11 deletions lib/Iugu/APIRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ private function encodeParameters($method, $url, $data = [])
$method = strtolower($method);

switch ($method) {
case 'get':
case 'delete':
$paramsInURL = Iugu_Utilities::arrayToParams($data);
$data = null;
$url = (strpos($url, '?')) ? $url.'&'.$paramsInURL : $url.'?'.$paramsInURL;
break;
case 'post':
case 'put':
$data = Iugu_Utilities::arrayToParams($data);
break;
}
case 'get':
case 'delete':
$paramsInURL = Iugu_Utilities::arrayToParams($data);
$data = null;
$url = (strpos($url, '?')) ? $url.'&'.$paramsInURL : $url.'?'.$paramsInURL;
break;
case 'post':
case 'put':
$data = Iugu_Utilities::arrayToParams($data);
break;
}

return [$url, $data];
}
Expand Down
48 changes: 24 additions & 24 deletions lib/Iugu/APIResource.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
<?php

class APIResource extends Iugu_Object
class APIResource extends Iugu_Object
{

private static $_apiRequester = null;

public static function convertClassToObjectType()
public static function convertClassToObjectType()
{
$object_type = str_replace('Iugu_', '', get_called_class());
$object_type = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $object_type));

return mb_strtolower($object_type, 'UTF-8');
}

public static function objectBaseURI()
public static function objectBaseURI()
{
$object_type = self::convertClassToObjectType();
switch ($object_type) {
// Add Exceptions as needed
case 'charge':
return $object_type;
case 'payment_token':
return $object_type;
case 'bank_verification':
return $object_type;
case 'marketplace':
return $object_type; // WORKAROUND MARKETPLACE
default:
return $object_type . 's';
case 'charge':
return $object_type;
case 'payment_token':
return $object_type;
case 'bank_verification':
return $object_type;
case 'marketplace':
return $object_type; // WORKAROUND MARKETPLACE
default:
return $object_type . 's';
}
}

public static function API()
public static function API()
{
if (self::$_apiRequester == null) {
self::$_apiRequester = new Iugu_APIRequest();
Expand All @@ -40,7 +40,7 @@ public static function API()
return self::$_apiRequester;
}

public static function endpointAPI($object = null, $uri_path = '')
public static function endpointAPI($object = null, $uri_path = '')
{
$path = '';

Expand All @@ -61,19 +61,19 @@ public static function endpointAPI($object = null, $uri_path = '')
return Iugu::getBaseURI() . $uri_path . '/' . self::objectBaseURI() . $path;
}

public static function url($object = null)
public static function url($object = null)
{
return self::endpointAPI($object);
}

protected static function createFromResponse($response)
protected static function createFromResponse($response)
{
return Iugu_Factory::createFromResponse(
self::convertClassToObjectType(), $response
);
}

protected static function createAPI($attributes = [])
protected static function createAPI($attributes = [])
{
$response = self::createFromResponse(
self::API()->request(
Expand All @@ -87,7 +87,7 @@ protected static function createAPI($attributes = [])
return $response;
}

protected function deleteAPI()
protected function deleteAPI()
{
if ($this['id'] == null) {
return false;
Expand All @@ -108,7 +108,7 @@ protected function deleteAPI()
return true;
}

protected static function searchAPI($options = [])
protected static function searchAPI($options = [])
{
try {
$response = self::API()->request(
Expand All @@ -117,13 +117,13 @@ protected static function searchAPI($options = [])

return self::createFromResponse($response);
} catch (Exception $e) {

}

return [];
}

protected static function fetchAPI($key)
protected static function fetchAPI($key)
{
try {
$response = static::API()->request(
Expand All @@ -136,7 +136,7 @@ protected static function fetchAPI($key)
}
}

protected function refreshAPI()
protected function refreshAPI()
{
if ($this->is_new()) {
return false;
Expand All @@ -161,7 +161,7 @@ protected function refreshAPI()
return true;
}

protected function saveAPI()
protected function saveAPI()
{
try {
$response = self::API()->request(
Expand Down
18 changes: 9 additions & 9 deletions lib/exemplos.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"name" => 'nome',
"reply_to" => '[email protected]',
));

// verificação de subconta
$validate = Iugu_Account::create(Array(
"id" => 'CLIENT_ID ',
Expand All @@ -44,28 +44,28 @@
"bank_cc" => '999999-9',
)
));

// retornando os dados do mktplace
Iugu::setApiKey('TOKEN_IUGU'); // user token como parametro
$account = Iugu_Account::fetch("CLIENT_ID"); // id da conta como parametro



// transferendo valor para subconta
$transfer = Iugu_Transfer::create(Array(
"receiver_id" => "CLIENT_ID", // id da conta recebedora
"amount_cents" => '1000' // valor em centavos = R$ 10,00
));


// retirando valor da subconta
Iugu::setApiKey('TOKEN_IUGU'); // Chave do user
$transfer = Iugu_Transfer::create(Array(
"receiver_id" => "CLIENT_ID", // chave da conta mestre ou da conta recebedora
"amount_cents" => $numValorCentavos
));


// pedido de retirada de dinheiro
Iugu::setApiKey('TOKEN_IUGU'); // Chave do user
$withdraw = Iugu_Account::create(Array(
Expand Down
28 changes: 0 additions & 28 deletions test/Iugu.php

This file was deleted.

51 changes: 0 additions & 51 deletions test/Iugu/ChargeTest.php

This file was deleted.

Loading