Skip to content

Commit

Permalink
major bundle restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
nixilla committed Jun 20, 2018
1 parent 97422f0 commit 3963982
Show file tree
Hide file tree
Showing 30 changed files with 389 additions and 166 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vendor
bin
composer.lock
24 changes: 24 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
checks:
php:
code_rating: true
duplication: true
filter:
excluded_paths:
- spec/*

build:
environment:
variables:
COMPOSER_MEMORY_LIMIT: -1
dependencies:
before:
- pecl install xdebug
- echo "zend_extension=xdebug.so" > /home/scrutinizer/.phpenv/versions/7.2.0/etc/conf.d/xdebug.ini

tests:
override:
-
command: 'bin/phpspec run -f progress'
coverage:
file: 'build/logs/clover.xml'
format: 'clover'
15 changes: 10 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.2

env:
global:
- COMPOSER_MEMORY_LIMIT=-1

before_script:
- curl -s http://getcomposer.org/installer | php
- php composer.phar update --prefer-dist
- php composer.phar update --prefer-dist --ignore-platform-reqs

script: bin/phpspec run -fpretty --verbose

cache:
directories:
- $HOME/.composer/cache
- $HOME/.composer/cache

after_script:
- php bin/php-coveralls -v
29 changes: 0 additions & 29 deletions DependencyInjection/Configuration.php

This file was deleted.

16 changes: 0 additions & 16 deletions Logger/Api.php

This file was deleted.

70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# API Logger Bundle

[![Version](https://img.shields.io/packagist/v/nixilla/api-logger-bundle.svg?style=flat-square)](https://packagist.org/packages/nixilla/api-logger-bundle)
[![Build Status](https://travis-ci.org/nixilla/api-logger-bundle.svg?branch=develop)](https://travis-ci.org/nixilla/api-logger-bundle)
[![Coverage Status](https://coveralls.io/repos/github/nixilla/api-logger-bundle/badge.svg?branch=develop)](https://coveralls.io/github/nixilla/api-logger-bundle?branch=develop)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/nixilla/api-logger-bundle/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/nixilla/api-logger-bundle/?branch=develop)
[![License](https://poser.pugx.org/nixilla/api-logger-bundle/license.svg)](https://packagist.org/packages/nixilla/api-logger-bundle)

## Installation

Step 1: composer

```bash
composer require nixilla/api-logger-bundle
```

Step 2: enable bundle by adding it to AppKernel


```php
<?php

// app/AppKernel.php

if (in_array($this->getEnvironment(), array('dev', 'test'))) {
// your other dev bundles here
$bundles[] = new Nixilla\Api\LoggerBundle\NixillaApiLoggerBundle();
}

```

Step 3: configuration

If you're use HWIOAuthBundle and you want to monitor all OAuth API calls, you can now override default
`hwi_oauth.http_client` service used by this bundle by adding this few lines to your `config_dev.yml` file

```yaml
# app/config/config_dev.yml
imports:
- { resource: config.yml }

parameters:
buzz.client.class: Nixilla\Api\LoggerBundle\Proxy\Buzz\Client\Curl

services:
hwi_oauth.http_client:
class: "%buzz.client.class%"
calls:
- [ "setLogger", [ "@nixilla.api.logger" ] ]
```
If you're using `sensio/buzz-bundle`, you may want to override the `buzz.client` in config_dev.yml

```yaml
# app/config/config_dev.yml
imports:
- { resource: config.yml }
parameters:
buzz.client.class: Nixilla\Api\LoggerBundle\Proxy\Buzz\Client\Curl
services:
buzz.client:
class: "%buzz.client.class%"
calls:
- [ "setTimeout", [ "%buzz.client.timeout%" ] ]
- [ "setLogger", [ "@nixilla.api.logger" ] ]
```


72 changes: 0 additions & 72 deletions README.rst

This file was deleted.

29 changes: 20 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,38 @@
],
"homepage": "https://github.com/nixilla/api-logger-bundle",
"license": "MIT",
"minimum-stability": "stable",
"authors": [
{
"name": "Janusz Slota",
"email": "janusz.slota@nixilla.com"
}
],
"require": {
"php": ">=5.4",
"symfony/framework-bundle": "~2.3|~3.0",
"twig/twig": "~1.24|~2"
"php": ">=5.6",
"symfony/framework-bundle": "~2.3||~3",
"twig/twig": "~1.24||~2",
"kriswallsmith/buzz": "<0.16"
},
"require-dev" :{
"phpspec/phpspec": "^2.5|~3"
"phpspec/phpspec": "^4.3",
"pdepend/pdepend": "^2.5",
"phploc/phploc": "^4.0",
"phpmd/phpmd": "^2.6",
"sebastian/phpcpd": "^4.0",
"leanphp/phpspec-code-coverage": "^4.2",
"php-coveralls/php-coveralls": "^2.1",
"symfony/expression-language": "~2.3||~3"
},
"autoload": {
"psr-0": {
"Nixilla\\Api\\LoggerBundle": ""
"psr-4": {
"Nixilla\\Api\\LoggerBundle\\": "src/"
}
},
"config": {
"bin-dir": "bin"
},
"target-dir": "Nixilla/Api/LoggerBundle"
"bin-dir": "bin",
"platform": {
"php": "7.2"
}
}
}
15 changes: 15 additions & 0 deletions phpspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
suites:
default:
namespace: Nixilla\Api\LoggerBundle
psr4_prefix: Nixilla\Api\LoggerBundle

extensions:
LeanPHP\PhpSpec\CodeCoverage\CodeCoverageExtension:
blacklist: [ 'spec', 'vendor' ]
format:
- clover
- html

output:
clover: build/logs/clover.xml
html: build/coverage
45 changes: 45 additions & 0 deletions spec/DataCollector/ApiDataCollectorSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace spec\Nixilla\Api\LoggerBundle\DataCollector;

use Nixilla\Api\LoggerBundle\DataCollector\ApiDataCollector;
use Nixilla\Api\LoggerBundle\Logger\Api;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;

class ApiDataCollectorSpec extends ObjectBehavior
{
function let(Api $logger)
{
$this->beConstructedWith($logger);
}

function it_is_initializable()
{
$this->shouldHaveType(ApiDataCollector::class);
$this->shouldHaveType(DataCollector::class);
}

function it_implements_getName()
{
$this->getName()->shouldNotReturn(null);
}

function it_implements_collect_method(Api $logger, Request $request, Response $response)
{
$logger->getCalls()->shouldBeCalled()->willReturn([['time' => 5 ]]);
$logger->getCallsCount()->shouldBeCalled()->willReturn(5);

$this->collect($request, $response);

$this->getCalls()->shouldNotReturn(null);
$this->getCallsCount()->shouldReturn(5);

$this->getTime()->shouldReturn(5);

$this->reset();
}
}
27 changes: 27 additions & 0 deletions spec/DependencyInjection/NixillaApiLoggerExtensionSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace spec\Nixilla\Api\LoggerBundle\DependencyInjection;

use Nixilla\Api\LoggerBundle\DependencyInjection\NixillaApiLoggerExtension;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;

class NixillaApiLoggerExtensionSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(NixillaApiLoggerExtension::class);
$this->shouldHaveType(Extension::class);
}

function it_implements_required_load_method(ContainerBuilder $container)
{
$container->fileExists(Argument::any())->willReturn(true);
$container->setDefinition(Argument::any(), Argument::any())->shouldBeCalled();
$container->setParameter(Argument::any(), Argument::any())->shouldBeCalled();

$this->load([], $container);
}
}
Loading

0 comments on commit 3963982

Please sign in to comment.