Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate phpcsfixer for development #27

Merged
merged 6 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,36 @@ jobs:

- name: Run unit tests
run: docker exec mycontainer vendor/bin/phpunit

job3:
strategy:
matrix:
php_version: ["8.1"]
name: PhpCsFixer code style checker ${{ matrix.php_version }}
runs-on: ubuntu-latest
steps:
- name: Checkout codebase
uses: actions/checkout@v3

- name: Enable caching
uses: satackey/[email protected]
# Deprecation warnings are expected...
continue-on-error: true

- name: Build image
run: docker image build . -f Dockerfile -t myimage:latest --build-arg PHP_VERSION=${{ matrix.php_version }}

- name: Launch container
run: docker run -d -v "$(pwd)/:/app" --name mycontainer myimage:latest tail -f /dev/null

- name: Check PHP version
run: docker exec mycontainer php -v

- name: Check composer.json validity
run: docker exec mycontainer composer validate

- name: Install dependencies
run: docker exec mycontainer composer install

- name: Run unit tests
run: docker exec mycontainer vendor/friendsofphp/php-cs-fixer/php-cs-fixer check
10 changes: 6 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
composer.lock
vendor
.phpunit.cache
.env
/composer.lock
/vendor
/.phpunit.cache
/.php-cs-fixer.cache

.env
17 changes: 17 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$finder = (new Finder())
->ignoreDotFiles(false)
->ignoreVCSIgnored(true)
->in(__DIR__);

return (new Config())
->setRules([
'@PSR12' => true,
'concat_space' => ['spacing' => 'one'],
'new_with_parentheses' => false,
])
->setFinder($finder);
3 changes: 3 additions & 0 deletions aliases
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ alias php='d php "$@"'
alias composer='d composer "$@"'
alias phpstan='d vendor/bin/phpstan analyze "$@"'
alias phpunit='d vendor/bin/phpunit "$@"'
alias phpcsfixer='d vendor/friendsofphp/php-cs-fixer/php-cs-fixer "$@"'

alias reload='. ./aliases'
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"league/flysystem-adapter-test-utilities": "^3.15",
"league/flysystem-memory": "^3.15",
"symfony/cache": "^6.3|^7.0",
"league/flysystem-aws-s3-v3": "^3.15"
"league/flysystem-aws-s3-v3": "^3.15",
"friendsofphp/php-cs-fixer": "^3.68"
},
"suggest": {
"symfony/cache": "Ready to use adapters for the most common caching backends"
Expand Down
4 changes: 2 additions & 2 deletions src/CacheItemsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
*/
trait CacheItemsTrait
{
static string $CACHE_KEY_PREFIX = 'flysystem_item_';
static string $CACHE_KEY_HASH_SALT = '563ce5132194441b';
public static string $CACHE_KEY_PREFIX = 'flysystem_item_';
public static string $CACHE_KEY_HASH_SALT = '563ce5132194441b';

protected function getCacheItem(string $path): CacheItemInterface
{
Expand Down
32 changes: 0 additions & 32 deletions tests/CacheAdapter_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,4 @@ protected static function createFilesystemAdapter(): FilesystemAdapter

return new CacheAdapter($fileSystemAdapter, $cache);
}

/**
* @test
* @dataProvider filenameProvider2
*/
public function writing_and_reading_files_with_special_path(string $path): void
{
parent::writing_and_reading_files_with_special_path($path);
}

/**
* "Override" function from parent which is not static and thus incompatible with phpunit 10
* @todo Remove when https://github.com/thephpleague/flysystem-adapter-test-utilities/commit/bf4c950b176bbefcc49c443cdab1ffb62a9fef5c is tagged (version >= 3.16?)
* @return Generator
*/
public static function filenameProvider2(): Generator
{
yield "a path with square brackets in filename 1" => ["some/file[name].txt"];
yield "a path with square brackets in filename 2" => ["some/file[0].txt"];
yield "a path with square brackets in filename 3" => ["some/file[10].txt"];
yield "a path with square brackets in dirname 1" => ["some[name]/file.txt"];
yield "a path with square brackets in dirname 2" => ["some[0]/file.txt"];
yield "a path with square brackets in dirname 3" => ["some[10]/file.txt"];
yield "a path with curly brackets in filename 1" => ["some/file{name}.txt"];
yield "a path with curly brackets in filename 2" => ["some/file{0}.txt"];
yield "a path with curly brackets in filename 3" => ["some/file{10}.txt"];
yield "a path with curly brackets in dirname 1" => ["some{name}/filename.txt"];
yield "a path with curly brackets in dirname 2" => ["some{0}/filename.txt"];
yield "a path with curly brackets in dirname 3" => ["some{10}/filename.txt"];
yield "a path with space in dirname" => ["some dir/filename.txt"];
yield "a path with space in filename" => ["somedir/file name.txt"];
}
}
6 changes: 3 additions & 3 deletions tests/CacheTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function setUp(): void
}

/**
* @param array<string, FileAttributes|DirectoryAttributes> $items
* @param array<string, FileAttributes|DirectoryAttributes> $items
*/
protected function setupCache(array $items): void
{
Expand All @@ -71,7 +71,7 @@ protected function setupCache(array $items): void
}

/**
* @param array<string, string> $items
* @param array<string, string> $items
*/
protected function setupFiles(array $items): void
{
Expand All @@ -81,7 +81,7 @@ protected function setupFiles(array $items): void
}

/**
* @param array<string, StorageAttributes|FileAttributes|DirectoryAttributes|null> $items
* @param array<string, StorageAttributes|FileAttributes|DirectoryAttributes|null> $items
*/
protected function assertCachedItems(array $items): void
{
Expand Down
6 changes: 3 additions & 3 deletions tests/Copy_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class Copy_Test extends CacheTestCase
{
/**
/**
* @test
* @dataProvider dataProvider
*/
Expand All @@ -27,7 +27,7 @@ public function copy_ok(string $source, FileAttributes|null $expectedSourceCache
}

/**
*
*
* @return iterable<array<mixed>>
*/
public static function dataProvider(): iterable
Expand All @@ -36,7 +36,7 @@ public static function dataProvider(): iterable
yield 'cache item is created' => ['non-cached-file', \null, new FileAttributes('destination')];
}

/**
/**
* @test
*/
public function cache_is_purged_after_unsuccessful_copy(): void
Expand Down
4 changes: 2 additions & 2 deletions tests/CreateDirectory_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class CreateDirectory_Test extends CacheTestCase
{
/**
/**
* @test
* @dataProvider dataProvider
*/
Expand All @@ -21,7 +21,7 @@ public function directory_is_cached_after_creating(string $path): void
}

/**
*
*
* @return iterable<array<mixed>>
*/
public static function dataProvider(): iterable
Expand Down
6 changes: 3 additions & 3 deletions tests/DeleteDirectory_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class DeleteDirectory_Test extends CacheTestCase
{
/**
/**
* @test
* @dataProvider dataProvider
*/
Expand All @@ -20,7 +20,7 @@ public function directory_is_not_cached_deleting(string $path): void
}

/**
*
*
* @return iterable<array<mixed>>
*/
public static function dataProvider(): iterable
Expand All @@ -41,7 +41,7 @@ public function nested_files_are_purged_from_cache(): void
]);
}

/**
/**
* @test
*/
public function cache_is_purged_after_unsuccessful_delete(): void
Expand Down
6 changes: 3 additions & 3 deletions tests/Delete_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Delete_Test extends CacheTestCase
{
/**
/**
* @test
* @dataProvider dataProvider
*/
Expand All @@ -20,7 +20,7 @@ public function file_is_not_cached_deleting(string $path): void
}

/**
*
*
* @return iterable<array<mixed>>
*/
public static function dataProvider(): iterable
Expand All @@ -29,7 +29,7 @@ public static function dataProvider(): iterable
yield 'non cached file stays uncached' => ['non-cached-file'];
}

/**
/**
* @test
*/
public function cache_is_purged_after_unsuccessful_delete(): void
Expand Down
6 changes: 3 additions & 3 deletions tests/DirectoryExists_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class DirectoryExists_Test extends CacheTestCase
{
/**
/**
* @test
* @dataProvider dataProvider
*/
Expand All @@ -18,7 +18,7 @@ public function directory_exists_ok(string $path, bool $expectedResult): void
}

/**
*
*
* @return iterable<array<mixed>>
*/
public static function dataProvider(): iterable
Expand All @@ -30,7 +30,7 @@ public static function dataProvider(): iterable
yield 'file is not a directory' => ['fully-cached-file', false];
}

/**
/**
* @test
*/
public function directory_is_cached_after_checking_filesystem(): void
Expand Down
12 changes: 6 additions & 6 deletions tests/GetChecksum_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function setUp(): void
]);
}

/**
/**
* @test
* @dataProvider dataProvider
*/
Expand All @@ -35,7 +35,7 @@ public function get_checksum(string $path, string $expectedChecksum): void
}

/**
*
*
* @return iterable<array<mixed>>
*/
public static function dataProvider(): iterable
Expand All @@ -45,7 +45,7 @@ public static function dataProvider(): iterable
yield 'file is not cached' => ['non-cached-file', md5('0123456789')];
}

/**
/**
* @test
* @dataProvider aws_dataProvider
*/
Expand All @@ -62,7 +62,7 @@ public function with_mock_aws_adapter(string $path, string $expectedChecksum): v
}

/**
*
*
* @return iterable<array<mixed>>
*/
public static function aws_dataProvider(): iterable
Expand All @@ -84,7 +84,7 @@ public function error(string $path): void
}

/**
*
*
* @return iterable<array<mixed>>
*/
public static function errorDataProvider(): iterable
Expand All @@ -94,7 +94,7 @@ public static function errorDataProvider(): iterable
yield 'Path is directory (non-cached)' => ['non-cached-directory'];
}

/**
/**
* @test
*/
public function cache_is_purged_after_unsuccessful_get(): void
Expand Down
8 changes: 4 additions & 4 deletions tests/GetFileSize_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class GetFileSize_Test extends CacheTestCase
{
/**
/**
* @test
* @dataProvider dataProvider
*/
Expand All @@ -18,7 +18,7 @@ public function get_fileSize(string $path, int $expectedFileSize): void
}

/**
*
*
* @return iterable<array<mixed>>
*/
public static function dataProvider(): iterable
Expand All @@ -41,7 +41,7 @@ public function error(string $path): void
}

/**
*
*
* @return iterable<array<mixed>>
*/
public static function errorDataProvider(): iterable
Expand All @@ -51,7 +51,7 @@ public static function errorDataProvider(): iterable
yield 'Path is directory (non-cached)' => ['non-cached-directory'];
}

/**
/**
* @test
*/
public function cache_is_purged_after_unsuccessful_get(): void
Expand Down
Loading
Loading