Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade dependencies #17

Merged
merged 10 commits into from
Jun 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/composer.lock
/.phpcs.cache
/infection-log.txt
/.phpunit.result.cache
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build:
rabbitmq: false
mongodb: false
php:
version: 7.2
version: 7.3

cache:
disabled: false
Expand Down
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ sudo: false
language: php

php:
- 7.2
- 7.3
- 7.4snapshot
- nightly

cache:
Expand All @@ -21,9 +22,8 @@ script:

jobs:
allow_failures:
- php: 7.4snapshot
- php: nightly
- env: STATIC_ANALYSIS=1
- env: MUTATION_TESTS=1

include:
- stage: Code Quality
Expand Down Expand Up @@ -53,4 +53,4 @@ jobs:
- mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{.disabled,}
- if [[ ! $(php -m | grep -si xdebug) ]]; then echo "xdebug required for mutation tests"; exit 1; fi
script:
- ./vendor/bin/infection --threads=4 --min-msi=100 --min-covered-msi=100
- ./vendor/bin/infection --threads=$(nproc) --min-msi=97 --min-covered-msi=97
19 changes: 10 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,24 @@
}
},
"require": {
"php": "^7.2",
"php": "^7.3",
"ext-json": "^1.7",
"fig/http-message-util": "^1.1",
"psr/http-server-middleware": "^1.0"
},
"require-dev": {
"doctrine/coding-standard": "^4.0",
"infection/infection": "dev-master@dev",
"jms/serializer": "^1.11",
"infection/infection": "^0.13",
"jms/serializer": "^3.0",
"lcobucci/coding-standard": "^3.0",
"league/plates": "^3.3",
"middlewares/negotiation": "^1.0",
"phpstan/phpstan": "^0.10",
"phpstan/phpstan-phpunit": "^0.10",
"phpstan/phpstan-strict-rules": "^0.10",
"phpunit/phpunit": "^7.0",
"phpstan/phpstan": "^0.11",
"phpstan/phpstan-phpunit": "^0.11",
"phpstan/phpstan-strict-rules": "^0.11",
"phpunit/phpunit": "^8.2",
"squizlabs/php_codesniffer": "^3.2",
"twig/twig": "^2.0",
"zendframework/zend-diactoros": "^1.7"
"zendframework/zend-diactoros": "^2.0"
},
"suggest": {
"jms/serializer": "For content formatting using a more flexible serializer",
Expand Down
20 changes: 1 addition & 19 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,5 @@
<file>src</file>
<file>tests</file>

<rule ref="Doctrine">
<exclude name="SlevomatCodingStandard.Commenting.RequireOneLinePropertyDocComment" />
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<properties>
<property name="newlinesCountBetweenOpenTagAndDeclare" value="1"/>
<property name="spacesCountAroundEqualsSign" value="0"/>
<property name="newlinesCountAfterDeclare" value="2"/>
</properties>
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing">
<properties>
<property name="spacesCountBeforeColon" value="0"/>
</properties>
</rule>

<rule ref="SlevomatCodingStandard.Commenting.DisallowOneLinePropertyDocComment" />
<rule ref="Lcobucci" />
</ruleset>
4 changes: 4 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ parameters:
paths:
- src
- tests
ignoreErrors:
-
message: '#Variable method call on#'
path: tests/UnformattedResponseTest.php
2 changes: 1 addition & 1 deletion src/ContentTypeMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function fromRecommendedSettings(
return new self(
new ContentType($formats),
$formatters,
$streamFactory ?? function (): StreamInterface {
$streamFactory ?? static function (): StreamInterface {
return new Stream('php://temp', 'wb+');
}
);
Expand Down
21 changes: 8 additions & 13 deletions src/Formatter/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
use const JSON_HEX_APOS;
use const JSON_HEX_QUOT;
use const JSON_HEX_TAG;
use const JSON_THROW_ON_ERROR;
use const JSON_UNESCAPED_SLASHES;
use function assert;
use function is_string;
use function json_encode;
use function json_last_error;
use function json_last_error_msg;
use function sprintf;

final class Json implements Formatter
Expand All @@ -36,22 +37,16 @@ public function __construct(int $flags = self::DEFAULT_FLAGS)
public function format($content, array $attributes = []): string
{
try {
$encoded = json_encode($content, $this->flags);
$content = json_encode($content, $this->flags | JSON_THROW_ON_ERROR);
assert(is_string($content));

return $content;
} catch (Throwable $exception) {
throw new ContentCouldNotBeFormatted(
'An exception was thrown during JSON formatting',
sprintf('An exception was thrown during JSON formatting: %s', $exception->getMessage()),
$exception->getCode(),
$exception
);
}

if ($encoded === false) {
throw new ContentCouldNotBeFormatted(
sprintf('Given data cannot be formatted as JSON: %s', json_last_error_msg()),
json_last_error()
);
}

return $encoded;
}
}
8 changes: 4 additions & 4 deletions tests/ContentTypeMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ public function processShouldPassAttributesToTheFormatterProperly(): void

$body = (string) $response->getBody();

self::assertContains('<dd>1</dd>', $body);
self::assertContains('<dd>Testing</dd>', $body);
self::assertStringContainsString('<dd>1</dd>', $body);
self::assertStringContainsString('<dd>Testing</dd>', $body);
}

/**
Expand Down Expand Up @@ -214,7 +214,7 @@ private function processWithInvalidStreamFactory(): void
{
$middleware = $this->createMiddleware(
true,
function () {
static function () {
return false;
}
);
Expand Down Expand Up @@ -279,7 +279,7 @@ private function createMiddleware(bool $forceCharset = true, ?callable $streamFa
private function configureCharset(bool $forceCharset = true): array
{
return array_map(
function (array $config) use ($forceCharset): array {
static function (array $config) use ($forceCharset): array {
return ['charset' => $forceCharset] + $config;
},
self::SUPPORTED_FORMATS
Expand Down
21 changes: 11 additions & 10 deletions tests/Formatter/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
use Lcobucci\ContentNegotiation\Tests\PersonDto;
use PHPUnit\Framework\TestCase;
use RuntimeException;
use const JSON_HEX_AMP;
use const JSON_HEX_APOS;
use const JSON_HEX_QUOT;
use const JSON_HEX_TAG;
use const JSON_UNESCAPED_SLASHES;
use function acos;

Expand All @@ -25,23 +21,29 @@ final class JsonTest extends TestCase
* @test
*
* @covers ::__construct()
*
* @uses \Lcobucci\ContentNegotiation\Formatter\Json::format()
*/
public function constructorShouldAllowTheConfigurationOfEncodingFlags(): void
{
self::assertAttributeSame(JSON_UNESCAPED_SLASHES, 'flags', new Json(JSON_UNESCAPED_SLASHES));
self::assertSame(
'["<foo>","\'bar\'","\"baz\"","&blong&","\u00e9","http://"]',
(new Json(JSON_UNESCAPED_SLASHES))->format(['<foo>', "'bar'", '"baz"', '&blong&', "\xc3\xa9", 'http://'])
);
}

/**
* @test
*
* @covers ::__construct()
*
* @uses \Lcobucci\ContentNegotiation\Formatter\Json::format()
*/
public function constructorShouldUseDefaultFlagsWhenNothingWasSet(): void
{
self::assertAttributeSame(
JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_SLASHES,
'flags',
new Json()
self::assertSame(
'["\u003Cfoo\u003E","\u0027bar\u0027","\u0022baz\u0022","\u0026blong\u0026","\u00e9","http://"]',
$this->format(['<foo>', "'bar'", '"baz"', '&blong&', "\xc3\xa9", 'http://'])
);
}

Expand All @@ -51,7 +53,6 @@ public function constructorShouldUseDefaultFlagsWhenNothingWasSet(): void
* @covers ::format()
*
* @uses \Lcobucci\ContentNegotiation\Formatter\Json::__construct()
*
*/
public function formatShouldReturnAJsonEncodedValue(): void
{
Expand Down
8 changes: 5 additions & 3 deletions tests/Formatter/NaiveTemplateEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ private function getTemplateContent(array $attributes): string
$template = $attributes['template'] ?? '';
assert(is_string($template));

$file = new SplFileObject(self::BASE_DIR . $template . '.' . self::EXTENSION);
$file = new SplFileObject(self::BASE_DIR . $template . '.' . self::EXTENSION);
$content = $file->fread($file->getSize());
assert(is_string($content));

return $file->fread($file->getSize());
return $content;
}

/**
Expand All @@ -46,7 +48,7 @@ private function getTemplateContent(array $attributes): string
private function render(string $template, array $data): string
{
$variables = array_map(
function (string $attribute): string {
static function (string $attribute): string {
return '{' . $attribute . '}';
},
array_keys($data)
Expand Down
8 changes: 4 additions & 4 deletions tests/Formatter/PlatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public function formatShouldReturnContentFormattedByPlates(): void
$formatter = new Plates($this->engine);
$content = $formatter->format(new PersonDto(1, 'Testing'), ['template' => 'person']);

self::assertContains('<dd>1</dd>', $content);
self::assertContains('<dd>Testing</dd>', $content);
self::assertStringContainsString('<dd>1</dd>', $content);
self::assertStringContainsString('<dd>Testing</dd>', $content);
}

/**
Expand All @@ -56,8 +56,8 @@ public function formatShouldReadTemplateNameFromCustomAttribute(): void
$formatter = new Plates($this->engine, 'fancy!');
$content = $formatter->format(new PersonDto(1, 'Testing'), ['fancy!' => 'person']);

self::assertContains('<dd>1</dd>', $content);
self::assertContains('<dd>Testing</dd>', $content);
self::assertStringContainsString('<dd>1</dd>', $content);
self::assertStringContainsString('<dd>Testing</dd>', $content);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/Formatter/TwigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public function formatShouldReturnContentFormattedByPlates(): void
$formatter = new Twig($this->environment);
$content = $formatter->format(new PersonDto(1, 'Testing'), ['template' => 'person.twig']);

self::assertContains('<dd>1</dd>', $content);
self::assertContains('<dd>Testing</dd>', $content);
self::assertStringContainsString('<dd>1</dd>', $content);
self::assertStringContainsString('<dd>Testing</dd>', $content);
}

/**
Expand All @@ -59,8 +59,8 @@ public function formatShouldReadTemplateNameFromCustomAttribute(): void
$formatter = new Twig($this->environment, 'fancy!');
$content = $formatter->format(new PersonDto(1, 'Testing'), ['fancy!' => 'person.twig']);

self::assertContains('<dd>1</dd>', $content);
self::assertContains('<dd>Testing</dd>', $content);
self::assertStringContainsString('<dd>1</dd>', $content);
self::assertStringContainsString('<dd>Testing</dd>', $content);
}

/**
Expand Down
9 changes: 6 additions & 3 deletions tests/UnformattedResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,24 @@ public function getUnformattedContentShouldReturnTheConfiguredValue(): void
* @covers ::withAttribute()
*
* @uses \Lcobucci\ContentNegotiation\UnformattedResponse::__construct()
* @uses \Lcobucci\ContentNegotiation\UnformattedResponse::getAttributes()
*/
public function withAttributeShouldReturnANewInstanceWithTheAddedAttribute(): void
{
$response1 = new UnformattedResponse(new Response(), new PersonDto(1, 'Testing'));
$response2 = $response1->withAttribute('test', 1);

self::assertAttributeSame([], 'attributes', $response1);
self::assertAttributeSame(['test' => 1], 'attributes', $response2);
self::assertSame([], $response1->getAttributes());
self::assertSame(['test' => 1], $response2->getAttributes());
}

/**
* @test
*
* @covers ::__construct()
* @covers ::withAttribute()
*
* @uses \Lcobucci\ContentNegotiation\UnformattedResponse::getAttributes()
*/
public function withAttributeShouldOverrideExistingAttributes(): void
{
Expand All @@ -57,7 +60,7 @@ public function withAttributeShouldOverrideExistingAttributes(): void
['test' => 1]
);

self::assertAttributeSame(['test' => 2], 'attributes', $response->withAttribute('test', 2));
self::assertSame(['test' => 2], $response->withAttribute('test', 2)->getAttributes());
}

/**
Expand Down