Skip to content

Commit

Permalink
Merge pull request #6 from stylers-llc/4.0
Browse files Browse the repository at this point in the history
feat: laravel 8 upgrade and tests upgrades
  • Loading branch information
t1k3 committed Jan 3, 2024
2 parents 1d0c185 + e426a7a commit 5442581
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 65 deletions.
10 changes: 0 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,7 @@ jobs:
with:
php-version: ${{ matrix.php_versions }}

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run test suite
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
],
"require": {
"php": ">=7.3",
"illuminate/support": "^7"
"illuminate/support": "^8"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.18",
"orchestra/testbench": "~3.0|~3.6|~3.7|~4.0|~5.0",
"orchestra/testbench": "^6.0",
"phpmd/phpmd": "^2.6",
"phpunit/phpunit": "^7.5.15 || ^8.4 || ^9.5.4"
},
Expand Down
59 changes: 26 additions & 33 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,35 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Unit">
<directory suffix=".php">tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix=".php">tests/Feature</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="build/phpunit/html"/>
<log type="coverage-clover" target="build/phpunit/clover.xml"/>
<log type="coverage-text" target="build/phpunit/coverage.txt"/>
</logging>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
</php>
<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" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<clover outputFile="build/phpunit/clover.xml"/>
<html outputDirectory="build/phpunit/html"/>
<text outputFile="build/phpunit/coverage.txt"/>
</report>
</coverage>
<testsuites>
<testsuite name="Unit">
<directory suffix=".php">tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix=".php">tests/Feature</directory>
</testsuite>
</testsuites>
<logging/>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
</php>
</phpunit>
21 changes: 15 additions & 6 deletions tests/Feature/Console/TaskManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
use Carbon\Carbon;
use Illuminate\Console\Command;
use Mockery\MockInterface;
use PHPUnit\Framework\MockObject\Matcher\Invocation;
use PHPUnit\Framework\MockObject\Rule\InvokedCount;
use Stylers\TaskManager\Console\TaskManager;
use Stylers\TaskManager\Contracts\TaskTimerInterface;
use Stylers\TaskManager\Tests\TestCase;
use Stylers\TaskManager\Tests\Fixtures\CommandTask;
use Stylers\TaskManager\Tests\TestCase;

class TaskManagerTest extends TestCase
{
Expand Down Expand Up @@ -109,15 +108,21 @@ public function processTimeDataProvider(): array
$beforeCurrentMinute = abs($currentMinute - 10);

return [
'run - run' => [self::once(), $currentMinute, true, self::once(), $currentMinute, true],
'run - not run' => [self::once(), $currentMinute, true, self::never(), $beforeCurrentMinute, false],
'not run - not run' => [self::never(), $beforeCurrentMinute, false, self::never(), $beforeCurrentMinute, false],
'run - run' => [self::once(), $currentMinute, true, self::once(), $currentMinute, true],
'run - not run' => [self::once(), $currentMinute, true, self::never(), $beforeCurrentMinute, false],
'not run - not run' => [self::never(), $beforeCurrentMinute, false, self::never(), $beforeCurrentMinute, false],
];
}

/**
* @test
* @dataProvider processTimeDataProvider
* @param InvokedCount $task1Times
* @param int $task1Interval
* @param bool $task1IsTimeToExecute
* @param InvokedCount $task2Times
* @param int $task2Interval
* @param bool $task2IsTimeToExecute
*/
public function it_can_handle_correcty_all_tasks_time(
InvokedCount $task1Times,
Expand All @@ -126,7 +131,8 @@ public function it_can_handle_correcty_all_tasks_time(
InvokedCount $task2Times,
int $task2Interval,
bool $task2IsTimeToExecute
) {
)
{
/** @var TaskTimerInterface $task */
$task = $this->assertMockTaskMethodHandleCalled($task1Times, $task1Interval);
$task2 = $this->assertMockTaskMethodHandleCalled($task2Times, $task2Interval);
Expand All @@ -142,6 +148,7 @@ public function it_can_handle_correcty_all_tasks_time(
}

/**
* @param bool $returnValue
* @return object|TaskTimerInterface
*/
private function mockTaskMethodIsTimeToExecuteAndReturn(bool $returnValue)
Expand All @@ -157,6 +164,8 @@ private function mockTaskMethodIsTimeToExecuteAndReturn(bool $returnValue)
}

/**
* @param InvokedCount $times
* @param int $minutes
* @return object|TaskTimerInterface
*/
private function assertMockTaskMethodHandleCalled(InvokedCount $times, int $minutes)
Expand Down
27 changes: 13 additions & 14 deletions tests/Unit/Traits/TaskTimerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use Cron\CronExpression;
use Illuminate\Support\Facades\Log;
use Stylers\TaskManager\Contracts\TaskTimerInterface;
use Stylers\TaskManager\Tests\TestCase;
use Stylers\TaskManager\Tests\Fixtures\CommandTask;
use Stylers\TaskManager\Tests\TestCase;

class TaskTimerTest extends TestCase
{
Expand Down Expand Up @@ -49,8 +49,8 @@ public function it_can_set_specified_minutes()
{
$task = $this->subject->hourlyAt(self::MINUTE);

$expectedExpression = CronExpression::factory(sprintf('%d * * * *', self::MINUTE))
->getExpression();
$expectedExpression = new CronExpression(sprintf('%d * * * *', self::MINUTE));
$expectedExpression->getExpression();

self::assertEquals($expectedExpression, $task->expression);
}
Expand All @@ -62,9 +62,8 @@ public function it_can_set_every_week_on_monday_at_7_40()
{
$task = $this->subject->weeklyOn(Carbon::MONDAY, sprintf(self::TIME_PATTERN, self::HOUR, self::MINUTE));

$expectedExpression = CronExpression::factory(
sprintf('%d %d * * %d', self::MINUTE, self::HOUR, Carbon::MONDAY)
)->getExpression();
$expectedExpression = new CronExpression(sprintf('%d %d * * %d', self::MINUTE, self::HOUR, Carbon::MONDAY));
$expectedExpression->getExpression();

self::assertEquals($expectedExpression, $task->expression);
}
Expand All @@ -76,8 +75,8 @@ public function it_can_set_monthly()
{
$task = $this->subject->monthly();

$expectedExpression = CronExpression::factory('@monthly')
->getExpression();
$expectedExpression = new CronExpression('@monthly');
$expectedExpression->getExpression();

self::assertEquals($expectedExpression, $task->expression);
}
Expand All @@ -89,9 +88,9 @@ public function it_can_set_monthly_on_friday_at_7_hour()
{
$task = $this->subject->monthlyOn(Carbon::FRIDAY, sprintf('%d:00', self::HOUR));

$expectedExpression = CronExpression::factory('@monthly')
->setPart(CronExpression::DAY, Carbon::FRIDAY)
->setPart(CronExpression::HOUR, self::HOUR)
$expectedExpression = new CronExpression('@monthly');
$expectedExpression->setPart(CronExpression::DAY, (string)Carbon::FRIDAY)
->setPart(CronExpression::HOUR, (string)self::HOUR)
->getExpression();

self::assertEquals($expectedExpression, $task->expression);
Expand All @@ -104,9 +103,9 @@ public function it_can_set_daily_at_7_40()
{
$task = $this->subject->dailyAt(sprintf(self::TIME_PATTERN, self::HOUR, self::MINUTE));

$expectedExpression = CronExpression::factory('@daily')
->setPart(CronExpression::HOUR, self::HOUR)
->setPart(CronExpression::MINUTE, self::MINUTE)
$expectedExpression = new CronExpression('@daily');
$expectedExpression->setPart(CronExpression::HOUR, (string)self::HOUR)
->setPart(CronExpression::MINUTE, (string)self::MINUTE)
->getExpression();

self::assertEquals($expectedExpression, $task->expression);
Expand Down

0 comments on commit 5442581

Please sign in to comment.