Skip to content

Commit 101f795

Browse files
authored
Merge pull request #2 from ddrv-fork/master
Added github actions CI configuration
2 parents d3baed3 + aa13448 commit 101f795

13 files changed

+325
-11
lines changed

.github/CODE_OF_CONDUCT.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
## Our Standards
8+
9+
Examples of behavior that contributes to creating a positive environment include:
10+
11+
* Using welcoming and inclusive language
12+
* Being respectful of differing viewpoints and experiences
13+
* Gracefully accepting constructive criticism
14+
* Focusing on what is best for the community
15+
* Showing empathy towards other community members
16+
17+
Examples of unacceptable behavior by participants include:
18+
19+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
20+
* Trolling, insulting/derogatory comments, and personal or political attacks
21+
* Public or private harassment
22+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
23+
* Other conduct which could reasonably be considered inappropriate in a professional setting
24+
25+
## Our Responsibilities
26+
27+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28+
29+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30+
31+
## Scope
32+
33+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34+
35+
## Enforcement
36+
37+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [email protected]. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38+
39+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40+
41+
## Attribution
42+
43+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44+
45+
[homepage]: http://contributor-covenant.org
46+
[version]: http://contributor-covenant.org/version/1/4/

.github/CONTRIBUTING.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Contributing
2+
3+
## Report an issue
4+
5+
Please follow the guidelines below when creating an issue so that your issue can be more promptly resolved:
6+
* Provide information including: the version of PHP and This package, the type of operating system and Web server;
7+
* Provide the complete error call stack if available;
8+
* Describe the steps for reproducing the issue. It would be even better if you could provide code to reproduce the issue;
9+
10+
Do not report an issue if you are asking how to use some feature. You should use the `README.md` file.
11+
12+
Before you report an issue, please search through existing issues to see if your issue is already reported or fixed to make sure you are not reporting a duplicated issue. Also make sure you have the latest version of package and see if the issue still exists.

.github/FUNDING.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
custom: "https://www.paypal.me/ddrv"

.github/ISSUE_TEMPLATE/bug_report.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: 'Bug'
5+
labels: bug
6+
assignees: ddrv
7+
8+
---
9+
10+
### What steps will reproduce the problem?
11+
12+
### What is the expected result?
13+
14+
### What do you get instead?
15+
16+
### Additional info
17+
18+
| Q | A
19+
| ---------------- | ---
20+
| Library version | 1.?
21+
| PHP version | ?
22+
| Operating system | ?

.github/ISSUE_TEMPLATE/custom.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
name: Custom issue template
3+
about: Describe this issue template's purpose here.
4+
title: ''
5+
labels: ''
6+
assignees: ddrv
7+
8+
---
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: feature
6+
assignees: ddrv
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

.github/PULL_REQUEST_TEMPLATE.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
| Q | A
2+
| ------------- | ---
3+
| Bug fix? | yes/no
4+
| New feature? | yes/no
5+
| Tickets | Fix #...

.github/workflows/ci.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
tests:
7+
runs-on: ubuntu-latest
8+
9+
strategy:
10+
matrix:
11+
php: [7.0, 7.1, 7.2, 7.3, 7.4, 8.0]
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v2
16+
17+
- name: Setup PHP
18+
uses: shivammathur/setup-php@v2
19+
with:
20+
php-version: ${{ matrix.php }}
21+
coverage: none
22+
23+
- name: Validate composer.json and composer.lock
24+
run: composer validate
25+
26+
- name: Install dependencies
27+
run: composer install --prefer-dist --no-progress --no-interaction --no-suggest
28+
29+
- name: Check code style
30+
run: vendor/bin/phpcs
31+
32+
- name: Run test suite
33+
run: vendor/bin/phpunit

composer.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@
2020
"psr/http-factory": "^1.0"
2121
},
2222
"require-dev": {
23-
"cache/array-adapter": "^1.0",
24-
"nyholm/psr7": "^1.3",
25-
"phpunit/phpunit": "^6.5",
23+
"guzzlehttp/psr7": "^1.7",
24+
"phpunit/phpunit": ">=6.5",
2625
"squizlabs/php_codesniffer": "^3.5",
2726
"webclient/fake-http-client": "^1.0"
2827
},

phpunit.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="vendor/autoload.php" colors="true">
2+
<phpunit bootstrap="vendor/autoload.php" colors="true" cacheResult="false">
33
<testsuites>
44
<testsuite name="all">
55
<directory>tests</directory>

stuff/ArrayCache.php

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?php
2+
3+
namespace Stuff\Webclient\Extension\Cache;
4+
5+
use DateInterval;
6+
use Psr\SimpleCache\CacheInterface;
7+
8+
class ArrayCache implements CacheInterface
9+
{
10+
11+
/**
12+
* @var array
13+
*/
14+
private $storage = [];
15+
16+
/**
17+
* @inheritDoc
18+
*/
19+
public function get($key, $default = null)
20+
{
21+
if (!$this->has($key)) {
22+
return $default;
23+
}
24+
return $this->storage[$key]['value'];
25+
}
26+
27+
/**
28+
* @inheritDoc
29+
*/
30+
public function set($key, $value, $ttl = null)
31+
{
32+
$item = [
33+
'value' => $value,
34+
];
35+
$seconds = is_int($ttl) ? $ttl : 0;
36+
if ($ttl instanceof DateInterval) {
37+
if ($ttl->invert === 1) {
38+
return false;
39+
}
40+
$seconds = $ttl->days * 86400 + $ttl->h * 3600 + $ttl->i * 60 + $ttl->s;
41+
}
42+
if ($seconds) {
43+
$item['expired'] = time() + $seconds;
44+
}
45+
$this->storage[$key] = $item;
46+
return true;
47+
}
48+
49+
/**
50+
* @inheritDoc
51+
*/
52+
public function delete($key)
53+
{
54+
if (array_key_exists($key, $this->storage)) {
55+
unset($this->storage[$key]);
56+
}
57+
return true;
58+
}
59+
60+
/**
61+
* @inheritDoc
62+
*/
63+
public function clear()
64+
{
65+
$this->storage = [];
66+
return true;
67+
}
68+
69+
/**
70+
* @inheritDoc
71+
*/
72+
public function getMultiple($keys, $default = null)
73+
{
74+
$result = [];
75+
foreach ($keys as $key) {
76+
$result[$key] = $this->get($key, $default);
77+
}
78+
return $result;
79+
}
80+
81+
/**
82+
* @inheritDoc
83+
*/
84+
public function setMultiple($values, $ttl = null)
85+
{
86+
$result = true;
87+
foreach ($values as $key => $value) {
88+
if (!$this->set($key, $value, $ttl)) {
89+
$result = false;
90+
}
91+
}
92+
return $result;
93+
}
94+
95+
/**
96+
* @inheritDoc
97+
*/
98+
public function deleteMultiple($keys)
99+
{
100+
$result = true;
101+
foreach ($keys as $key) {
102+
if (!$this->delete($key)) {
103+
$result = false;
104+
}
105+
}
106+
return $result;
107+
}
108+
109+
/**
110+
* @inheritDoc
111+
*/
112+
public function has($key)
113+
{
114+
if (!array_key_exists($key, $this->storage)) {
115+
return false;
116+
}
117+
if (!array_key_exists('value', $this->storage[$key])) {
118+
unset($this->storage[$key]);
119+
return false;
120+
}
121+
$expired = false;
122+
if (array_key_exists('expired', $this->storage[$key])) {
123+
$expired = time() >= $this->storage[$key]['expired'];
124+
}
125+
if ($expired) {
126+
unset($this->storage[$key]);
127+
return false;
128+
}
129+
return true;
130+
}
131+
}

stuff/HttpFactory.php

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Stuff\Webclient\Extension\Cache;
6+
7+
use GuzzleHttp\Psr7\Response;
8+
use GuzzleHttp\Psr7\Stream;
9+
use Psr\Http\Message\ResponseFactoryInterface;
10+
use Psr\Http\Message\ResponseInterface;
11+
use Psr\Http\Message\StreamFactoryInterface;
12+
use Psr\Http\Message\StreamInterface;
13+
14+
class HttpFactory implements ResponseFactoryInterface, StreamFactoryInterface
15+
{
16+
public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
17+
{
18+
return new Response($code, [], null, '1.1', $reasonPhrase);
19+
}
20+
21+
public function createStream(string $content = ''): StreamInterface
22+
{
23+
$resource = fopen('php://temp', 'w+');
24+
fwrite($resource, $content);
25+
rewind($resource);
26+
return $this->createStreamFromResource($resource);
27+
}
28+
29+
public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface
30+
{
31+
$resource = fopen($filename, $mode);
32+
return $this->createStreamFromResource($resource);
33+
}
34+
35+
public function createStreamFromResource($resource): StreamInterface
36+
{
37+
return new Stream($resource);
38+
}
39+
}

tests/ClientTest.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
namespace Tests\Webclient\Extension\Cache;
66

7-
use Cache\Adapter\PHPArray\ArrayCachePool;
8-
use Nyholm\Psr7\Factory\Psr17Factory;
9-
use Nyholm\Psr7\Request;
7+
use GuzzleHttp\Psr7\Request;
108
use PHPUnit\Framework\TestCase;
119
use Psr\Http\Client\ClientExceptionInterface;
10+
use Stuff\Webclient\Extension\Cache\ArrayCache;
1211
use Stuff\Webclient\Extension\Cache\Handler;
12+
use Stuff\Webclient\Extension\Cache\HttpFactory;
1313
use Webclient\Extension\Cache\Client;
1414
use Webclient\Fake\Client as FakeClient;
1515

@@ -21,9 +21,8 @@ class ClientTest extends TestCase
2121
*/
2222
public function testClient()
2323
{
24-
$items = [];
25-
$factory = new Psr17Factory();
26-
$cache = new ArrayCachePool(null, $items);
24+
$factory = new HttpFactory();
25+
$cache = new ArrayCache();
2726
$client = new Client(
2827
new FakeClient(new Handler($factory, $factory)),
2928
$cache,
@@ -34,6 +33,5 @@ public function testClient()
3433
$request = new Request('GET', 'http://localhost?etag=ok', ['User-Agent' => 'webclient/1.0']);
3534
$response = $client->sendRequest($request);
3635
$this->assertSame(200, $response->getStatusCode());
37-
$this->fail('Help me cover this with tests, please');
3836
}
3937
}

0 commit comments

Comments
 (0)