Skip to content

Commit

Permalink
Merge pull request #16 from higidi/master
Browse files Browse the repository at this point in the history
Primarily add support for SF 5
  • Loading branch information
simonhard authored Aug 25, 2021
2 parents fa22760 + cc19020 commit e894a7a
Show file tree
Hide file tree
Showing 20 changed files with 474 additions and 75 deletions.
5 changes: 3 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.gitattributes export-ignore
.gitignore export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.phpunit.xml.dist export-ignore
72 changes: 72 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: "Continuous Integration"

on:
push:
branches:
- master
pull_request: ~

jobs:
phpunit:
name: "PHPUnit"
runs-on: "ubuntu-20.04"
env:
SYMFONY_REQUIRE: ${{matrix.symfony-require}}
SYMFONY_DEPRECATIONS_HELPER: ${{matrix.symfony-deprecations-helper}}

strategy:
fail-fast: false
matrix:
php-version:
- "7.2"
- "7.3"
- "7.4"
dependencies:
- "highest"
stability:
- "stable"
symfony-require:
- "4.4.*"
- "5.3.*"
symfony-deprecations-helper:
- ""
include:
# Tests the lowest set of dependencies
- dependencies: "lowest"
stability: "stable"
php-version: "7.2"
symfony-deprecations-helper: "weak"

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
with:
fetch-depth: 2

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
if: "${{ matrix.php-version != '7.1' }}"
with:
php-version: "${{ matrix.php-version }}"

- name: "Globally install symfony/flex"
run: "composer global require --no-progress --no-scripts --no-plugins symfony/flex"

- name: "Enforce using stable dependencies"
run: "composer config minimum-stability stable"
if: "${{ matrix.stability == 'stable' }}"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
with:
dependency-versions: "${{ matrix.dependencies }}"
composer-options: "--prefer-dist"

- name: "Run PHPUnit"
run: "vendor/bin/phpunit --log-junit phpunit.xml"

- name: "Publish Test Report"
uses: "mikepenz/action-junit-report@v2"
if: "always()" # always run even if the previous step fails
with:
report_paths: "phpunit.xml"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ And declare the bundle in your `config/bundles.php` file:
```php
return [
// ...
VCR\VCRBundle\VCRVCRBundle::class => ['test' => true],
VCR\VCRBundle\VCRBundle::class => ['test' => true],
];

```

## Configuration reference

```yaml
vcrvcr:
vcr:
enabled: true
library_hooks:
stream_wrapper: false
Expand Down
29 changes: 21 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,31 @@
}
],
"require": {
"php-vcr/php-vcr": "^1.2",
"symfony/config": "^2.6|^3|^4",
"symfony/dependency-injection": "^2.6|^3|^4",
"symfony/filesystem": "^2.6|^3|^4",
"symfony/event-dispatcher": "^2.6|^3|^4",
"symfony/http-foundation": "^2.6|^3|^4",
"symfony/http-kernel": "^2.6|^3|^4",
"symfony/yaml": "^2.6|^3|^4"
"php": "^7.2",
"php-vcr/php-vcr": "^1.5",
"symfony/config": "^4|^5",
"symfony/dependency-injection": "^4|^5",
"symfony/filesystem": "^4|^5",
"symfony/event-dispatcher": "^4|^5",
"symfony/http-foundation": "^4|^5",
"symfony/http-kernel": "^4.4|^5",
"symfony/yaml": "^4|^5"
},
"require-dev": {
"neutron/temporary-filesystem": "^2.3",
"phpunit/phpunit": "^7.5",
"symfony/framework-bundle": "^4.4|^5.3",
"symfony/phpunit-bridge": "^5.2|^6"
},
"autoload": {
"psr-4": {
"VCR\\VCRBundle\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"VCR\\VCRBundle\\Tests\\Functional\\App\\": "tests/Functional/app",
"VCR\\VCRBundle\\Tests\\": "tests/"
}
}
}
24 changes: 24 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="php-vcr/vcr-bundle Functional Tests">
<directory>tests/Functional/</directory>
</testsuite>
<testsuite name="php-vcr/vcr-bundle Unit Tests">
<directory>tests/Unit/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src</directory>
<exclude>
<directory>src/Resources</directory>
</exclude>
</whitelist>
</filter>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
</phpunit>
39 changes: 21 additions & 18 deletions src/DataCollector/VCRDataCollector.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
declare(strict_types = 1);

namespace VCR\VCRBundle\DataCollector;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;

use VCR\VCRBundle\VCR\Logger;

class VCRDataCollector extends DataCollector
Expand All @@ -15,54 +15,57 @@ class VCRDataCollector extends DataCollector
public function __construct(Logger $logger)
{
$this->logger = $logger;
$this->reset();
}

public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null): void
{
$requests = $this->logger->getHttpRequests();
$requests = $this->logger->getHttpRequests();
$playbacks = $this->logger->getPlaybacks();

$this->data = array(
'requests' => $requests,
'playbacks' => $playbacks,
'count' => count($requests) + count($playbacks),
);
$this->data = [
'requests' => $requests,
'playbacks' => $playbacks,
'count' => count($requests) + count($playbacks),
];
}

public function getRequestsLogs()
public function getRequestsLogs(): array
{
return $this->data['requests'];
}

public function getPlaybacks()
public function getPlaybacks(): array
{
return $this->data['playbacks'];
}

public function getPlaybacksCount()
public function getPlaybacksCount(): int
{
return count($this->data['playbacks']);
}

public function getRequestsCount()
public function getRequestsCount(): int
{
return count($this->data['requests']);
}

public function getCount()
public function getCount(): int
{
return $this->data['count'];
}

public function getName()
public function getName(): string
{
return 'vcr_collector';
}

public function reset()
public function reset(): void
{
$this->data['requests'] = [];
$this->data['playbacks'] = [];
$this->data['count'] = 0;
$this->data = [
'requests' => [],
'playbacks' => [],
'count' => 0,
];
}
}
16 changes: 5 additions & 11 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types = 1);

namespace VCR\VCRBundle\DependencyInjection;

Expand All @@ -8,24 +9,17 @@

class Configuration implements ConfigurationInterface
{
protected $factories = array();

public function __construct(array $factories = array())
{
$this->factories = $factories;
}

public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('vcrvcr');
$treeBuilder = new TreeBuilder(VCRExtension::ALIAS);
$rootNode = $treeBuilder->getRootNode();

$this->addCassetteNode($rootNode);

return $treeBuilder;
}

protected function addCassetteNode(ArrayNodeDefinition $rootNode)
protected function addCassetteNode(ArrayNodeDefinition $rootNode): ArrayNodeDefinition
{
$rootNode
->children()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types = 1);

namespace VCR\VCRBundle\DependencyInjection;

Expand All @@ -7,9 +8,11 @@
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Config\FileLocator;

class VCRVCRExtension extends Extension
class VCRExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
const ALIAS = 'vcr';

public function load(array $configs, ContainerBuilder $container): void
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('listeners.yml');
Expand All @@ -32,13 +35,13 @@ public function load(array $configs, ContainerBuilder $container)
/**
* {@inheritdoc}
*/
public function getConfiguration(array $config, ContainerBuilder $container)
public function getConfiguration(array $config, ContainerBuilder $container): Configuration
{
return new Configuration();
}

public function getAlias()
public function getAlias(): string
{
return 'vcrvcr';
return static::ALIAS;
}
}
5 changes: 3 additions & 2 deletions src/EventListener/HttpRequestListener.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types = 1);

namespace VCR\VCRBundle\EventListener;

Expand All @@ -20,14 +21,14 @@ public function __construct(Logger $logger)
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents()
public static function getSubscribedEvents(): array
{
return array(
VCREvents::VCR_AFTER_HTTP_REQUEST => 'onHttpRequest',
);
}

public function onHttpRequest(AfterHttpRequestEvent $event)
public function onHttpRequest(AfterHttpRequestEvent $event): void
{
$this->logger->logHttpRequest(
$event->getRequest(),
Expand Down
5 changes: 3 additions & 2 deletions src/EventListener/PlaybackListener.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types = 1);

namespace VCR\VCRBundle\EventListener;

Expand All @@ -20,14 +21,14 @@ public function __construct(Logger $logger)
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents()
public static function getSubscribedEvents(): array
{
return array(
VCREvents::VCR_AFTER_PLAYBACK => 'onPlayback',
);
}

public function onPlayback(AfterPlaybackEvent $event)
public function onPlayback(AfterPlaybackEvent $event): void
{
$this->logger->logPlayback(
$event->getRequest(),
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
class: VCR\VCRBundle\DataCollector\VCRDataCollector
arguments: [ '@vcr.logger' ]
tags:
- { name: data_collector, template: "VCRVCRBundle:Profiler:collector", id: "vcr_collector" }
- { name: data_collector, template: "VCRBundle:Profiler:collector", id: "vcr_collector" }

vcr.logger:
class: VCR\VCRBundle\VCR\Logger
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/views/Profiler/call.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
</ul>

<div class="tab-content">
{% include 'VCRVCRBundle:Profiler:request.html.twig' with { 'index':index, 'request': log.request } %}
{% include 'VCRVCRBundle:Profiler:response.html.twig' with { 'index':index, 'response':log.response } %}
{% include 'VCRBundle:Profiler:request.html.twig' with { 'index':index, 'request': log.request } %}
{% include 'VCRBundle:Profiler:response.html.twig' with { 'index':index, 'response':log.response } %}
</div>

<div class="progress-striped" style="text-align:center;background-color:#ddd;margin:5px 0 30px 0;padding: 0;font-variant:small-caps;">
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/views/Profiler/calls.html.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="vcr_logs">
{% for index, log in logs %}
{% include 'VCRVCRBundle:Profiler:call.html.twig' %}
{% include 'VCRBundle:Profiler:call.html.twig' %}
{% endfor %}
</div>

{% include 'VCRVCRBundle:Profiler:javascript.html.twig' %}
{% include 'VCRBundle:Profiler:javascript.html.twig' %}
Loading

0 comments on commit e894a7a

Please sign in to comment.