Skip to content

Commit

Permalink
Update grumphp to configure php-cs-fixer, and fix phpunit
Browse files Browse the repository at this point in the history
  • Loading branch information
jeckel committed Oct 16, 2023
1 parent d614ff1 commit 2ccabc8
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ on:

jobs:
global-qa-tests:
name: PHP ${{ matrix.php }}
runs-on: ubuntu-latest
strategy:
fail-fast: true
Expand All @@ -21,6 +20,7 @@ jobs:

env:
extensions: ctype, dom, intl, json, mbstring, openssl, xml, zip, zlib
key: cache-v1

steps:
- name: Checkout
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
/.idea
/.phpunit.result.cache
/coverage
/.php-cs-fixer.cache
/.phpunit.cache/
12 changes: 12 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

$finder = PhpCsFixer\Finder::create()->in(__DIR__);

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@PER-CS2.0' => true,
])
->setFinder($finder);
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,10 @@
"phpro/grumphp": true,
"phpstan/extension-installer": true
}
},
"scripts": {
"test": "vendor/bin/phpunit --testdox",
"cs-fix": "vendor/bin/php-cs-fixer fix --diff --verbose",
"grumphp": "vendor/bin/grumphp run"
}
}
21 changes: 12 additions & 9 deletions grumphp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ grumphp:
github_actions:
tasks:
- composer_require_checker
- phpcs
- phpcsfixer
- phpmd
- phpstan

tasks:
phpcs:
whitelist_patterns:
- /^src\/(.*)/
phpcsfixer:
allow_risky: ~
cache_file: ~
config: .php-cs-fixer.dist.php
using_cache: ~
config_contains_finder: false
verbose: true
diff: false
triggered_by: ['php']
phpmd:
whitelist_patterns:
- /^src\/(.*)/
Expand All @@ -34,10 +41,6 @@ grumphp:
- "feature/*"
- "bugfix/*"
- "hotfix/*"
blacklist:
- "develop"
- "master"
- "main"
additional_modifiers: ''
allow_detached_head: true
infection:
# infection:
5 changes: 0 additions & 5 deletions infection.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,5 @@
},
"mutators": {
"@default": true
},
"logs": {
"badge": {
"branch": "main"
}
}
}
7 changes: 3 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
parameters:
level: max
level: 9
paths:
- src
- tests
includes:
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
excludes_analyse:
- tests/*
29 changes: 15 additions & 14 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="vendor/autoload.php">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<directory suffix=".php">src/CodeceptionHelper</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests/</directory>
</testsuite>
</testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="vendor/autoload.php" cacheDirectory=".phpunit.cache">
<coverage/>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<directory suffix=".php">src/CodeceptionHelper</directory>
</exclude>
</source>
</phpunit>
4 changes: 1 addition & 3 deletions src/Exception/EnableToGenerateNewIdentityException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@
* @psalm-immutable
* @psalm-suppress MutableDependency
*/
class EnableToGenerateNewIdentityException extends LogicException implements IdentityException
{
}
class EnableToGenerateNewIdentityException extends LogicException implements IdentityException {}
5 changes: 1 addition & 4 deletions tests/Fixtures/FixtureIntIdentity.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,4 @@
* @package JeckelLab\IdentityContract\Test\Fixtures
* @psalm-immutable
*/
class FixtureIntIdentity extends AbstractIntIdentity
{

}
class FixtureIntIdentity extends AbstractIntIdentity {}
5 changes: 1 addition & 4 deletions tests/Fixtures/FixtureStringIdentity.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,4 @@
* @package JeckelLab\IdentityContract\Test\Fixtures
* @psalm-immutable
*/
class FixtureStringIdentity extends AbstractStringIdentity
{

}
class FixtureStringIdentity extends AbstractStringIdentity {}
5 changes: 1 addition & 4 deletions tests/Fixtures/FixtureUuidIdentity.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,4 @@
* @package Tests\JeckelLab\IdentityContract\Fixtures
* @psalm-immutable
*/
class FixtureUuidIdentity extends AbstractUuidIdentity
{

}
class FixtureUuidIdentity extends AbstractUuidIdentity {}
22 changes: 11 additions & 11 deletions tests/IntIdentityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class IntIdentityTest extends TestCase
{
public function testFromWithIntShouldSuccess(): void
{
$this->assertInstanceOf(FixtureIntIdentity::class, FixtureIntIdentity::from(25));
self::assertInstanceOf(FixtureIntIdentity::class, FixtureIntIdentity::from(25));
}

/**
Expand All @@ -44,26 +44,26 @@ public function testNewShouldFail(): void

public function testIdReturnTheProvidedId(): void
{
$this->assertSame(123, FixtureIntIdentity::from(123)->id());
self::assertSame(123, FixtureIntIdentity::from(123)->id());
}

public function testStringifyReturnTheProvidedIdAsString(): void
{
$this->assertSame('123', (string) FixtureIntIdentity::from(123));
self::assertSame('123', (string) FixtureIntIdentity::from(123));
}

public function testEqualsWithSameIdShouldSuccess(): void
{
$id1 = FixtureIntIdentity::from(123);
$id2 = FixtureIntIdentity::from(123);

$this->assertSame($id1, $id2);
$this->assertTrue($id1->equals($id1));
$this->assertTrue($id1->equals($id2));
self::assertSame($id1, $id2);
self::assertTrue($id1->equals($id1));
self::assertTrue($id1->equals($id2));

// Test with same class
$this->assertFalse($id1->equals(FixtureIntIdentity::from(124)));
$this->assertFalse($id1->equals(FixtureStringIdentity::from('Foobar')));
self::assertFalse($id1->equals(FixtureIntIdentity::from(124)));
self::assertFalse($id1->equals(FixtureStringIdentity::from('Foobar')));
}

/**
Expand All @@ -74,7 +74,7 @@ public function testEqualsWithSameIdShouldSuccess(): void
public function testEqualsWithDifferentIdShouldFail(mixed $id): void
{
$id1 = FixtureIntIdentity::from(123);
$this->assertFalse($id1->equals($id));
self::assertFalse($id1->equals($id));
}

/**
Expand All @@ -83,7 +83,7 @@ public function testEqualsWithDifferentIdShouldFail(mixed $id): void
*/
public function testJsonSerialization(): void
{
$this->assertEquals(
self::assertEquals(
123,
json_encode(FixtureIntIdentity::from(123), JSON_THROW_ON_ERROR)
);
Expand All @@ -92,7 +92,7 @@ public function testJsonSerialization(): void
/**
* @return list<list<mixed>>
*/
public function notIntData(): array
public static function notIntData(): array
{
return [
[null],
Expand Down
30 changes: 15 additions & 15 deletions tests/StringIdentityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class StringIdentityTest extends TestCase
{
public function testFromWithStringShouldSuccess(): void
{
$this->assertInstanceOf(FixtureStringIdentity::class, FixtureStringIdentity::from('barfoo'));
self::assertInstanceOf(FixtureStringIdentity::class, FixtureStringIdentity::from('barfoo'));
}

/**
Expand All @@ -34,38 +34,38 @@ public function testFromWithNotStringShouldFail($invalidId): void
public function testNewShouldGenerateRandomId(): void
{
$id1 = FixtureStringIdentity::new();
$this->assertInstanceOf(FixtureStringIdentity::class, $id1);
self::assertInstanceOf(FixtureStringIdentity::class, $id1);

$id2 = FixtureStringIdentity::new();
$this->assertInstanceOf(FixtureStringIdentity::class, $id2);
self::assertInstanceOf(FixtureStringIdentity::class, $id2);

$this->assertNotEquals($id1->id(), $id2->id());
self::assertNotEquals($id1->id(), $id2->id());

$customId = FixtureStringCustomGeneratorIdentity::new();
$this->assertInstanceOf(FixtureStringCustomGeneratorIdentity::class, $customId);
self::assertInstanceOf(FixtureStringCustomGeneratorIdentity::class, $customId);
}

public function testIdReturnTheProvidedId(): void
{
$this->assertSame('foobar', FixtureStringIdentity::from('foobar')->id());
self::assertSame('foobar', FixtureStringIdentity::from('foobar')->id());
}

public function testStringifyReturnTheProvidedIdAsString(): void
{
$this->assertSame('foobar', (string) FixtureStringIdentity::from('foobar'));
self::assertSame('foobar', (string) FixtureStringIdentity::from('foobar'));
}

public function testEqualsWithSameIdShouldSuccess(): void
{
$id1 = FixtureStringIdentity::from('foobar');
$id2 = FixtureStringIdentity::from('foobar');

$this->assertSame($id1, $id2);
$this->assertTrue($id1->equals($id1));
$this->assertTrue($id1->equals($id2));
self::assertSame($id1, $id2);
self::assertTrue($id1->equals($id1));
self::assertTrue($id1->equals($id2));

$this->assertFalse($id1->equals(FixtureStringIdentity::from('foobarbaz')));
$this->assertFalse($id1->equals(FixtureIntIdentity::from(123)));
self::assertFalse($id1->equals(FixtureStringIdentity::from('foobarbaz')));
self::assertFalse($id1->equals(FixtureIntIdentity::from(123)));
}

/**
Expand All @@ -76,7 +76,7 @@ public function testEqualsWithSameIdShouldSuccess(): void
public function testEqualsWithDifferentIdShouldFail(mixed $id): void
{
$id1 = FixtureStringIdentity::from('foobar');
$this->assertFalse($id1->equals($id));
self::assertFalse($id1->equals($id));
}

/**
Expand All @@ -85,7 +85,7 @@ public function testEqualsWithDifferentIdShouldFail(mixed $id): void
*/
public function testJsonSerialization(): void
{
$this->assertEquals(
self::assertEquals(
'"foobar"',
json_encode(FixtureStringIdentity::from('foobar'), JSON_THROW_ON_ERROR)
);
Expand All @@ -94,7 +94,7 @@ public function testJsonSerialization(): void
/**
* @return list<list<mixed>>
*/
public function notStringData(): array
public static function notStringData(): array
{
return [
[null],
Expand Down
Loading

0 comments on commit 2ccabc8

Please sign in to comment.