Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
cs fixes
Browse files Browse the repository at this point in the history
added jobs to travis
added symfony/polyfill-mbstring
updated phpstan/phpstan
  • Loading branch information
Daniel Bannert committed Jun 6, 2018
1 parent 831a59c commit 206ec14
Show file tree
Hide file tree
Showing 14 changed files with 186 additions and 148 deletions.
9 changes: 8 additions & 1 deletion .php_cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<?php
use Narrowspark\CS\Config\Config;

$config = new Config();
$config = new Config(null, [
'native_function_invocation' => [
'exclude' => [
'headers_sent',
'header',
],
],
]);
$config->getFinder()
->files()
->in(__DIR__)
Expand Down
66 changes: 43 additions & 23 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,56 @@
language: php

dist: trusty
sudo: false
language: php

matrix:
include:
- php: 7.1
env: SETUP=basic CS=true
- php: 7.1
env: SETUP=basic PHPSTAN=true
- php: 7.2
env: SETUP=basic SEND_COVERAGE=true PHPUNIT=true
fast_finish: true
env:
global:
- TEST="./vendor/bin/phpunit --verbose"
- COMPOSER_UP="composer update --no-interaction --prefer-dist --no-progress --profile --no-suggest"

cache:
directories:
- $HOME/.composer/cache
- $HOME/.composer/cache/files
- $HOME/.php-cs-fixer

before_install:
- chmod a+x ./build/travis/script.sh && chmod a+x ./build/travis/after_success.sh
- stty cols 120
- mkdir -p ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d
- chmod a+x ./build/travis/configure_php.sh
- ./build/travis/configure_php.sh

install:
- travis_retry composer install --no-interaction --prefer-dist --no-progress --profile --no-suggest

script:
- ./build/travis/script.sh
- composer global require hirak/prestissimo
- $COMPOSER_UP

after_success:
- ./build/travis/after_success.sh
jobs:
include:
- stage: Test
php: 7.1
env: REMOVE_XDEBUG=true
- stage: Test
php: 7.2
env: REMOVE_XDEBUG=true

- stage: Coding standard
php: 7.2
env: REMOVE_XDEBUG=true
script:
- ./vendor/bin/php-cs-fixer fix --verbose --diff --dry-run
- stage: Coding standard
php: 7.2
env: REMOVE_XDEBUG=false
script:
- ./vendor/bin/phpstan analyse -c phpstan.neon -l 7 src

- stage: Coverage
php: 7.2
env: REMOVE_XDEBUG=false
script:
- bash -xc "$TEST -c ./phpunit.xml.dist --coverage-clover=coverage.xml"
after_success:
- bash <(curl -s https://codecov.io/bash)

notifications:
email: false
webhooks:
urls:
- https://webhooks.gitter.im/e/5886ad33ac123a7c06b0
email:
on_success: never
on_failure: change
6 changes: 6 additions & 0 deletions build/travis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Build Scripts

This directory contains the scripts that travis uses to build the project.

Tests on the entire [`narrowspark/http-emitter`](https://github.com/narrowspark/http-emitter) repository,
and then sends code coverage reports out to [Codecov](https://codecov.io/github/narrowspark/http-emitter).
5 changes: 0 additions & 5 deletions build/travis/after_success.sh

This file was deleted.

7 changes: 7 additions & 0 deletions build/travis/configure_php.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

if [[ "$REMOVE_XDEBUG" = true ]]; then
phpenv config-rm xdebug.ini;
fi

echo date.timezone = Europe/Berlin >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
23 changes: 0 additions & 23 deletions build/travis/script.sh

This file was deleted.

21 changes: 13 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@
],
"require": {
"php": "^7.1",
"psr/http-message": "^1.0"
"psr/http-message": "^1.0",
"symfony/polyfill-mbstring": "^1.8.0"
},
"provide": {
"psr/container-implementation": "^1.0",
"psr/http-message-implementation": "^1.0"
},
"require-dev": {
"narrowspark/php-cs-fixer-config": "^2.0",
"phpstan/phpstan": "^0.8",
"phpunit/phpunit": "^6.0",
"zendframework/zend-diactoros": "^1.3"
"narrowspark/php-cs-fixer-config": "^3.0.1",
"phpstan/phpstan": "^0.9",
"phpstan/phpstan-phpunit": "^0.9",
"phpstan/phpstan-strict-rules": "^0.9",
"phpunit/phpunit": "^7.0",
"zendframework/zend-diactoros": "^1.7.0"
},
"config": {
"optimize-autoloader": true,
Expand All @@ -52,10 +55,12 @@
"tests/OverwritePhpFunctions.php"
]
},
"minimum-stability": "dev",
"minimum-stability": "stable",
"scripts": {
"cs": "sh vendor/bin/php-cs-fixer fix",
"phpstan": "sh vendor/bin/phpstan analyse -c phpstan.neon -l 6 src/"
"coverage": "phpunit --coverage-html=\"build/logs\"",
"cs": "php-cs-fixer fix",
"phpstan": "phpstan analyse -c phpstan.neon -l 7 src --memory-limit=-1",
"test": "phpunit"
},
"support": {
"issues": "https://github.com/narrowspark/http-emitter/issues",
Expand Down
8 changes: 7 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
- vendor/phpstan/phpstan-strict-rules/rules.neon

parameters:
ignoreErrors:
autoload_directories:
- %currentWorkingDirectory%/src/
4 changes: 2 additions & 2 deletions src/AbstractSapiEmitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function assertNoPreviousOutput(): void
));
}

if (ob_get_level() > 0 && ob_get_length() > 0) {
if (\ob_get_level() > 0 && \ob_get_length() > 0) {
throw new RuntimeException('Output has been emitted previously; cannot emit response.');
}
}
Expand Down Expand Up @@ -82,7 +82,7 @@ protected function emitHeaders(ResponseInterface $response): void

foreach ($response->getHeaders() as $header => $values) {
$name = $this->toWordCase($header);
$first = $name === 'Set-Cookie' ? false : true;
$first = $name !== 'Set-Cookie';

foreach ($values as $value) {
header(
Expand Down
2 changes: 1 addition & 1 deletion src/SapiStreamEmitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function emit(ResponseInterface $response): void

$range = $this->parseContentRange($response->getHeaderLine('Content-Range'));

if (is_array($range) && $range[0] === 'bytes') {
if (\is_array($range) && $range[0] === 'bytes') {
$this->emitBodyRange($range, $response, $this->maxBufferLength);

return;
Expand Down
23 changes: 13 additions & 10 deletions tests/AbstractEmitterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@
use Psr\Http\Message\StreamInterface;
use Zend\Diactoros\Response;

/**
* @internal
*/
abstract class AbstractEmitterTest extends TestCase
{
/**
* @var \Narrowspark\HttpEmitter\AbstractSapiEmitter
*/
protected $emitter;

public function tearDown(): void
protected function tearDown(): void
{
HeaderStack::reset();
}
Expand All @@ -46,12 +49,12 @@ public function testEmitsResponseHeaders(): void
->withAddedHeader('Content-Type', 'text/plain');
$response->getBody()->write('Content!');

ob_start();
\ob_start();
$this->emitter->emit($response);
ob_end_clean();
\ob_end_clean();

self::assertTrue(HeaderStack::has('HTTP/1.1 200 OK'));
self::assertTrue(HeaderStack::has('Content-Type: text/plain'));
$this->assertTrue(HeaderStack::has('HTTP/1.1 200 OK'));
$this->assertTrue(HeaderStack::has('Content-Type: text/plain'));
}

public function testMultipleSetCookieHeadersAreNotReplaced(): void
Expand All @@ -69,7 +72,7 @@ public function testMultipleSetCookieHeadersAreNotReplaced(): void
['header' => 'HTTP/1.1 200 OK', 'replace' => true, 'status_code' => 200],
];

self::assertSame($expectedStack, HeaderStack::stack());
$this->assertSame($expectedStack, HeaderStack::stack());
}

public function testDoesNotLetResponseCodeBeOverriddenByPHP(): void
Expand All @@ -87,7 +90,7 @@ public function testDoesNotLetResponseCodeBeOverriddenByPHP(): void
['header' => 'HTTP/1.1 202 Accepted', 'replace' => true, 'status_code' => 202],
];

self::assertSame($expectedStack, HeaderStack::stack());
$this->assertSame($expectedStack, HeaderStack::stack());
}

public function testEmitterRespectLocationHeader(): void
Expand All @@ -103,7 +106,7 @@ public function testEmitterRespectLocationHeader(): void
['header' => 'HTTP/1.1 200 OK', 'replace' => true, 'status_code' => 200],
];

self::assertSame($expectedStack, HeaderStack::stack());
$this->assertSame($expectedStack, HeaderStack::stack());
}

public function testDoesNotInjectContentLengthHeaderIfStreamSizeIsUnknown(): void
Expand All @@ -115,9 +118,9 @@ public function testDoesNotInjectContentLengthHeaderIfStreamSizeIsUnknown(): voi
->withStatus(200)
->withBody($stream->reveal());

ob_start();
\ob_start();
$this->emitter->emit($response);
ob_end_clean();
\ob_end_clean();

foreach (HeaderStack::stack() as $header) {
$this->assertNotContains('Content-Length:', $header['header']);
Expand Down
7 changes: 5 additions & 2 deletions tests/SapiEmitterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
use Narrowspark\HttpEmitter\SapiEmitter;
use Narrowspark\HttpEmitter\Tests\Helper\HeaderStack;

class SapiEmitterTest extends AbstractEmitterTest
/**
* @internal
*/
final class SapiEmitterTest extends AbstractEmitterTest
{
public function setUp(): void
protected function setUp(): void
{
HeaderStack::reset();

Expand Down
Loading

0 comments on commit 206ec14

Please sign in to comment.