Skip to content

Commit

Permalink
Merge pull request #13 from mybuilder/php-8
Browse files Browse the repository at this point in the history
Update to PHP8
  • Loading branch information
maxbaldanza authored Sep 28, 2022
2 parents 3b1332a + f40c9ff commit 97c64cb
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 64 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Test

on: [push]

jobs:
run:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.4', '8.1']
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
steps:
# —— Setup Github actions 🐙 —————————————————————————————————————————————
- name: Checkout
uses: actions/checkout@v2

# https://github.com/shivammathur/setup-php (community)
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, xml, ctype, iconv, intl
coverage: xdebug #optional

# https://github.com/marketplace/actions/setup-php-action#problem-matchers
- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"

# https://github.com/marketplace/actions/setup-php-action#problem-matchers
- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

# —— Composer 🧙‍️ —————————————————————————————————————————————————————————
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache composer dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
# Use composer.json for key, if composer.lock is not committed.
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
key: ${{ runner.os }}-composer-${{ matrix.php-versions }}-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-${{ matrix.php-versions }}-

- name: Validate Composer.json
run: composer validate

- name: Install Composer dependencies
run: composer update --no-progress --no-suggest --prefer-dist --optimize-autoloader

## —— Test ✅ ———————————————————————————————————————————————————————————
- name: Run Tests
run: php bin/phpunit --coverage-text
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
/bin/
/build/
composer.lock
composer.json.old
phpunit.xml
.phpunit.result.cache
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
[![Build Status](https://travis-ci.org/mybuilder/when-i-work-api.svg?branch=master)](https://travis-ci.org/mybuilder/when-i-work-api)

When I Work library
=====================

This library support connection and retrieval of data from WhenIWork.com API. PHP 7.1 required.
This library support connection and retrieval of data from WhenIWork.com API. At least PHP 7.4 is required.

Docs:
http://dev.wheniwork.com

```php
$jmsSerializer = new JMS\Serializer\Serializer();
$client = new GuzzleHttp\Client()

require_once __DIR__ . '/vendor/autoload.php';

use MyBuilder\Library\WhenIWork\Repository\PayrollRepository;
use MyBuilder\Library\WhenIWork\Repository\UserRepository;
use MyBuilder\Library\WhenIWork\Service\WhenIWorkApi;

$serializer = JMS\Serializer\SerializerBuilder::create()->build();
$client = new GuzzleHttp\Client();
$whenIWorkApi = new WhenIWorkApi($client, 'your-developer-key', 'user-email', 'user-password');
$userRepository = new Repository\WhenIWorkUserRepository($whenIWorkApi, $jmsSerializer);
$userRepository = new UserRepository($whenIWorkApi, $serializer);
$payrollRepository = new PayrollRepository($whenIWorkApi, $serializer);
```

### List of all users:
Expand All @@ -24,11 +30,10 @@ $users = $userRepository->findAll();
### List of all payroll periods:

```php
$payrolls = $payrollRepository->findAll();
$payrolls = $payrollRepository->findByPeriod();
```



Todos:

- Add more models that are supported via WhenIWork API
Expand Down
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
"description": "Library that support connections and retrieve data from WhenIWork.com API",
"minimum-stability": "stable",
"license": "MIT",
"version": "0.5.2",
"require": {
"php": ">=7.1",
"jms/serializer": "~1.1",
"guzzlehttp/guzzle": "^6.2"
"php": ">=7.4",
"doctrine/collections": "^1.7",
"guzzlehttp/guzzle": "^6.2||^7.0",
"jms/serializer": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "~5.0",
"mockery/mockery": "~0.9"
"phpunit/phpunit": "^9.0",
"mockery/mockery": "^1.0"
},
"autoload": {
"psr-4": { "MyBuilder\\Library\\WhenIWork\\": "src" }
},
"config": {
"bin-dir": "bin"
"bin-dir": "bin",
"sort-packages": true
},
"extra": {
"branch-alias": {
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php"
>
<testsuites>
Expand Down
1 change: 0 additions & 1 deletion src/Exception/WhenIWorkApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@
*/
class WhenIWorkApiException extends \RuntimeException
{

}
1 change: 0 additions & 1 deletion src/Model/Payroll.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,5 +287,4 @@ public function setUpdatedAt(DateTime $updatedAt = null): void
{
$this->updatedAt = $updatedAt;
}

}
1 change: 0 additions & 1 deletion src/Model/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,5 +495,4 @@ public function setCreatedAt($createdAt): void
{
$this->createdAt = $createdAt;
}

}
1 change: 0 additions & 1 deletion src/Repository/TimeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,4 @@ public function findByUserIdAndPeriod($userId, \DateTime $startDate, \DateTime $

return $this->deserializeModel($timesRaw, 'ArrayCollection<'. Time::class .'>');
}

}
1 change: 0 additions & 1 deletion src/Repository/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ public function findAll()

return $this->deserializeModel($usersRaw, 'ArrayCollection<'. User::class .'>');
}

}
12 changes: 2 additions & 10 deletions src/Repository/WhenIWorkRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,8 @@
*/
abstract class WhenIWorkRepository
{
/**
* @var WhenIWorkApi
*/
protected $whenIWorkApi;

/**
* @var SerializerInterface
*/
protected $serializer;
protected WhenIWorkApi $whenIWorkApi;
protected SerializerInterface $serializer;

public function __construct(
WhenIWorkApi $whenIWorkApi,
Expand All @@ -38,5 +31,4 @@ protected function deserializeModel($data, $modelType)
{
return $this->serializer->deserialize(json_encode($data), $modelType, 'json');
}

}
5 changes: 1 addition & 4 deletions src/Service/WhenIWorkApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ class WhenIWorkApi

private $apiToken;

/**
* @var Client
*/
private $client;
private Client $client;

public function __construct(
Client $client,
Expand Down
17 changes: 8 additions & 9 deletions tests/Repository/UserRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
namespace MyBuilder\Bundle\WhenIWorkBundle\Tests\Service\Repository;

use JMS\Serializer\SerializerInterface;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use MyBuilder\Library\WhenIWork\Service\WhenIWorkApi;
use MyBuilder\Library\WhenIWork\Repository\UserRepository;
use MyBuilder\Library\WhenIWork\Repository\WhenIWorkRepository;
use PHPUnit\Framework\TestCase;

/**
* @group unit
* @coversDefaultClass MyBuilder\Library\WhenIWork\Repository\UserRepository
* @coversDefaultClass \MyBuilder\Library\WhenIWork\Repository\UserRepository
*/
class UserRepositoryTest extends \PHPUnit_Framework_TestCase
class UserRepositoryTest extends TestCase
{
/**
* @var UserRepository
*/
private $userRepository;
use MockeryPHPUnitIntegration;

private UserRepository $userRepository;

/**
* @var SerializerInterface|\Mockery\MockInterface
Expand All @@ -28,15 +29,14 @@ class UserRepositoryTest extends \PHPUnit_Framework_TestCase
*/
private $whenIWorkApi;

public function setUp()
public function setUp(): void
{
$this->whenIWorkApi = \Mockery::mock(WhenIWorkApi::class);
$this->serializer = \Mockery::mock(SerializerInterface::class);
$this->userRepository = new UserRepository(
$this->whenIWorkApi,
$this->serializer
);

}

public function test_it_delegates_find_by_id_to_api(): void
Expand All @@ -61,7 +61,6 @@ public function test_it_is_an_instance_of_when_i_work_repository(): void
$this->assertInstanceOf(WhenIWorkRepository::class, $this->userRepository);
}


public function test_it_delegates_find_all_to_api(): void
{
$this->whenIWorkApi
Expand Down
11 changes: 7 additions & 4 deletions tests/Service/WhenIWorkApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
use GuzzleHttp\Client;
use GuzzleHttp\Exception\BadResponseException;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use Mockery;
use MyBuilder\Library\WhenIWork\Exception\WhenIWorkApiException;
use MyBuilder\Library\WhenIWork\Service\WhenIWorkApi;
use GuzzleHttp\Psr7\Stream;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;

/**
* @group unit
* @coversDefaultClass \MyBuilder\Library\WhenIWork\Service\WhenIWorkApi
*/
class WhenIWorkApiTest extends \PHPUnit_Framework_TestCase
class WhenIWorkApiTest extends TestCase
{
private const DEVELOPER_KEY = '12345';
private const USERNAME = '[email protected]';
Expand All @@ -37,9 +40,9 @@ class WhenIWorkApiTest extends \PHPUnit_Framework_TestCase
*/
private $request;

public function setUp()
public function setUp(): void
{
$this->request = Mockery::mock('GuzzleHttp\Psr7\Message\Request');
$this->request = Mockery::mock(ResponseInterface::class);
$this->guzzleClient = Mockery::mock(Client::class);

$this->whenIWorkApi = new WhenIWorkApi(
Expand All @@ -60,7 +63,7 @@ public function test_setup_and_exception_from_guzzle_client(): void
array('headers' => array('W-Token' => self::TOKEN))
)
->once()
->andThrow(new BadResponseException('', new Request('GET', 'foo')));
->andThrow(new BadResponseException('', new Request('GET', 'foo'), new Response()));

$this->expectException(WhenIWorkApiException::class);
$this->whenIWorkApi->usersListingUsers();
Expand Down

0 comments on commit 97c64cb

Please sign in to comment.