Skip to content

Commit d65e2aa

Browse files
committed
Major update and cleanup
1 parent 77911ca commit d65e2aa

File tree

86 files changed

+604
-969
lines changed

Some content is hidden

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

86 files changed

+604
-969
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
*.idea*
2-
*.sublime-*
31
**/vendor/*
42
coverage/*
53
notes.md
64
tests/fixtures/cassette*
7-
/.php_cs.cache
85
/.php_cs
96
composer.lock
107
.phpunit.result.cache

.php-cs-fixer.dist.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
'@PSR12' => true,
66
'@Symfony' => true,
77
'@Symfony:risky' => true,
8-
'@PHP73Migration' => true,
9-
'@PHP71Migration:risky' => true,
8+
'@PHP80Migration' => true,
9+
'@PHP80Migration:risky' => true,
1010
'@PHPUnit84Migration:risky' => true,
11-
// Causes too much problems for now, fix later
12-
'declare_strict_types' => false,
1311
])
1412
->setFinder(
1513
PhpCsFixer\Finder::create()

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ $ composer require --dev php-vcr/php-vcr
9797

9898
PHP-VCR depends on:
9999

100-
* PHP 7.2+
100+
* PHP 8
101101
* Curl extension
102102
* [symfony/event-dispatcher](https://github.com/symfony/event-dispatcher)
103103
* [symfony/yaml](https://github.com/symfony/yaml)

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@
2222
"symfony/event-dispatcher": "^5.0"
2323
},
2424
"require-dev": {
25-
"phpunit/phpunit": "^8.4.0",
25+
"phpunit/phpunit": "^9.5.0",
2626
"mikey179/vfsstream": "^1.6.10",
2727
"phpstan/phpstan": "^0.12.92",
2828
"phpstan/phpstan-beberlei-assert": "^0.12.0",
2929
"thecodingmachine/phpstan-strict-rules": "^0.12",
30-
"sebastian/version": "^1.0.3|^2.0",
3130
"friendsofphp/php-cs-fixer": "^3.0",
3231
"phpstan/phpstan-phpunit": "^0.12.22",
3332
"phpstan/extension-installer": "^1.1"

phpstan-baseline.neon

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Access to an undefined property object\\:\\:\\$data\\.$#"
5+
count: 2
6+
path: src/VCR/CodeTransform/AbstractCodeTransform.php
7+
8+
-
9+
message: "#^Access to an undefined property object\\:\\:\\$datalen\\.$#"
10+
count: 1
11+
path: src/VCR/CodeTransform/AbstractCodeTransform.php
12+
13+
-
14+
message: "#^Parameter \\#1 \\$string of function substr expects string, string\\|false given\\.$#"
15+
count: 1
16+
path: src/VCR/Util/HttpUtil.php
17+
18+
-
19+
message: "#^Cannot call method record\\(\\) on VCR\\\\Cassette\\|null\\.$#"
20+
count: 1
21+
path: src/VCR/Videorecorder.php
22+
23+
-
24+
message: "#^Parameter \\#3 \\$cassette of class VCR\\\\Event\\\\BeforeRecordEvent constructor expects VCR\\\\Cassette, VCR\\\\Cassette\\|null given\\.$#"
25+
count: 1
26+
path: src/VCR/Videorecorder.php
27+

phpstan.neon

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1+
includes:
2+
- phpstan-baseline.neon
3+
14
parameters:
2-
level: 7
5+
level: max
36
paths:
47
- src
58
- tests/VCR
6-
ignoreErrors:
7-
# This part of PHP is not very well documented, resulting PHPStan's definitions not being accurate
8-
- "#Access to an undefined property object::\\$data\\.#"
9-
- "#Access to an undefined property object::\\$datalen\\.#"
10-
# PHPStan cannot detect that strrpos will succeed (because of Assertion above) in HttpUtil::parseStatus
11-
- '#Parameter .* \$str(ing)? of function substr expects string, string\|false given.#'

src/VCR/Cassette.php

Lines changed: 11 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace VCR;
46

57
use VCR\Storage\Storage;
@@ -10,61 +12,20 @@
1012
class Cassette
1113
{
1214
/**
13-
* Casette name.
14-
*
15-
* @var string
16-
*/
17-
protected $name;
18-
19-
/**
20-
* VCR configuration.
21-
*
22-
* @var Configuration
15+
* @param Storage<array> $storage
2316
*/
24-
protected $config;
25-
26-
/**
27-
* Storage used to store records and request pairs.
28-
*
29-
* @var Storage<array>
30-
*/
31-
protected $storage;
32-
33-
/**
34-
* Creates a new cassette.
35-
*
36-
* @param string $name name of the cassette
37-
* @param Configuration $config configuration to use for this cassette
38-
* @param Storage<array> $storage storage to use for requests and responses
39-
*
40-
* @throws \VCR\VCRException if cassette name is in an invalid format
41-
*/
42-
public function __construct(string $name, Configuration $config, Storage $storage)
43-
{
44-
$this->name = $name;
45-
$this->config = $config;
46-
$this->storage = $storage;
17+
public function __construct(
18+
protected string $name,
19+
protected Configuration $config,
20+
protected Storage $storage
21+
) {
4722
}
4823

49-
/**
50-
* Returns true if a response was recorded for specified request.
51-
*
52-
* @param Request $request request to check if it was recorded
53-
*
54-
* @return bool true if a response was recorded for specified request
55-
*/
5624
public function hasResponse(Request $request): bool
5725
{
5826
return null !== $this->playback($request);
5927
}
6028

61-
/**
62-
* Returns a response for given request or null if not found.
63-
*
64-
* @param Request $request request
65-
*
66-
* @return Response|null response for specified request
67-
*/
6829
public function playback(Request $request): ?Response
6930
{
7031
foreach ($this->storage as $recording) {
@@ -77,48 +38,30 @@ public function playback(Request $request): ?Response
7738
return null;
7839
}
7940

80-
/**
81-
* Records a request and response pair.
82-
*
83-
* @param Request $request request to record
84-
* @param Response $response response to record
85-
*/
8641
public function record(Request $request, Response $response): void
8742
{
8843
if ($this->hasResponse($request)) {
8944
return;
9045
}
9146

92-
$recording = [
47+
$this->storage->storeRecording([
9348
'request' => $request->toArray(),
9449
'response' => $response->toArray(),
95-
];
96-
97-
$this->storage->storeRecording($recording);
50+
]);
9851
}
9952

100-
/**
101-
* Returns the name of the current cassette.
102-
*
103-
* @return string current cassette name
104-
*/
10553
public function getName(): string
10654
{
10755
return $this->name;
10856
}
10957

110-
/**
111-
* Returns true if the cassette was created recently.
112-
*/
11358
public function isNew(): bool
11459
{
11560
return $this->storage->isNew();
11661
}
11762

11863
/**
119-
* Returns a list of callbacks to configured request matchers.
120-
*
121-
* @return callable[] list of callbacks to configured request matchers
64+
* @return callable[]
12265
*/
12366
protected function getRequestMatchers(): array
12467
{

src/VCR/CodeTransform/AbstractCodeTransform.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace VCR\CodeTransform;
46

57
use function stream_get_filters;

src/VCR/CodeTransform/CurlCodeTransform.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace VCR\CodeTransform;
46

57
use VCR\Util\Assertion;

src/VCR/CodeTransform/SoapCodeTransform.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace VCR\CodeTransform;
46

57
use VCR\Util\Assertion;

0 commit comments

Comments
 (0)