Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
use pcov instead of phpdbg
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikzogg committed Aug 18, 2020
1 parent db49365 commit fdfb5d2
Show file tree
Hide file tree
Showing 25 changed files with 110 additions and 88 deletions.
35 changes: 9 additions & 26 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,21 @@
<?php

declare(strict_types=1);

$finder = PhpCsFixer\Finder::create()
->files()
->name('*.php')
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
;

/** @var array $config */
$config = require __DIR__ . '/vendor/chubbyphp/chubbyphp-dev-helper/phpcs.php';

return PhpCsFixer\Config::create()
->setIndent(" ")
->setLineEnding("\n")
->setRules([
'@DoctrineAnnotation' => true,
'@PhpCsFixer' => true,
'@Symfony' => true,
'array_syntax' => ['syntax' => 'short'],
'declare_strict_types' => true,
'dir_constant' => true,
'final_class' => true,
'is_null' => true,
'linebreak_after_opening_tag' => true,
'list_syntax' => true,
'method_chaining_indentation' => false,
'no_php4_constructor' => true,
'ordered_interfaces' => true,
'php_unit_dedicate_assert_internal_type' => true,
'php_unit_dedicate_assert' => true,
'php_unit_expectation' => true,
'php_unit_mock' => true,
'php_unit_namespaced' => true,
'php_unit_no_expectation_annotation' => true,
'single_line_throw' => false,
'ternary_to_null_coalescing' => true,
])
->setRiskyAllowed(true)
->setIndent($config['indent'])
->setLineEnding($config['lineEnding'])
->setRules($config['rules'])
->setRiskyAllowed($config['riskyAllowed'])
->setFinder($finder)
;
12 changes: 4 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
dist: bionic

language: php

matrix:
include:
- php: 7.0
env: composerargs="--prefer-lowest"
- php: 7.0
- php: 7.1
env: composerargs="--prefer-lowest"
- php: 7.1
- php: 7.2
env: composerargs="--prefer-lowest"
- php: 7.2
Expand All @@ -20,11 +16,11 @@ matrix:
- php: nightly
env: composerargs="--ignore-platform-reqs"
allow_failures:
- php: 7.4
env: composerargs="--prefer-lowest"
- php: nightly

before_script:
- (phpenv config-rm xdebug.ini || exit 0)
- pecl install pcov
- echo 'Europe/Zurich' | sudo tee /etc/timezone
- echo 'date.timezone = "Europe/Zurich"' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- composer self-update -q
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2018 Dominik Zogg
Copyright (c) 2020 Dominik Zogg

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ A simple socket server mock.

## Requirements

* php: ^7.0
* symfony/process: ^2.8.50|^3.4.26|^4.2.7|^5.0
* php: ^7.2
* symfony/process: ^3.4.43|^4.4.11|^5.0

## Installation

Through [Composer](http://getcomposer.org) as [chubbyphp/chubbyphp-socket-server-mock][1].

```sh
composer require chubbyphp/chubbyphp-socket-server-mock "^1.1"
composer require chubbyphp/chubbyphp-socket-server-mock "^1.2"
```

## Usage
Expand Down
33 changes: 22 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@
}
],
"require": {
"php": "^7.0",
"symfony/process": "^2.8.50|^3.4.26|^4.2.7|^5.0"
"php": "^7.2",
"symfony/process": "^3.4.43|^4.4.11|^5.0"
},
"require-dev": {
"chubbyphp/chubbyphp-mock": "^1.4.2",
"friendsofphp/php-cs-fixer": "^2.16.1",
"chubbyphp/chubbyphp-dev-helper": "dev-master",
"chubbyphp/chubbyphp-mock": "^1.4.5",
"infection/infection": "^0.15.3|^0.16.4",
"laminas/laminas-container-config-test": "^0.2 || ^1.0",
"mavimo/phpstan-junit": "^0.3",
"php-coveralls/php-coveralls": "^2.2",
"php-mock/php-mock-phpunit": "^2.2",
"phploc/phploc": "^4.0.1||^5.0",
"phpunit/phpunit": "^6.5.14|^7.5.17|^8.5.1"
"php-mock/php-mock-phpunit": "^2.6",
"phploc/phploc": "^5.0|^6.0.2",
"phpstan/extension-installer": "^1.0.4",
"phpstan/phpstan": "^0.12.33",
"phpunit/phpunit": "^8.5.8|^9.2.6"
},
"autoload": {
"psr-4": { "Chubbyphp\\SocketServerMock\\": "src/" }
Expand All @@ -32,7 +37,7 @@
],
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
"dev-master": "1.2-dev"
}
},
"scripts": {
Expand All @@ -41,13 +46,19 @@
"@test:lint",
"@test:unit",
"@test:integration",
"@test:infection",
"@test:static-analysis",
"@test:loc",
"@test:cs"
"@test:cs",
"@test:insights"
],
"test:cs": "mkdir -p build && vendor/bin/php-cs-fixer fix --dry-run --stop-on-violation --cache-file=build/phpcs.cache",
"test:integration": "vendor/bin/phpunit --testsuite=Integration",
"test:infection": "vendor/bin/infection --threads=$(nproc) --min-msi=85 --verbose --coverage=build/phpunit",
"test:insights": "mkdir -p build && bash -c 'vendor/bin/phpinsights analyse -v --no-interaction --min-quality=96 --disable-security-check | tee build/phpinsights.log; if [ ${PIPESTATUS[0]} -ne \"0\" ]; then exit 1; fi'",
"test:integration": "vendor/bin/phpunit --testsuite=Integration --cache-result-file=build/phpunit/result.cache",
"test:lint": "mkdir -p build && find src tests -name '*.php' -print0 | xargs -0 -n1 -P$(nproc) php -l | tee build/phplint.log",
"test:loc": "mkdir -p build && vendor/bin/phploc src --verbose | tee build/phploc.log",
"test:unit": "phpdbg -qrr vendor/bin/phpunit --testsuite=Unit --coverage-text --coverage-clover=build/phpunit/clover.xml --coverage-html=build/phpunit/coverage-html --coverage-xml=build/phpunit/coverage-xml --log-junit=build/phpunit/junit.xml"
"test:static-analysis": "mkdir -p build && bash -c 'vendor/bin/phpstan analyse src --no-progress --level=7 --error-format=junit | tee build/phpstan.junit.xml; if [ ${PIPESTATUS[0]} -ne \"0\" ]; then exit 1; fi'",
"test:unit": "vendor/bin/phpunit --testsuite=Unit --coverage-text --coverage-clover=build/phpunit/clover.xml --coverage-html=build/phpunit/coverage-html --coverage-xml=build/phpunit/coverage-xml --log-junit=build/phpunit/junit.xml --cache-result-file=build/phpunit/result.cache"
}
}
14 changes: 14 additions & 0 deletions infection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"source": {
"directories": [
"src"
]
},
"timeout": 10,
"logs": {
"text": "build/phpinfection.log"
},
"mutators": {
"@default": true
}
}
8 changes: 8 additions & 0 deletions phpinsights.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

declare(strict_types=1);

/** @var array $config */
$config = require __DIR__ . '/vendor/chubbyphp/chubbyphp-dev-helper/phpinsights.php';

return $config;
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
parameters:
ignoreErrors: []
4 changes: 3 additions & 1 deletion src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ public function __construct(string $input, string $output)
$this->output = $output;
}

/**
* @param array<string, string> $data
*/
public static function createFromArray(array $data): self
{
$missingFields = [];
$invalidFields = [];

if (!isset($data['input'])) {
$missingFields[] = 'input';
Expand Down
5 changes: 4 additions & 1 deletion src/MessageLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public function __construct(array $messages)
}
}

/**
* @param array<int, array<string, string>> $data
*/
public static function createFromArray(array $data): self
{
$messages = [];
Expand All @@ -41,7 +44,7 @@ public function getNextMessage()
return array_shift($this->messages);
}

private function addMessage(MessageInterface $message)
private function addMessage(MessageInterface $message): void
{
$this->messages[] = $message;
}
Expand Down
5 changes: 4 additions & 1 deletion src/MessageLogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public function __construct(array $messageLogs)
}
}

/**
* @param array<int, array<int, array<string, string>>> $data
*/
public static function createFromArray(array $data): self
{
$messageLogs = [];
Expand All @@ -41,7 +44,7 @@ public function getNextMessageLog()
return array_shift($this->messageLogs);
}

private function addMessageLog(MessageLogInterface $connection)
private function addMessageLog(MessageLogInterface $connection): void
{
$this->messageLogs[] = $connection;
}
Expand Down
6 changes: 3 additions & 3 deletions src/SocketServerMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public function __construct(ServerFactoryInterface $serverFactory)
$this->serverFactory = $serverFactory;
}

public function run(string $host, int $port, MessageLogsInterface $messageLogs)
public function run(string $host, int $port, MessageLogsInterface $messageLogs): void
{
$socketServer = $this->serverFactory->createByHostAndPort($host, $port);

$this->processMessageLogs($socketServer, $messageLogs);
}

private function processMessageLogs(ServerInterface $socketServer, MessageLogsInterface $messageLogs)
private function processMessageLogs(ServerInterface $socketServer, MessageLogsInterface $messageLogs): void
{
while (null !== $messageLog = $messageLogs->getNextMessageLog()) {
$socketConnection = $socketServer->createConnection();
Expand All @@ -36,7 +36,7 @@ private function processMessageLogs(ServerInterface $socketServer, MessageLogsIn
}
}

private function processMessageLog(ConnectionInterface $socketConnection, MessageLogInterface $messageLog)
private function processMessageLog(ConnectionInterface $socketConnection, MessageLogInterface $messageLog): void
{
while (null !== $message = $messageLog->getNextMessage()) {
$input = $this->getDecodedValue($message->getInput());
Expand Down
6 changes: 3 additions & 3 deletions src/Stream/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ public function __construct(ServerInterface $socketServer)
$this->stream = $stream;
}

public function __deconstruct()
public function __deconstruct(): void
{
fclose($this->stream);
}

public function read(int $length): string
{
return fread($this->stream, $length);
return (string) fread($this->stream, $length);
}

public function write(string $string)
public function write(string $string): void
{
fwrite($this->stream, $string);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Stream/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ interface ConnectionInterface
{
public function read(int $length): string;

public function write(string $string);
public function write(string $string): void;
}
2 changes: 1 addition & 1 deletion src/Stream/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(string $host, int $port)
fwrite(STDOUT, 'socket server mock: started'.PHP_EOL);
}

public function __deconstruct()
public function __deconstruct(): void
{
fclose($this->stream);
}
Expand Down
14 changes: 7 additions & 7 deletions tests/Unit/CreateSocketServerMockTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class CreateSocketServerMockTraitTest extends TestCase
{
use CreateSocketServerMockTrait;

public function testWithExpectedInput()
public function testWithExpectedInput(): void
{
$process = $this->createSocketServerMock('0.0.0.0', 62000, [[['input' => 'input', 'output' => 'output']]]);

Expand All @@ -37,7 +37,7 @@ public function testWithExpectedInput()
self::assertSame(0, $process->getExitCode());
}

public function testWithUnexpectedInput()
public function testWithUnexpectedInput(): void
{
$process = $this->createSocketServerMock('0.0.0.0', 62000, [[['input' => 'input', 'output' => 'output']]]);

Expand All @@ -53,7 +53,7 @@ public function testWithUnexpectedInput()
self::assertSame(200, $process->getExitCode());
}

public function testMissingHost()
public function testMissingHost(): void
{
$process = new Process([realpath(__DIR__.'/../../bin/socketServerMock')]);
$process->start();
Expand All @@ -63,7 +63,7 @@ public function testMissingHost()
self::assertSame('Missing host'.PHP_EOL, $process->getErrorOutput());
}

public function testMissingPort()
public function testMissingPort(): void
{
$process = new Process([
realpath(__DIR__.'/../../bin/socketServerMock'),
Expand All @@ -76,7 +76,7 @@ public function testMissingPort()
self::assertSame('Missing port'.PHP_EOL, $process->getErrorOutput());
}

public function testMissingMessageLogs()
public function testMissingMessageLogs(): void
{
$process = new Process([
realpath(__DIR__.'/../../bin/socketServerMock'),
Expand All @@ -90,7 +90,7 @@ public function testMissingMessageLogs()
self::assertSame('Missing message logs'.PHP_EOL, $process->getErrorOutput());
}

public function testWithStringAsPort()
public function testWithStringAsPort(): void
{
$process = new Process([
realpath(__DIR__.'/../../bin/socketServerMock'),
Expand All @@ -105,7 +105,7 @@ public function testWithStringAsPort()
self::assertSame('Port "test" is not an integer'.PHP_EOL, $process->getErrorOutput());
}

public function testWithInvalidMessageLogsJson()
public function testWithInvalidMessageLogsJson(): void
{
$process = new Process([
realpath(__DIR__.'/../../bin/socketServerMock'),
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/MessageLogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
final class MessageLogTest extends TestCase
{
public function testMessageLog()
public function testMessageLog(): void
{
$messageLog = MessageLog::createFromArray([['input' => 'input', 'output' => 'output']]);

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/MessageLogsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
final class MessageLogsTest extends TestCase
{
public function testMessageLogs()
public function testMessageLogs(): void
{
$messageLogs = MessageLogs::createFromArray([[['input' => 'input', 'output' => 'output']]]);

Expand Down
Loading

0 comments on commit fdfb5d2

Please sign in to comment.