Skip to content

Commit

Permalink
Use Github actions with style (#233)
Browse files Browse the repository at this point in the history
* Update style

* Update CI rules

* Normalize composer.json

* Disable yoda

* Apply CS fixes
  • Loading branch information
Nyholm committed Jan 18, 2021
1 parent 0cb5813 commit bb3cf2e
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 62 deletions.
32 changes: 11 additions & 21 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ jobs:

runs-on: "ubuntu-latest"

strategy:
matrix:
php-version:
- "7.2"

steps:
- name: "Checkout"
uses: "actions/checkout@v2.3.4"
Expand All @@ -31,25 +26,25 @@ jobs:
with:
coverage: "none"
extensions: "mbstring"
php-version: "${{ matrix.php-version }}"
php-version: "7.4"
tools: "composer-normalize"

- name: "Validate composer.json and composer.lock"
- name: "Validate composer.json"
run: "composer validate --strict"

- name: "Normalize composer.json"
run: "composer-normalize --dry-run"

- name: "Install dependencies with composer"
run: "composer update --no-interaction --no-progress"
- name: "PHP-CS-Fixer"
uses: "docker://oskarstark/php-cs-fixer-ga:2.18.0"
with:
args: "--dry-run --diff-format udiff"

static-code-analysis:
name: "Static Code Analysis"

runs-on: "ubuntu-latest"

strategy:
matrix:
php-version:
- "7.4"

steps:
- name: "Checkout"
uses: "actions/checkout@v2.3.4"
Expand All @@ -59,7 +54,7 @@ jobs:
with:
coverage: "none"
extensions: "mbstring"
php-version: "${{ matrix.php-version }}"
php-version: "7.4"

- name: "Install dependencies with composer"
run: "composer update --no-interaction --no-progress && composer i --working-dir=ci"
Expand Down Expand Up @@ -135,11 +130,6 @@ jobs:

runs-on: "ubuntu-latest"

strategy:
matrix:
php-version:
- "7.4"

steps:
- name: "Checkout"
uses: "actions/checkout@v2.3.4"
Expand All @@ -148,7 +138,7 @@ jobs:
with:
coverage: "pcov"
extensions: "mbstring"
php-version: "${{ matrix.php-version }}"
php-version: "7.4"

- name: "Install dependencies with composer"
run: "composer update --no-interaction --no-progress"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor/
/composer.lock
.phpunit.result.cache
.php_cs.cache
24 changes: 24 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

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

return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'@Symfony' => true,
'ordered_imports' => true,
'array_syntax' => ['syntax' => 'long'],
'no_superfluous_phpdoc_tags' => false,
'phpdoc_annotation_without_dot' => false,
'phpdoc_types_order' => false,
'phpdoc_summary' => false,
'phpdoc_to_comment' => false,
'phpdoc_align' => false,
'yoda_style' => false,
])
->setFinder($finder)
;
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@
"php": "^5.3.3 || ^7.0 || ^8.0",
"symfony/polyfill-ctype": "^1.8"
},
"conflict": {
"phpstan/phpstan": "<0.12.20",
"vimeo/psalm": "<3.9.1"
},
"require-dev": {
"phpunit/phpunit": "^4.8.36 || ^7.5.13 || ^8.5.13"
},
"conflict": {
"vimeo/psalm": "<3.9.1",
"phpstan/phpstan": "<0.12.20"
"extra": {
"branch-alias": {
"dev-master": "1.10-dev"
}
},
"autoload": {
"psr-4": {
Expand All @@ -34,10 +39,5 @@
"Webmozart\\Assert\\Tests\\": "tests/",
"Webmozart\\Assert\\Bin\\": "bin/src"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.10-dev"
}
}
}
20 changes: 10 additions & 10 deletions tests/AssertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

use ArrayIterator;
use ArrayObject;
use Exception;
use Error;
use Exception;
use LogicException;
use RuntimeException;
use stdClass;
Expand Down Expand Up @@ -516,12 +516,12 @@ public function getTests()
array('uuid', array('ff6f8cb0-c57da-51e1-9b21-0800200c9a66'), false),
array('uuid', array('af6f8cb-c57d-11e1-9b21-0800200c9a66'), false),
array('uuid', array('3f6f8cb0-c57d-11e1-9b21-0800200c9a6'), false),
array('throws', array(function() { throw new LogicException('test'); }, 'LogicException'), true),
array('throws', array(function() { throw new LogicException('test'); }, 'IllogicException'), false),
array('throws', array(function() { throw new Exception('test'); }), true),
array('throws', array(function() { trigger_error('test'); }, 'Throwable'), true, false, 70000),
array('throws', array(function() { trigger_error('test'); }, 'Unthrowable'), false, false, 70000),
array('throws', array(function() { throw new Error(); }, 'Throwable'), true, true, 70000),
array('throws', array(function () { throw new LogicException('test'); }, 'LogicException'), true),
array('throws', array(function () { throw new LogicException('test'); }, 'IllogicException'), false),
array('throws', array(function () { throw new Exception('test'); }), true),
array('throws', array(function () { trigger_error('test'); }, 'Throwable'), true, false, 70000),
array('throws', array(function () { trigger_error('test'); }, 'Unthrowable'), false, false, 70000),
array('throws', array(function () { throw new Error(); }, 'Throwable'), true, true, 70000),
array('ip', array('192.168.0.1'), true),
array('ip', array(new ToStringClass('192.168.0.1')), true),
array('ip', array('255.255.255.255'), true),
Expand Down Expand Up @@ -698,7 +698,7 @@ public function getStringConversions()
array('string', array(self::getResource()), 'Expected a string. Got: resource'),

array('eq', array('1', '2'), 'Expected a value equal to "2". Got: "1"'),
array('eq', array(new ToStringClass("XXX"), new ToStringClass("YYY")), 'Expected a value equal to Webmozart\Assert\Tests\ToStringClass: "YYY". Got: Webmozart\Assert\Tests\ToStringClass: "XXX"'),
array('eq', array(new ToStringClass('XXX'), new ToStringClass('YYY')), 'Expected a value equal to Webmozart\Assert\Tests\ToStringClass: "YYY". Got: Webmozart\Assert\Tests\ToStringClass: "XXX"'),
array('eq', array(1, 2), 'Expected a value equal to 2. Got: 1'),
array('eq', array(true, false), 'Expected a value equal to false. Got: true'),
array('eq', array(true, null), 'Expected a value equal to null. Got: true'),
Expand Down Expand Up @@ -732,8 +732,8 @@ public function testAnUnknownMethodThrowsABadMethodCall()
/**
* @ignore
*/
class ToStringClass {

class ToStringClass
{
/**
* @var string
*/
Expand Down
8 changes: 5 additions & 3 deletions tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ class BaseTestCase extends TestCase
* @param string $exceptionMessage
* @param int $exceptionCode
*/
public function setExpectedException($exceptionName, $exceptionMessage = '', $exceptionCode = null) {
public function setExpectedException($exceptionName, $exceptionMessage = '', $exceptionCode = null)
{
if (method_exists($this, 'expectException')) {
$this->expectException($exceptionName);
if($exceptionMessage) {
if ($exceptionMessage) {
$this->expectExceptionMessage($exceptionMessage);
}
if( $exceptionCode) {
if ($exceptionCode) {
$this->expectExceptionCode($exceptionCode);
}

return;
}
parent::setExpectedException($exceptionName, $exceptionMessage, $exceptionCode);
Expand Down
34 changes: 18 additions & 16 deletions tests/ProjectCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Webmozart\Assert\Tests;

use Webmozart\Assert\Bin\MixinGenerator;
use ReflectionClass;
use ReflectionMethod;
use Webmozart\Assert\Bin\MixinGenerator;

/**
* @coversNothing
Expand All @@ -20,7 +20,7 @@ class ProjectCodeTest extends BaseTestCase
*/
public static function doSetUpBeforeClass()
{
self::$readmeContent = file_get_contents(__DIR__ . '/../README.md');
self::$readmeContent = file_get_contents(__DIR__.'/../README.md');

$rc = new ReflectionClass('\Webmozart\Assert\Mixin');
self::$assertDocComment = $rc->getDocComment();
Expand All @@ -38,13 +38,14 @@ public static function doSetUpBeforeClass()
*/
public function testHasNullOr($method)
{
$fullMethodName = 'nullOr' . ucfirst($method);
$fullMethodName = 'nullOr'.ucfirst($method);

if ($method === 'notNull' || $method === 'null') {
$this->addToAssertionCount(1);

return;
}
$correct = strpos( (string)self::$assertDocComment,'@method static void ' . $fullMethodName);
$correct = strpos((string) self::$assertDocComment, '@method static void '.$fullMethodName);
if (!$correct) {
$correct = in_array($fullMethodName, self::$mixinMethodNames, true);
}
Expand All @@ -56,7 +57,7 @@ public function testHasNullOr($method)
));
}

$this->addToAssertionCount(1);
$this->addToAssertionCount(1);
}

/**
Expand All @@ -66,9 +67,9 @@ public function testHasNullOr($method)
*/
public function testHasAll($method)
{
$fullMethodName = 'all' . ucfirst($method);
$fullMethodName = 'all'.ucfirst($method);

$correct = strpos((string) self::$assertDocComment,'@method static void ' . $fullMethodName);
$correct = strpos((string) self::$assertDocComment, '@method static void '.$fullMethodName);
if (!$correct) {
$correct = in_array($fullMethodName, self::$mixinMethodNames, true);
}
Expand All @@ -90,9 +91,9 @@ public function testHasAll($method)
*/
public function testIsInReadme($method)
{
$correct = strpos((string) self::$readmeContent,$method);
$correct = strpos((string) self::$readmeContent, $method);

if($correct === false) {
if ($correct === false) {
$this->fail(sprintf(
'All methods must be documented in the README.md, please add the "%s" method.',
$method
Expand Down Expand Up @@ -126,7 +127,6 @@ public function testHasThrowsAnnotation($method)
$method->getName()
)
);

}

/**
Expand All @@ -138,28 +138,30 @@ public function testHasCorrespondingStaticAnalysisFile($method)
{
$doc = $method->getDocComment();

if($doc === false || strpos($doc, '@psalm-assert') === false) {
if ($doc === false || strpos($doc, '@psalm-assert') === false) {
$this->addToAssertionCount(1);

return;
}

$this->assertFileExists(
__DIR__ . '/static-analysis/assert-'. $method->getName() . '.php'
__DIR__.'/static-analysis/assert-'.$method->getName().'.php'
);
}

public function testMixinIsUpToDateVersion()
{
if (version_compare(PHP_VERSION, '7.2.0') < 0) {
$this->markTestSkipped('mixin generator is implemented using php 7.2 features');

return;
}

require_once __DIR__ . '/../bin/src/MixinGenerator.php';
require_once __DIR__.'/../bin/src/MixinGenerator.php';

$generator = new MixinGenerator();

$actual = file_get_contents(__DIR__ . '/../src/Mixin.php');
$actual = file_get_contents(__DIR__.'/../src/Mixin.php');

$this->assertEquals($generator->generate(), $actual, 'please regenerate Mixin with `php bin/generate.php` command in the project root');
}
Expand All @@ -169,7 +171,7 @@ public function testMixinIsUpToDateVersion()
*/
public function providesMethodNames()
{
return array_map(function($value) {
return array_map(function ($value) {
return array($value->getName());
}, $this->getMethods());
}
Expand All @@ -179,7 +181,7 @@ public function providesMethodNames()
*/
public function provideMethods()
{
return array_map(function($value) {
return array_map(function ($value) {
return array($value);
}, $this->getMethods());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/static-analysis/assert-isNotA.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Webmozart\Assert\Tests\StaticAnalysis;

use stdClass;
use DateTime;
use stdClass;
use Webmozart\Assert\Assert;

/**
Expand Down
1 change: 0 additions & 1 deletion tests/static-analysis/assert-keyNotExists.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ function nullOrKeyNotExists(?array $array, $key): ?array
* @psalm-pure
*
* @param iterable<array> $array
*
* @param array-key $key
*
* @return iterable<array>
Expand Down
1 change: 0 additions & 1 deletion tests/static-analysis/assert-notEmpty.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ function notEmptyArray(array $value)
return $value;
}


/**
* @psalm-pure
*
Expand Down
2 changes: 1 addition & 1 deletion tests/static-analysis/assert-notInstanceOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Webmozart\Assert\Tests\StaticAnalysis;

use stdClass;
use DateTime;
use stdClass;
use Webmozart\Assert\Assert;

/**
Expand Down

0 comments on commit bb3cf2e

Please sign in to comment.