Skip to content

Commit

Permalink
Merge pull request #4 from lentex/dev/housekeeping
Browse files Browse the repository at this point in the history
Housekeeping
  • Loading branch information
lentex authored Feb 28, 2024
2 parents d65fd27 + e86e3d9 commit 95de29a
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 77 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [ "8.2" ]
php: [ "8.3" ]

runs-on: [self-hosted, linux, x64]
name: PHP@${{ matrix.php }}
Expand All @@ -22,6 +22,8 @@ jobs:

- name: Install composer dependencies
run: composer install --prefer-dist --no-progress --no-suggest
env:
COMPOSER_ALLOW_SUPERUSER: 1

- name: Run Testsuite
run: composer run-script test
Expand All @@ -30,4 +32,7 @@ jobs:
run: composer run-script lint

- name: Run Static Analysis
run: composer run-script analyse
run: composer run-script analyse

- name: Run Type Coverage
run: composer run-script coverage:type
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/vendor/
composer.lock
.phpunit.result.cache
.phpunit.cache
coverage.xml
/coverage/
junit.xml
21 changes: 11 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
"type": "package",
"description": "The Gaudigame Engine",
"require": {
"php": "8.2.*"
"php": "8.3.*"
},
"require-dev": {
"laravel/pint": "^1.4",
"pestphp/pest": "^1.22",
"phpstan/phpstan": "^1.9"
"laravel/pint": "^1.14",
"pestphp/pest": "^2.34",
"pestphp/pest-plugin-type-coverage": "^2.8",
"phpstan/phpstan": "^1.10.59"
},
"autoload": {
"psr-4": {
"Lentex\\Gaudigame\\Engine\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"analyse": "phpstan analyse src tests --memory-limit 512M",
"lint": "pint --test",
"lint:verbose": "pint -v --test",
"fix": "pint",
"test": "pest",
"test:all": "@test",
"test:unit": "pest --group=unit",
"test:architecture": "pest --group=architecture",
"coverage:type": "pest --type-coverage --min=100",
"coverage": "pest --coverage --ci --coverage-html coverage --coverage-clover coverage.xml --log-junit junit.xml",
"report": "pest --coverage",
"report:html": "pest --coverage --coverage-html coverage"
Expand All @@ -34,7 +34,8 @@
"optimize-autoloader": true,
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true
"pestphp/pest-plugin": true,
"pestphp/pest-plugin-type-coverage": true
}
},
"prefer-stable": true,
Expand Down
14 changes: 9 additions & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ parameters:
# @see https://pestphp.com/docs/underlying-test-case
-
message: '#^Undefined variable: \$this$#'
paths:
- tests/*
reportUnmatched: false
path: tests/*
-
message: '#^Call to an undefined method Pest\\Expectation\|Pest\\Support\\Extendable\:\:[a-zA-Z]+\(\)\.$#'
paths:
- tests/*
message: '#^Call to an undefined method Pest\\Expectation<([a-zA-Z|\\\\]+)>\:\:[a-zA-Z]+\(\)\.$#'
reportUnmatched: false
path: tests/*
-
message: "#^Call to an undefined method Pest\\\\PendingCalls\\\\TestCall\\:\\:expect\\(\\)\\.$#"
reportUnmatched: false
path: tests/*

29 changes: 14 additions & 15 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="architecture">
<directory suffix="Test.php">./tests/Architecture</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
2 changes: 2 additions & 0 deletions src/Contracts/CalculationModel.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Lentex\Gaudigame\Engine\Contracts;

interface CalculationModel
Expand Down
8 changes: 2 additions & 6 deletions src/Contracts/Score.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
<?php

declare(strict_types=1);

namespace Lentex\Gaudigame\Engine\Contracts;

interface Score
{
public function canBeEvaluated(): bool;

public function home(): int;

public function away(): int;

public function isDraw(): bool;

public function isHomeWin(): bool;

public function isAwayWin(): bool;

public function margin(): int;
}
23 changes: 16 additions & 7 deletions src/DefaultCalculationModel.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,47 @@
<?php

declare(strict_types=1);

namespace Lentex\Gaudigame\Engine;

use Lentex\Gaudigame\Engine\Contracts\CalculationModel;

class DefaultCalculationModel implements CalculationModel
final class DefaultCalculationModel implements CalculationModel
{
private const int EXACT = 3;
private const int EXACT_GAP = 2;
private const int DRAW_GAP = 1;
private const int TENDENCY = 1;
private const int WRONG = 0;
private const int NO = 0;

public function getPointsForExactGuess(): int
{
return 3;
return self::EXACT;
}

public function getPointsForExactGap(): int
{
return 2;
return self::EXACT_GAP;
}

public function getPointsForDrawGap(): int
{
return 1;
return self::DRAW_GAP;
}

public function getPointsForTendency(): int
{
return 1;
return self::TENDENCY;
}

public function getPointsForWrongGuess(): int
{
return 0;
return self::WRONG;
}

public function getPointsForNoGuess(): int
{
return 0;
return self::NO;
}
}
4 changes: 3 additions & 1 deletion src/EvaluatedResult.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

declare(strict_types=1);

namespace Lentex\Gaudigame\Engine;

class EvaluatedResult
final class EvaluatedResult
{
private float $points = 0.0;
private bool $boost = false;
Expand Down
8 changes: 5 additions & 3 deletions src/MatchCalculator.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php

declare(strict_types=1);

namespace Lentex\Gaudigame\Engine;

use Lentex\Gaudigame\Engine\Contracts\CalculationModel;
use Lentex\Gaudigame\Engine\Contracts\Score;

class MatchCalculator
final class MatchCalculator
{
private const DEFAULT_POINTS = 0.0;
private const DEFAULT_BOOST = 1.0;
private const float DEFAULT_POINTS = 0.0;
private const float DEFAULT_BOOST = 1.0;

private float $points = self::DEFAULT_POINTS;
private float $boost = self::DEFAULT_BOOST;
Expand Down
4 changes: 3 additions & 1 deletion src/NoScore.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php

declare(strict_types=1);

namespace Lentex\Gaudigame\Engine;

use Lentex\Gaudigame\Engine\Contracts\Score;

class NoScore implements Score
final class NoScore implements Score
{
public function home(): int
{
Expand Down
6 changes: 4 additions & 2 deletions src/Score.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<?php

declare(strict_types=1);

namespace Lentex\Gaudigame\Engine;

use Lentex\Gaudigame\Engine\Contracts\Score as ScoreContract;

class Score implements ScoreContract
final class Score implements ScoreContract
{
private bool $isDraw = false;
private bool $isHomeWin = false;
private bool $isAwayWin = false;
private int $margin = 0;

public function __construct(private int $home, private int $away)
public function __construct(private readonly int $home, private readonly int $away)
{
$this->setupCalculationBasis();
}
Expand Down
16 changes: 16 additions & 0 deletions tests/Architecture/ArchitectureTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

arch('strict types')
->expect('Lentex\Gaudigame\Engine')
->toUseStrictTypes();

arch('contracts')
->expect('Lentex\Gaudigame\Engine\Contracts')
->toBeInterface();

arch('final')
->expect('Lentex\Gaudigame\Engine')
->classes()
->toBeFinal();
27 changes: 4 additions & 23 deletions tests/Pest.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
<?php

/*
|--------------------------------------------------------------------------
| Test Case
|--------------------------------------------------------------------------
|
| The closure you provide to your test functions is always bound to a specific PHPUnit test
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
| need to change it using the "uses()" function to bind a different classes or traits.
|
*/

// uses(Tests\TestCase::class)->in('Feature');

/*
|--------------------------------------------------------------------------
| Expectations
|--------------------------------------------------------------------------
|
| When you're writing tests, you often need to check that values meet certain conditions. The
| "expect()" function gives you access to a set of "expectations" methods that you can use
| to assert different things. Of course, you may extend the Expectation API at any time.
|
*/
declare(strict_types=1);

use Lentex\Gaudigame\Engine\DefaultCalculationModel;
use Lentex\Gaudigame\Engine\Score;

uses()->group('architecture')->in('Architecture');
uses()->group('unit')->in('Unit');

expect()->extend('toBeNoGuess', function () {
$this->getPoints()->toEqual((float) (new DefaultCalculationModel())->getPointsForNoGuess())
->isExact()->toBeFalse()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tests;
declare(strict_types=1);

use Lentex\Gaudigame\Engine\DefaultCalculationModel;
use Lentex\Gaudigame\Engine\MatchCalculator;
Expand Down
2 changes: 2 additions & 0 deletions tests/NoScoreTest.php → tests/Unit/NoScoreTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use Lentex\Gaudigame\Engine\NoScore;

test('public no score methods', function () {
Expand Down

0 comments on commit 95de29a

Please sign in to comment.