Skip to content

Commit e894a7a

Browse files
authored
Merge pull request #16 from higidi/master
Primarily add support for SF 5
2 parents fa22760 + cc19020 commit e894a7a

File tree

20 files changed

+474
-75
lines changed

20 files changed

+474
-75
lines changed

.gitattributes

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
.gitattributes export-ignore
2-
.gitignore export-ignore
1+
.gitattributes export-ignore
2+
.gitignore export-ignore
3+
.phpunit.xml.dist export-ignore
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: "Continuous Integration"
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request: ~
8+
9+
jobs:
10+
phpunit:
11+
name: "PHPUnit"
12+
runs-on: "ubuntu-20.04"
13+
env:
14+
SYMFONY_REQUIRE: ${{matrix.symfony-require}}
15+
SYMFONY_DEPRECATIONS_HELPER: ${{matrix.symfony-deprecations-helper}}
16+
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
php-version:
21+
- "7.2"
22+
- "7.3"
23+
- "7.4"
24+
dependencies:
25+
- "highest"
26+
stability:
27+
- "stable"
28+
symfony-require:
29+
- "4.4.*"
30+
- "5.3.*"
31+
symfony-deprecations-helper:
32+
- ""
33+
include:
34+
# Tests the lowest set of dependencies
35+
- dependencies: "lowest"
36+
stability: "stable"
37+
php-version: "7.2"
38+
symfony-deprecations-helper: "weak"
39+
40+
steps:
41+
- name: "Checkout"
42+
uses: "actions/checkout@v2"
43+
with:
44+
fetch-depth: 2
45+
46+
- name: "Install PHP"
47+
uses: "shivammathur/setup-php@v2"
48+
if: "${{ matrix.php-version != '7.1' }}"
49+
with:
50+
php-version: "${{ matrix.php-version }}"
51+
52+
- name: "Globally install symfony/flex"
53+
run: "composer global require --no-progress --no-scripts --no-plugins symfony/flex"
54+
55+
- name: "Enforce using stable dependencies"
56+
run: "composer config minimum-stability stable"
57+
if: "${{ matrix.stability == 'stable' }}"
58+
59+
- name: "Install dependencies with Composer"
60+
uses: "ramsey/composer-install@v1"
61+
with:
62+
dependency-versions: "${{ matrix.dependencies }}"
63+
composer-options: "--prefer-dist"
64+
65+
- name: "Run PHPUnit"
66+
run: "vendor/bin/phpunit --log-junit phpunit.xml"
67+
68+
- name: "Publish Test Report"
69+
uses: "mikepenz/action-junit-report@v2"
70+
if: "always()" # always run even if the previous step fails
71+
with:
72+
report_paths: "phpunit.xml"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ And declare the bundle in your `config/bundles.php` file:
2222
```php
2323
return [
2424
// ...
25-
VCR\VCRBundle\VCRVCRBundle::class => ['test' => true],
25+
VCR\VCRBundle\VCRBundle::class => ['test' => true],
2626
];
2727

2828
```
2929

3030
## Configuration reference
3131

3232
```yaml
33-
vcrvcr:
33+
vcr:
3434
enabled: true
3535
library_hooks:
3636
stream_wrapper: false

composer.json

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,31 @@
1010
}
1111
],
1212
"require": {
13-
"php-vcr/php-vcr": "^1.2",
14-
"symfony/config": "^2.6|^3|^4",
15-
"symfony/dependency-injection": "^2.6|^3|^4",
16-
"symfony/filesystem": "^2.6|^3|^4",
17-
"symfony/event-dispatcher": "^2.6|^3|^4",
18-
"symfony/http-foundation": "^2.6|^3|^4",
19-
"symfony/http-kernel": "^2.6|^3|^4",
20-
"symfony/yaml": "^2.6|^3|^4"
13+
"php": "^7.2",
14+
"php-vcr/php-vcr": "^1.5",
15+
"symfony/config": "^4|^5",
16+
"symfony/dependency-injection": "^4|^5",
17+
"symfony/filesystem": "^4|^5",
18+
"symfony/event-dispatcher": "^4|^5",
19+
"symfony/http-foundation": "^4|^5",
20+
"symfony/http-kernel": "^4.4|^5",
21+
"symfony/yaml": "^4|^5"
22+
},
23+
"require-dev": {
24+
"neutron/temporary-filesystem": "^2.3",
25+
"phpunit/phpunit": "^7.5",
26+
"symfony/framework-bundle": "^4.4|^5.3",
27+
"symfony/phpunit-bridge": "^5.2|^6"
2128
},
2229
"autoload": {
2330
"psr-4": {
2431
"VCR\\VCRBundle\\": "src/"
2532
}
33+
},
34+
"autoload-dev": {
35+
"psr-4": {
36+
"VCR\\VCRBundle\\Tests\\Functional\\App\\": "tests/Functional/app",
37+
"VCR\\VCRBundle\\Tests\\": "tests/"
38+
}
2639
}
2740
}

phpunit.xml.dist

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit colors="true" bootstrap="vendor/autoload.php">
3+
<testsuites>
4+
<testsuite name="php-vcr/vcr-bundle Functional Tests">
5+
<directory>tests/Functional/</directory>
6+
</testsuite>
7+
<testsuite name="php-vcr/vcr-bundle Unit Tests">
8+
<directory>tests/Unit/</directory>
9+
</testsuite>
10+
</testsuites>
11+
12+
<filter>
13+
<whitelist>
14+
<directory>src</directory>
15+
<exclude>
16+
<directory>src/Resources</directory>
17+
</exclude>
18+
</whitelist>
19+
</filter>
20+
21+
<listeners>
22+
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
23+
</listeners>
24+
</phpunit>
Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
2+
declare(strict_types = 1);
23

34
namespace VCR\VCRBundle\DataCollector;
45

56
use Symfony\Component\HttpFoundation\Request;
67
use Symfony\Component\HttpFoundation\Response;
78
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
8-
99
use VCR\VCRBundle\VCR\Logger;
1010

1111
class VCRDataCollector extends DataCollector
@@ -15,54 +15,57 @@ class VCRDataCollector extends DataCollector
1515
public function __construct(Logger $logger)
1616
{
1717
$this->logger = $logger;
18+
$this->reset();
1819
}
1920

20-
public function collect(Request $request, Response $response, \Exception $exception = null)
21+
public function collect(Request $request, Response $response, \Throwable $exception = null): void
2122
{
22-
$requests = $this->logger->getHttpRequests();
23+
$requests = $this->logger->getHttpRequests();
2324
$playbacks = $this->logger->getPlaybacks();
2425

25-
$this->data = array(
26-
'requests' => $requests,
27-
'playbacks' => $playbacks,
28-
'count' => count($requests) + count($playbacks),
29-
);
26+
$this->data = [
27+
'requests' => $requests,
28+
'playbacks' => $playbacks,
29+
'count' => count($requests) + count($playbacks),
30+
];
3031
}
3132

32-
public function getRequestsLogs()
33+
public function getRequestsLogs(): array
3334
{
3435
return $this->data['requests'];
3536
}
3637

37-
public function getPlaybacks()
38+
public function getPlaybacks(): array
3839
{
3940
return $this->data['playbacks'];
4041
}
4142

42-
public function getPlaybacksCount()
43+
public function getPlaybacksCount(): int
4344
{
4445
return count($this->data['playbacks']);
4546
}
4647

47-
public function getRequestsCount()
48+
public function getRequestsCount(): int
4849
{
4950
return count($this->data['requests']);
5051
}
5152

52-
public function getCount()
53+
public function getCount(): int
5354
{
5455
return $this->data['count'];
5556
}
5657

57-
public function getName()
58+
public function getName(): string
5859
{
5960
return 'vcr_collector';
6061
}
6162

62-
public function reset()
63+
public function reset(): void
6364
{
64-
$this->data['requests'] = [];
65-
$this->data['playbacks'] = [];
66-
$this->data['count'] = 0;
65+
$this->data = [
66+
'requests' => [],
67+
'playbacks' => [],
68+
'count' => 0,
69+
];
6770
}
6871
}

src/DependencyInjection/Configuration.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types = 1);
23

34
namespace VCR\VCRBundle\DependencyInjection;
45

@@ -8,24 +9,17 @@
89

910
class Configuration implements ConfigurationInterface
1011
{
11-
protected $factories = array();
12-
13-
public function __construct(array $factories = array())
14-
{
15-
$this->factories = $factories;
16-
}
17-
18-
public function getConfigTreeBuilder()
12+
public function getConfigTreeBuilder(): TreeBuilder
1913
{
20-
$treeBuilder = new TreeBuilder();
21-
$rootNode = $treeBuilder->root('vcrvcr');
14+
$treeBuilder = new TreeBuilder(VCRExtension::ALIAS);
15+
$rootNode = $treeBuilder->getRootNode();
2216

2317
$this->addCassetteNode($rootNode);
2418

2519
return $treeBuilder;
2620
}
2721

28-
protected function addCassetteNode(ArrayNodeDefinition $rootNode)
22+
protected function addCassetteNode(ArrayNodeDefinition $rootNode): ArrayNodeDefinition
2923
{
3024
$rootNode
3125
->children()

src/DependencyInjection/VCRVCRExtension.php renamed to src/DependencyInjection/VCRExtension.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types = 1);
23

34
namespace VCR\VCRBundle\DependencyInjection;
45

@@ -7,9 +8,11 @@
78
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
89
use Symfony\Component\Config\FileLocator;
910

10-
class VCRVCRExtension extends Extension
11+
class VCRExtension extends Extension
1112
{
12-
public function load(array $configs, ContainerBuilder $container)
13+
const ALIAS = 'vcr';
14+
15+
public function load(array $configs, ContainerBuilder $container): void
1316
{
1417
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
1518
$loader->load('listeners.yml');
@@ -32,13 +35,13 @@ public function load(array $configs, ContainerBuilder $container)
3235
/**
3336
* {@inheritdoc}
3437
*/
35-
public function getConfiguration(array $config, ContainerBuilder $container)
38+
public function getConfiguration(array $config, ContainerBuilder $container): Configuration
3639
{
3740
return new Configuration();
3841
}
3942

40-
public function getAlias()
43+
public function getAlias(): string
4144
{
42-
return 'vcrvcr';
45+
return static::ALIAS;
4346
}
4447
}

src/EventListener/HttpRequestListener.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types = 1);
23

34
namespace VCR\VCRBundle\EventListener;
45

@@ -20,14 +21,14 @@ public function __construct(Logger $logger)
2021
/**
2122
* {@inheritDoc}
2223
*/
23-
public static function getSubscribedEvents()
24+
public static function getSubscribedEvents(): array
2425
{
2526
return array(
2627
VCREvents::VCR_AFTER_HTTP_REQUEST => 'onHttpRequest',
2728
);
2829
}
2930

30-
public function onHttpRequest(AfterHttpRequestEvent $event)
31+
public function onHttpRequest(AfterHttpRequestEvent $event): void
3132
{
3233
$this->logger->logHttpRequest(
3334
$event->getRequest(),

src/EventListener/PlaybackListener.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types = 1);
23

34
namespace VCR\VCRBundle\EventListener;
45

@@ -20,14 +21,14 @@ public function __construct(Logger $logger)
2021
/**
2122
* {@inheritDoc}
2223
*/
23-
public static function getSubscribedEvents()
24+
public static function getSubscribedEvents(): array
2425
{
2526
return array(
2627
VCREvents::VCR_AFTER_PLAYBACK => 'onPlayback',
2728
);
2829
}
2930

30-
public function onPlayback(AfterPlaybackEvent $event)
31+
public function onPlayback(AfterPlaybackEvent $event): void
3132
{
3233
$this->logger->logPlayback(
3334
$event->getRequest(),

0 commit comments

Comments
 (0)