Skip to content

Commit

Permalink
feat: change github actions (add more php versions), add return types…
Browse files Browse the repository at this point in the history
…, remove composer.json minimum dev, add phpunit 9 support
  • Loading branch information
Chris53897 committed Sep 30, 2021
1 parent 49dc8dc commit 1d392da
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 72 deletions.
67 changes: 31 additions & 36 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,37 @@
# .github/workflows/tests.yaml
name: Tests

on: [push]
on: ["push", "pull_request"]

jobs:
phpunit73:
name: "Tests on PHP 7.3"
tests:
runs-on: ubuntu-latest
container:
image: lorisleiva/laravel-docker:7.3
steps:
- uses: actions/checkout@v2
- name: Validate composer.json and composer.lock
run: composer validate
- name: Cache dependencies
uses: actions/cache@v1
with:
path: /composer/cache/files
key: dependencies-composer-${{ hashFiles('composer.json') }}
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest
- name: Run tests
run: phpunit

phpunit74:
name: "Tests on PHP 7.4"
runs-on: ubuntu-latest
container:
image: lorisleiva/laravel-docker:7.4
strategy:
fail-fast: false
matrix:
php: ['7.3', '7.4', '8.0', '8.1']
stability: [ prefer-lowest, prefer-stable ]

name: PHP ${{ matrix.php }} - ${{ matrix.stability }} tests
steps:
- uses: actions/checkout@v2
- name: Validate composer.json and composer.lock
run: composer validate
- name: Cache dependencies
uses: actions/cache@v1
with:
path: /composer/cache/files
key: dependencies-composer-${{ hashFiles('composer.json') }}
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest
- name: Run tests
run: phpunit
# basically git clone
- uses: actions/checkout@v2

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

# use PHP of specific version
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: pcov
coverage: pcov

- name: Install dependencies
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress --no-suggest

- name: Execute tests
run: vendor/bin/phpunit --verbose
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"php" : "^7.3 || ^8.0"
},
"require-dev": {
"phpunit/phpunit" : "^8.0"
"phpunit/phpunit" : "^8.0 || ^9.0"
},
"autoload": {
"psr-4": {
Expand All @@ -30,7 +30,5 @@
"psr-4": {
"Lorisleiva\\CronTranslator\\Tests\\": "tests"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
}
28 changes: 15 additions & 13 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
</phpunit>
4 changes: 2 additions & 2 deletions src/CronExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(string $cron, string $locale = 'en', bool $timeForma
$this->loadTranslations();
}

public function getFields()
public function getFields(): array
{
return [
$this->minute,
Expand Down Expand Up @@ -108,7 +108,7 @@ protected function loadTranslationFile(string $file)
return include $filename;
}

protected function getTranslationDirectory()
protected function getTranslationDirectory(): string
{
return __DIR__ . '/lang/' . $this->locale;
}
Expand Down
2 changes: 1 addition & 1 deletion src/CronTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CronTranslator
'@hourly' => '0 * * * *'
];

public static function translate(string $cron, string $locale = 'en', bool $timeFormat24hours = false)
public static function translate(string $cron, string $locale = 'en', bool $timeFormat24hours = false): string
{
if (isset(self::$extendedMap[$cron])) {
$cron = self::$extendedMap[$cron];
Expand Down
12 changes: 6 additions & 6 deletions src/CronType.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,27 @@ private function __construct(string $type, ?int $value = null, ?int $count = nul
$this->increment = $increment;
}

public static function every()
public static function every(): CronType
{
return new static('Every');
}

public static function increment(int $increment, int $count = 1)
public static function increment(int $increment, int $count = 1): CronType
{
return new static('Increment', null, $count, $increment);
}

public static function multiple(int $count)
public static function multiple(int $count): CronType
{
return new static('Multiple', null, $count);
}

public static function once(int $value)
public static function once(int $value): CronType
{
return new static('Once', $value);
}

public static function parse(string $expression)
public static function parse(string $expression): CronType
{
// Parse "*".
if ($expression === '*') {
Expand Down Expand Up @@ -88,7 +88,7 @@ public static function parse(string $expression)
throw new CronParsingException($expression);
}

public function hasType()
public function hasType(): bool
{
return in_array($this->type, func_get_args());
}
Expand Down
8 changes: 4 additions & 4 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ public function translate()
}
}

public function hasType()
public function hasType(): bool
{
return $this->type->hasType(...func_get_args());
}

public function getValue()
public function getValue(): ?int
{
return $this->type->value;
}

public function getCount()
public function getCount(): ?int
{
return $this->type->count;
}

public function getIncrement()
public function getIncrement(): ?int
{
return $this->type->increment;
}
Expand Down
2 changes: 1 addition & 1 deletion src/HoursField.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function translateOnce()
]);
}

public function format(?MinutesField $minute = null)
public function format(?MinutesField $minute = null): string
{
if ($this->expression->timeFormat24hours) {
$hour = $this->getValue();
Expand Down
2 changes: 1 addition & 1 deletion src/MinutesField.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function translateMultiple()
]);
}

public function format()
public function format(): string
{
return ($this->getValue() < 10 ? '0' : '') . $this->getValue();
}
Expand Down
9 changes: 5 additions & 4 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

class TestCase extends BaseTestCase
{
public function assertCronTranslateTo($expected, $actual, $locale = 'en', $timeFormat24hours = false)
public function assertCronTranslateTo(string $expected, string $actual, string $locale = 'en', bool $timeFormat24hours = false)
{
$this->assertEquals($expected, CronTranslator::translate($actual, $locale, $timeFormat24hours));
}

public function assertCronThrowsParsingError($cron)
public function assertCronThrowsParsingError(string $cron)
{
try {
CronTranslator::translate($cron);
Expand All @@ -25,9 +25,10 @@ public function assertCronThrowsParsingError($cron)
$this->fail("Expected CronParsingError exception for [$cron]");
}

public function generateCombinationsFromMatrix($matrix, $locale = 'en', $timeFormat24hours = false)
public function generateCombinationsFromMatrix(array $matrix, string $locale = 'en', bool $timeFormat24hours = false)
{
function combinations($matrix, $acc = []) {
function combinations($matrix, $acc = []): array
{
if (empty($matrix)) {
return [implode(' ', $acc)];
}
Expand Down

0 comments on commit 1d392da

Please sign in to comment.