Skip to content

Commit

Permalink
Merge pull request #41 from tattersoftware/retool
Browse files Browse the repository at this point in the history
Update Toolkit
  • Loading branch information
MGatner authored Jul 10, 2022
2 parents c7ffd42 + 410f891 commit 31ef7d8
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 26 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://editorconfig.org

root = true

[*]
charset = utf-8
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{yml,yaml}]
indent_size = 2
71 changes: 71 additions & 0 deletions .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Psalm

on:
pull_request:
branches:
- develop
paths:
- '**.php'
- 'composer.*'
- 'psalm*'
- '.github/workflows/psalm.yml'
push:
branches:
- develop
paths:
- '**.php'
- 'composer.*'
- 'psalm*'
- '.github/workflows/psalm.yml'

jobs:
build:
name: Psalm Analysis
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]')"

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
tools: phpstan, phpunit
extensions: intl, json, mbstring, xml
coverage: none
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache composer dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Create Psalm cache directory
run: mkdir -p build/psalm

- name: Cache Psalm results
uses: actions/cache@v3
with:
path: build/psalm
key: ${{ runner.os }}-psalm-${{ github.sha }}
restore-keys: ${{ runner.os }}-psalm-

- name: Install dependencies
run: |
if [ -f composer.lock ]; then
composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
else
composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
fi
- name: Run Psalm analysis
run: vendor/bin/psalm
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,18 @@
"sort-packages": true
},
"scripts": {
"analyze": "phpstan analyze",
"analyze": [
"phpstan analyze",
"psalm",
"rector process --dry-run"
],
"ci": [
"Composer\\Config::disableProcessTimeout",
"@deduplicate",
"@analyze",
"@composer normalize --dry-run",
"@test",
"@inspect",
"rector process",
"@style"
],
"deduplicate": "phpcpd app/ src/",
Expand Down
18 changes: 18 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<psalm
errorLevel="7"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
autoloader="psalm_autoload.php"
cacheDirectory="build/psalm/"
>
<projectFiles>
<directory name="src/" />
<directory name="tests/" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
20 changes: 20 additions & 0 deletions psalm_autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

require __DIR__ . '/vendor/codeigniter4/framework/system/Test/bootstrap.php';

$helperDirs = [
'vendor/codeigniter4/framework/system/Helpers',
];

foreach ($helperDirs as $dir) {
$dir = __DIR__ . '/' . $dir;
chdir($dir);

foreach (glob('*_helper.php') as $filename) {
$filePath = realpath($dir . '/' . $filename);

require_once $filePath;
}
}
3 changes: 2 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
$rectorConfig->rule(NormalizeNamespaceByPSR4ComposerAutoloadRector::class);
$rectorConfig
->ruleWithConfiguration(TypedPropertyRector::class, [
TypedPropertyRector::INLINE_PUBLIC => false,
// Set to false if you use in libraries, or it does create breaking changes.
TypedPropertyRector::INLINE_PUBLIC => true,
]);
};
3 changes: 3 additions & 0 deletions src/Commands/HandlersCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class HandlersCache extends BaseCommand
protected $description = 'Discovers and caches all handlers';
protected $usage = 'handlers:cache';

/**
* @return void
*/
public function run(array $params = [])
{
// Make sure caching is enabled
Expand Down
3 changes: 3 additions & 0 deletions src/Commands/HandlersClear.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class HandlersClear extends BaseCommand
protected $description = 'Clears cached versions of discovered handlers';
protected $usage = 'handlers:clear';

/**
* @return void
*/
public function run(array $params = [])
{
$count = cache()->deleteMatching('handlers-*');
Expand Down
26 changes: 13 additions & 13 deletions tests/BaseFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
final class BaseFactoryTest extends TestCase
{
public function testNoDiscoveryReturnsEmptyArray()
public function testNoDiscoveryReturnsEmptyArray(): void
{
$factory = new class () extends BaseFactory {
public const HANDLER_PATH = 'Bananas';
Expand All @@ -19,7 +19,7 @@ public function testNoDiscoveryReturnsEmptyArray()
$this->assertSame([], $factory::findAll());
}

public function testGetHandlerClassReturnsClass()
public function testGetHandlerClassReturnsClass(): void
{
$expected = 'Tests\Support\Cars\WidgetCar';

Expand All @@ -29,36 +29,36 @@ public function testGetHandlerClassReturnsClass()
$this->assertSame($expected, $result);
}

public function testGetHandlerClassRequiresPhpExtension()
public function testGetHandlerClassRequiresPhpExtension(): void
{
$result = CarFactory::getHandlerClass('foo', 'bar');

$this->assertNull($result);
}

public function testGetHandlerClassRequiresInterfaces()
public function testGetHandlerClassRequiresInterfaces(): void
{
$result = CarFactory::getHandlerClass(SUPPORTPATH . 'Cars/NotCar.php', 'Tests\Support');

$this->assertNull($result);
}

public function testGetHandlerClassRequiresHandlerInterface()
public function testGetHandlerClassRequiresHandlerInterface(): void
{
$result = CarFactory::getHandlerClass(SUPPORTPATH . 'Cars/BadCar.php', 'Tests\Support');

$this->assertNull($result);
}

public function testGetHandlerClassFails()
public function testGetHandlerClassFails(): void
{
$file = realpath(SUPPORTPATH . 'Cars/WidgetCar.php');
$result = CarFactory::getHandlerClass($file, 'Foo\Bar');

$this->assertNull($result);
}

public function testIgnoresClass()
public function testIgnoresClass(): void
{
config('Handlers')->ignoredClasses[] = 'Tests\Support\Cars\PopCar';

Expand All @@ -68,7 +68,7 @@ public function testIgnoresClass()
$this->assertSame($expected, $result);
}

public function testCollision()
public function testCollision(): void
{
// Stop ignoring the collision clas
config('Handlers')->ignoredClasses = [];
Expand All @@ -79,7 +79,7 @@ public function testCollision()
CarFactory::findAll();
}

public function testFindAll()
public function testFindAll(): void
{
$expected = [
'pop' => 'Tests\Support\Cars\PopCar',
Expand All @@ -91,7 +91,7 @@ public function testFindAll()
$this->assertSame($expected, $result);
}

public function testFind()
public function testFind(): void
{
$expected = 'Tests\Support\Cars\PopCar';

Expand All @@ -100,15 +100,15 @@ public function testFind()
$this->assertSame($expected, $result);
}

public function testFindThrows()
public function testFindThrows(): void
{
$this->expectException('RuntimeException');
$this->expectExceptionMessage('Unknown handler "banana" for ' . CarFactory::class);

CarFactory::find('banana');
}

public function testResetSingle()
public function testResetSingle(): void
{
CarFactory::findAll();
FactoryFactory::findAll();
Expand All @@ -121,7 +121,7 @@ public function testResetSingle()
$this->assertSame(['Factories'], array_keys($result));
}

public function testResetAll()
public function testResetAll(): void
{
CarFactory::findAll();
FactoryFactory::findAll();
Expand Down
6 changes: 3 additions & 3 deletions tests/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protected function tearDown(): void
CarFactory::clearCache();
}

public function testDiscoveryUsesCache()
public function testDiscoveryUsesCache(): void
{
// Reenable caching
config('Handlers')->cacheDuration = MINUTE;
Expand All @@ -28,7 +28,7 @@ public function testDiscoveryUsesCache()
$this->assertSame($expected, $result); // @phpstan-ignore-line
}

public function testDiscoveryCreatesCache()
public function testDiscoveryCreatesCache(): void
{
// Reenable caching
config('Handlers')->cacheDuration = MINUTE;
Expand All @@ -41,7 +41,7 @@ public function testDiscoveryCreatesCache()
$this->assertSame('Tests\Support\Cars\PopCar', $result['pop']);
}

public function testDiscoveryIgnoresCache()
public function testDiscoveryIgnoresCache(): void
{
$expected = [
'pop' => 'Tests\Support\Cars\PopCar',
Expand Down
12 changes: 6 additions & 6 deletions tests/CommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ protected function tearDown(): void
stream_filter_remove($this->streamFilter);
}

protected function getBuffer()
protected function getBuffer(): string
{
return CITestStreamFilter::$buffer;
}

public function testCacheFailsCachingDisabled()
public function testCacheFailsCachingDisabled(): void
{
config('Handlers')->cacheDuration = null;

Expand All @@ -48,7 +48,7 @@ public function testCacheFailsCachingDisabled()
$this->assertStringContainsString('Handler caching is disabled by the Tatter\Handlers Config file', $this->getBuffer());
}

public function testCacheCreatesCache()
public function testCacheCreatesCache(): void
{
command('handlers:cache');

Expand All @@ -61,7 +61,7 @@ public function testCacheCreatesCache()
$this->assertSame('Tests\Support\Cars\PopCar', $result['pop']);
}

public function testCacheReportsErrors()
public function testCacheReportsErrors(): void
{
// Stop ignoring the ErrorFactory
unset(config('Handlers')->ignoredClasses[1]);
Expand All @@ -76,7 +76,7 @@ public function testCacheReportsErrors()
$this->assertSame(ErrorFactory::class, $result['error']);
}

public function testCacheErrorsNoHandlers()
public function testCacheErrorsNoHandlers(): void
{
// Ignore all Factories
config('Handlers')->ignoredClasses = [
Expand All @@ -90,7 +90,7 @@ public function testCacheErrorsNoHandlers()
$this->assertStringContainsString('No factories discovered!', $this->getBuffer());
}

public function testClearRemovesCache()
public function testClearRemovesCache(): void
{
command('handlers:cache');
$this->assertNotNull(cache()->get('handlers-factories'));
Expand Down
2 changes: 1 addition & 1 deletion tests/FactoryFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
final class FactoryFactoryTest extends TestCase
{
public function testDiscovers()
public function testDiscovers(): void
{
// Discovery is alphabetical by ID
$expected = [
Expand Down

0 comments on commit 31ef7d8

Please sign in to comment.