Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

update dev dependencies #117

Closed
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: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
language: php

php:
- 7.1
- 7.2
- 7.3
- 7.4snapshot
- 7.4
- 8.0
- nightly

env:
- dependencies=highest
Expand All @@ -13,6 +13,7 @@ env:
matrix:
fast_finish: true
allow_failures:
- php: 8.0
- php: nightly

cache:
Expand All @@ -34,7 +35,7 @@ jobs:
script: composer phpstan
env: dependencies=highest
- stage: Code coverage
php: 7.3
php: 7.4
env: dependencies=highest
script: vendor/bin/phpunit --verbose --coverage-clover=build/logs/clover.xml
after_success:
Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
}
],
"require": {
"php": "^7.1",
"php": "^7.3|^8.0",
"ext-json": "*",
"doctrine/inflector": "^1.3",
"doctrine/inflector": "^1.4",
"fig/http-message-util": "^1.1",
"php-http/client-common": "^1.5|^2.0",
"php-http/client-implementation": "^1.0",
Expand All @@ -30,11 +30,11 @@
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.13",
"php-coveralls/php-coveralls": "^2.0",
"php-http/mock-client": "^1.1",
"phpstan/phpstan": "^0.10.3",
"phpunit/phpunit": "^7.3",
"symfony/phpunit-bridge": "^4.1"
"php-coveralls/php-coveralls": "^2.4",
"php-http/mock-client": "^1.4",
"phpstan/phpstan": "^0.12",
"phpunit/phpunit": "^9.5",
"symfony/phpunit-bridge": "^5.2"
},
"replace": {
"paragonie/random_compat": "2.*",
Expand Down
8 changes: 1 addition & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@
bootstrap="tests/bootstrap.php"
>
<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak_vendors" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0" />
</php>

<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>

<testsuites>
<testsuite name="Close.io Api Wrapper Test Suite">
<directory>tests</directory>
Expand Down
14 changes: 12 additions & 2 deletions src/Exception/CloseIoResponseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,21 @@ class CloseIoResponseException extends CloseIoException
* @param CloseIoResponse $response The response that threw the exception
* @param Throwable|null $previous The previous throwable used for the exception chaining
*/
public function __construct(CloseIoResponse $response, Throwable $previous = null)
final public function __construct(CloseIoResponse $response, Throwable $previous = null)
{
$this->response = $response;

parent::__construct($response->getDecodedBody()['error'] ?? self::UNKNOWN_ERROR_MESSAGE, 0, $previous);
$error = $response->getDecodedBody()['error'] ?? null;
$errorMessage = self::UNKNOWN_ERROR_MESSAGE;

if (is_array($error)) {
$errorMessage = $error['message'] ?? self::UNKNOWN_ERROR_MESSAGE;
}
if (is_string($error)) {
$errorMessage = $error;
}

parent::__construct($errorMessage , 0, $previous);
}

/**
Expand Down
28 changes: 28 additions & 0 deletions src/Library/Doctrine/InflectorSingleton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace LooplineSystems\CloseIoApiWrapper\Library\Doctrine;

use Doctrine\Inflector\InflectorFactory;
use Doctrine\Inflector\Inflector;

final class InflectorSingleton
{
/**
* @var Inflector
*/
private static $instance;

private function __construct() {}

/**
* @return Inflector
*/
public static function getInstance()
{
if (self::$instance === null) {
self::$instance = InflectorFactory::create()->build();
}

return self::$instance;
}
}
8 changes: 4 additions & 4 deletions src/Library/ObjectHydrateHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace LooplineSystems\CloseIoApiWrapper\Library;

use Doctrine\Common\Inflector\Inflector;
use LooplineSystems\CloseIoApiWrapper\Library\Doctrine\InflectorSingleton;
use LooplineSystems\CloseIoApiWrapper\Library\Exception\InvalidParamException;

trait ObjectHydrateHelperTrait
Expand All @@ -34,7 +34,7 @@ public function hydrate(array $data, array $nestedObjects = [], array $method_ma

if (!\in_array($key, $nestedObjects)) {
// get setter method for each key in data
$setter = 'set' . Inflector::classify($key);
$setter = 'set' . InflectorSingleton::getInstance()->classify($key);
if (method_exists($this, $setter)) {
$this->$setter($value);
} else {
Expand All @@ -56,8 +56,8 @@ public function hydrate(array $data, array $nestedObjects = [], array $method_ma
$nestedObject = $data[$currentNestedObject];
$NestedObjectCollection = [];
foreach ($nestedObject as $nestedObjectArguments) {
$singluarizedName = Inflector::singularize($currentNestedObject);
$className = Inflector::classify($singluarizedName);
$singluarizedName = InflectorSingleton::getInstance()->singularize($currentNestedObject);
$className = InflectorSingleton::getInstance()->classify($singluarizedName);
$classNameWithFQDN = str_replace('Library', 'Model', __NAMESPACE__) . '\\' . $className;
$reflection = new \ReflectionClass($classNameWithFQDN);
$nestedObjectClass = $reflection->newInstanceArgs([$nestedObjectArguments]);
Expand Down
6 changes: 3 additions & 3 deletions src/Model/Opportunity.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ public function getConfidence()
*/
public function setConfidence($confidence)
{
if (\is_int($confidence)) {
$this->confidence = $confidence;
} else {
if (!\is_int($confidence)) {
throw new InvalidParamException('Opportunity confidence must be of type int');
}

$this->confidence = $confidence;

return $this;
}

Expand Down
13 changes: 7 additions & 6 deletions tests/Api/CustomFieldApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
use LooplineSystems\CloseIoApiWrapper\CloseIoApiWrapper;
use LooplineSystems\CloseIoApiWrapper\Configuration;
use LooplineSystems\CloseIoApiWrapper\Model\CustomField;
use PHPUnit\Framework\TestCase;

class CustomFieldApiTest extends \PHPUnit\Framework\TestCase
class CustomFieldApiTest extends TestCase
{
/**
* @var HttpClientMock
Expand All @@ -33,7 +34,7 @@ class CustomFieldApiTest extends \PHPUnit\Framework\TestCase
*/
protected $customFieldApi;

protected function setUp()
protected function setUp(): void
{
$this->httpClient = new HttpClientMock();

Expand All @@ -50,7 +51,7 @@ protected function setUp()
*
* @group legacy
*/
public function testGetCustomFields($customFieldArray)
public function testGetCustomFields($customFieldArray): void
{
$responseBody = [
'has_more' => false,
Expand All @@ -74,7 +75,7 @@ public function testGetCustomFields($customFieldArray)
*
* @group legacy
*/
public function testUpdateCustomField($customField)
public function testUpdateCustomField($customField): void
{
$customField->setId('TestId');
$originalCustomField = clone $customField;
Expand All @@ -94,7 +95,7 @@ public function testUpdateCustomField($customField)
/**
* @return array
*/
public function customFieldDataProvider()
public function customFieldDataProvider(): array
{
return [
[
Expand All @@ -106,7 +107,7 @@ public function customFieldDataProvider()
/**
* @return array
*/
public function customFieldArrayProvider()
public function customFieldArrayProvider(): array
{
$customField = new CustomField(['name' => 'Test Name']);

Expand Down
19 changes: 10 additions & 9 deletions tests/Api/LeadsApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
use LooplineSystems\CloseIoApiWrapper\CloseIoApiWrapper;
use LooplineSystems\CloseIoApiWrapper\Configuration;
use LooplineSystems\CloseIoApiWrapper\Model\Lead;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\RequestInterface;

class LeadsApiTest extends \PHPUnit\Framework\TestCase
class LeadsApiTest extends TestCase
{
/**
* @var HttpClientMock
Expand All @@ -34,7 +35,7 @@ class LeadsApiTest extends \PHPUnit\Framework\TestCase
*/
protected $leadApi;

protected function setUp()
protected function setUp(): void
{
$this->httpClient = new HttpClientMock();

Expand All @@ -52,7 +53,7 @@ protected function setUp()
*
* @group legacy
*/
public function testAddLead(Lead $lead)
public function testAddLead(Lead $lead): void
{
$this->httpClient->addResponse(MessageFactoryDiscovery::find()->createResponse(200, null, [], '{"id":"TestIdString"}'));

Expand All @@ -73,7 +74,7 @@ public function testAddLead(Lead $lead)
*
* @group legacy
*/
public function testGetLead($lead)
public function testGetLead($lead): void
{
$lead->setId('TestId');

Expand All @@ -91,7 +92,7 @@ public function testGetLead($lead)
*
* @group legacy
*/
public function testGetAllLeads($leadsArray)
public function testGetAllLeads($leadsArray): void
{
$responseBody = [
'has_more' => false,
Expand All @@ -116,7 +117,7 @@ public function testGetAllLeads($leadsArray)
*
* @group legacy
*/
public function testUpdateLead($lead)
public function testUpdateLead($lead): void
{
$lead->setId('TestId');
$originalLead = clone $lead;
Expand All @@ -136,7 +137,7 @@ public function testUpdateLead($lead)
/**
* @group legacy
*/
public function testDeleteLead()
public function testDeleteLead(): void
{
$this->httpClient->addResponse(MessageFactoryDiscovery::find()->createResponse(200, null, [], '{}'));

Expand All @@ -152,7 +153,7 @@ public function testDeleteLead()
/**
* @return array
*/
public function leadProvider()
public function leadProvider(): array
{
return [
[
Expand All @@ -164,7 +165,7 @@ public function leadProvider()
/**
* @return array
*/
public function leadArrayProvider()
public function leadArrayProvider(): array
{
$lead = new Lead(['name' => 'Test Name', 'description' => 'Test Description']);

Expand Down
30 changes: 17 additions & 13 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use LooplineSystems\CloseIoApiWrapper\Client;
use LooplineSystems\CloseIoApiWrapper\CloseIoRequest;
use LooplineSystems\CloseIoApiWrapper\Configuration;
use LooplineSystems\CloseIoApiWrapper\Exception\CloseIoException;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\RequestInterface;

Expand All @@ -36,15 +37,21 @@ class ClientTest extends TestCase
*/
private $client;

protected function setUp()
/**
* @var Configuration
*/
private $configuration;

protected function setUp(): void
{
$this->configuration = new Configuration('foo');
$this->httpClient = new HttpClientMock();
$this->client = new Client(new Configuration('foo'), $this->httpClient);
$this->client = new Client($this->configuration, $this->httpClient);
}

public function testGetConfiguration(): void
{
$this->assertAttributeSame($this->client->getConfiguration(), 'configuration', $this->client);
$this->assertSame($this->client->getConfiguration(), $this->configuration);
}

public function testGet(): void
Expand Down Expand Up @@ -154,31 +161,28 @@ public function sendRequestDataProvider(): array
];
}

/**
* @expectedException \LooplineSystems\CloseIoApiWrapper\Exception\CloseIoException
*/
public function testSendRequestThrowsOnBadRequest(): void
{
$this->expectException(CloseIoException::class);

$this->httpClient->addException(new TransferException());

$this->client->sendRequest(new CloseIoRequest(RequestMethodInterface::METHOD_GET, '/foo/'));
}

/**
* @expectedException \LooplineSystems\CloseIoApiWrapper\Exception\CloseIoException
*/
public function testSendRequestThrowsOnResponseThatHasErrors(): void
{
$this->expectException(CloseIoException::class);

$this->httpClient->addResponse(MessageFactoryDiscovery::find()->createResponse(StatusCodeInterface::STATUS_OK, null, [], '{"error":"foo"}'));

$this->client->sendRequest(new CloseIoRequest(RequestMethodInterface::METHOD_GET, '/foo/'));
}

/**
* @expectedException \LooplineSystems\CloseIoApiWrapper\Exception\CloseIoException
*/
public function testSendRequestThrowsOnResponseWithStatusCodeDifferentFromOk()
public function testSendRequestThrowsOnResponseWithStatusCodeDifferentFromOk(): void
{
$this->expectException(CloseIoException::class);

$this->httpClient->addResponse(MessageFactoryDiscovery::find()->createResponse(StatusCodeInterface::STATUS_NOT_FOUND, null, [], '{}'));

$this->client->sendRequest(new CloseIoRequest(RequestMethodInterface::METHOD_GET, '/foo/'));
Expand Down
Loading