Skip to content

Commit 0e8c206

Browse files
authored
Merge pull request #21 from tattersoftware/tools
PHP 8 + Toolkit
2 parents 9b5e6f6 + b8bc678 commit 0e8c206

File tree

7 files changed

+102
-46
lines changed

7 files changed

+102
-46
lines changed

.github/workflows/analyze.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
paths:
1010
- 'src/**'
1111
- 'tests/**'
12+
- 'composer.**'
1213
- 'phpstan*'
1314
- '.github/workflows/analyze.yml'
1415
push:
@@ -17,32 +18,41 @@ on:
1718
paths:
1819
- 'src/**'
1920
- 'tests/**'
21+
- 'composer.**'
2022
- 'phpstan*'
2123
- '.github/workflows/analyze.yml'
2224

2325
jobs:
2426
build:
25-
name: Analyze code
27+
name: PHP ${{ matrix.php-versions }} Static Analysis
2628
runs-on: ubuntu-latest
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
php-versions: ['7.3', '7.4', '8.0']
2733
steps:
2834
- name: Checkout
2935
uses: actions/checkout@v2
3036

3137
- name: Setup PHP
3238
uses: shivammathur/setup-php@v2
3339
with:
34-
php-version: '7.4'
35-
extensions: intl
40+
php-version: ${{ matrix.php-versions }}
41+
tools: composer, pecl, phpunit
42+
extensions: intl, json, mbstring, mysqlnd, xdebug, xml, sqlite3
3643

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

48+
- name: Create composer cache directory
49+
run: mkdir -p ${{ steps.composer-cache.outputs.dir }}
50+
4151
- name: Cache composer dependencies
4252
uses: actions/cache@v2
4353
with:
4454
path: ${{ steps.composer-cache.outputs.dir }}
45-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
55+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
4656
restore-keys: ${{ runner.os }}-composer-
4757

4858
- name: Create PHPStan cache directory
@@ -56,7 +66,7 @@ jobs:
5666
restore-keys: ${{ runner.os }}-phpstan-
5767

5868
- name: Install dependencies
59-
run: composer install --no-progress --no-suggest --no-interaction --prefer-dist --optimize-autoloader
69+
run: composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
6070
env:
6171
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
6272

.github/workflows/test.yml

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@ name: PHPUnit
22

33
on:
44
pull_request:
5-
branches:
5+
branches:
6+
- develop
7+
push:
8+
branches:
69
- develop
710

811
jobs:
912
main:
10-
name: Build and test
13+
name: PHP ${{ matrix.php-versions }} Unit Tests
1114

1215
strategy:
1316
matrix:
14-
php-versions: ['7.2', '7.3', '7.4']
17+
php-versions: ['7.3', '7.4', '8.0']
1518

1619
runs-on: ubuntu-latest
1720

@@ -41,9 +44,29 @@ jobs:
4144
restore-keys: ${{ runner.os }}-composer-
4245

4346
- name: Install dependencies
44-
run: composer install --no-progress --no-suggest --no-interaction --prefer-dist --optimize-autoloader
47+
run: composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
4548
env:
4649
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
4750

48-
- name: Test with phpunit
51+
- name: Test with PHPUnit
4952
run: vendor/bin/phpunit --verbose --coverage-text
53+
54+
- if: matrix.php-versions == '7.4'
55+
name: Run Coveralls
56+
run: |
57+
composer global require php-coveralls/php-coveralls:^2.4
58+
php-coveralls --coverage_clover=build/logs/clover.xml -v
59+
env:
60+
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
COVERALLS_PARALLEL: true
62+
COVERALLS_FLAG_NAME: PHP ${{ matrix.php-versions }} - ${{ matrix.db-platforms }}
63+
64+
coveralls:
65+
needs: [main]
66+
runs-on: ubuntu-latest
67+
steps:
68+
- name: Coveralls Finished
69+
uses: coverallsapp/github-action@master
70+
with:
71+
github-token: ${{ secrets.GITHUB_TOKEN }}
72+
parallel-finished: true

composer.json

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "tatter/assets",
3+
"type": "library",
34
"description": "Asset publishing and loading for CodeIgniter 4",
45
"keywords": [
56
"codeigniter",
@@ -19,42 +20,37 @@
1920
"role": "Developer"
2021
}
2122
],
22-
"repositories": [
23-
{
24-
"type": "vcs",
25-
"url": "https://github.com/codeigniter4/CodeIgniter4"
26-
}
27-
],
28-
"minimum-stability": "dev",
29-
"prefer-stable": true,
3023
"require": {
31-
"php" : ">=7.2"
24+
"php": "^7.3||^8.0"
3225
},
3326
"require-dev": {
3427
"codeigniter4/codeigniter4": "dev-develop",
35-
"fzaninotto/faker": "^1.9@dev",
36-
"mikey179/vfsstream": "^1.6",
37-
"phpunit/phpunit": "^8.5",
38-
"phpstan/phpstan": "^0.12",
39-
"squizlabs/php_codesniffer": "^3.5",
40-
"codeigniter4/codeigniter4-standard": "^1.0"
28+
"tatter/tools": "^1.4"
4129
},
4230
"autoload": {
4331
"psr-4": {
4432
"Tatter\\Assets\\": "src"
45-
}
33+
},
34+
"exclude-from-classmap": [
35+
"**/Database/Migrations/**"
36+
]
4637
},
4738
"autoload-dev": {
4839
"psr-4": {
4940
"Tests\\Support\\": "tests/_support"
5041
}
5142
},
43+
"repositories": [
44+
{
45+
"type": "vcs",
46+
"url": "https://github.com/codeigniter4/CodeIgniter4"
47+
}
48+
],
49+
"minimum-stability": "dev",
50+
"prefer-stable": true,
5251
"scripts": {
5352
"analyze": "phpstan analyze",
54-
"style": "phpcbf --standard=./vendor/codeigniter4/codeigniter4-standard/CodeIgniter4 src/ tests/",
55-
"test": "phpunit",
56-
"post-update-cmd": [
57-
"composer dump-autoload"
58-
]
53+
"style": "phpcbf --standard=./vendor/codeigniter4/codeigniter4-standard/CodeIgniter4 tests/ src/",
54+
"test": "phpunit"
5955
}
6056
}

src/Libraries/Assets.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use CodeIgniter\Config\Config;
2929
use CodeIgniter\Config\Services;
3030
use CodeIgniter\Router\RouteCollectionInterface;
31+
use Tatter\Assets\Config\Assets as AssetsConfig;
3132
use Tatter\Assets\Exceptions\AssetsException;
3233

3334
/*** CLASS ***/
@@ -36,14 +37,14 @@ class Assets
3637
/**
3738
* Our configuration instance.
3839
*
39-
* @var \Tatter\Assets\Config\Assets
40+
* @var AssetsConfig
4041
*/
4142
protected $config;
4243

4344
/**
4445
* Array of asset paths detected for the current route
4546
*
46-
* @var array
47+
* @var array|null
4748
*/
4849
protected $paths;
4950

@@ -61,7 +62,7 @@ class Assets
6162
* The URI to use for matching routed assets.
6263
* Defaults to uri_string()
6364
*
64-
* @var string
65+
* @var string|null
6566
*/
6667
protected $route;
6768

@@ -76,7 +77,7 @@ class Assets
7677
/**
7778
* Route collection used to determine the default route (if needed).
7879
*
79-
* @var CodeIgniter\Router\RouteCollectionInterface
80+
* @var RouteCollectionInterface|null
8081
*/
8182
protected $collection;
8283

@@ -147,7 +148,7 @@ public function getPaths($extension = null): array
147148
$tmpPaths = [];
148149
foreach ($this->paths as $path)
149150
{
150-
if (strtolower(pathinfo($path, PATHINFO_EXTENSION) == $extension))
151+
if (strtolower(pathinfo($path, PATHINFO_EXTENSION)) == $extension)
151152
{
152153
$tmpPaths[] = $path;
153154
}
@@ -197,16 +198,13 @@ public function tag(string $path)
197198
{
198199
case 'css':
199200
return link_tag($url);
200-
break;
201201

202202
case 'js':
203203
return script_tag($url);
204-
break;
205204

206205
case 'img':
207206
$alt = ucfirst(pathinfo($path, PATHINFO_FILENAME));
208207
return img($url, false, ['alt' => $alt]);
209-
break;
210208

211209
default:
212210
if ($this->config->silent)
@@ -281,7 +279,7 @@ protected function sanitizeRoute()
281279
if (Config::get('App')->negotiateLocale)
282280
{
283281
$route = explode('/', $this->route);
284-
if (count($route) && $route[0] == Services::request()->getLocale())
282+
if (count($route) && $route[0] == Services::request()->getLocale()) // @phpstan-ignore-line
285283
{
286284
unset($route[0]);
287285
}

src/Libraries/Manifests.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use CodeIgniter\Files\Exceptions\FileException;
55
use CodeIgniter\Files\Exceptions\FileNotFoundException;
66
use Tatter\Assets\Exceptions\ManifestsException;
7+
use stdClass;
78

89
class Manifests
910
{
@@ -294,7 +295,14 @@ public function expandPaths(&$resource, &$manifest)
294295
trim($resource->destination ?? '', '/') . '/';
295296
}
296297

297-
// Parse a resource and copy it to the determined destination
298+
/**
299+
* Parses a resource and copies it to
300+
* the determined destination.
301+
*
302+
* @param stdClass $resource
303+
*
304+
* @return bool
305+
*/
298306
protected function publishResource($resource): bool
299307
{
300308
// Validate the source
@@ -327,7 +335,15 @@ protected function publishResource($resource): bool
327335
return $this->publishFile($resource->source, $resource->destination);
328336
}
329337

330-
// Scan a directory and apply filters, publishing each file
338+
339+
/**
340+
* Scans a directory and applies filters,
341+
* publishing each file.
342+
*
343+
* @param stdClass $resource
344+
*
345+
* @return bool
346+
*/
331347
protected function publishResourceDirectory($resource): bool
332348
{
333349
$result = true;

tests/_support/ManifestsTestCase.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
<?php namespace Tests\Support;
22

33
use CodeIgniter\Test\CIUnitTestCase;
4+
use Tatter\Assets\Config\Assets as AssetsConfig;
45
use Tatter\Assets\Libraries\Manifests;
56
use org\bovigo\vfs\vfsStream;
7+
use org\bovigo\vfs\vfsStreamDirectory;
8+
use stdClass;
69

710
class ManifestsTestCase extends CIUnitTestCase
811
{
912
/**
10-
* @var \Tatter\Assets\Libraries\Manifests
13+
* @var vfsStreamDirectory|null
14+
*/
15+
protected $root;
16+
17+
/**
18+
* @var Manifests
1119
*/
1220
protected $manifests;
1321

1422
/**
15-
* @var \Tatter\Assets\Config\Assets
23+
* @var AssetsConfig
1624
*/
1725
protected $config;
1826

27+
/**
28+
* @var stdClass
29+
*/
30+
protected $testManifest;
31+
1932
public function setUp(): void
2033
{
2134
parent::setUp();

tests/manifests/PublishTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testExplicitFiles()
3434
];
3535

3636
$visitor = new vfsStreamStructureVisitor();
37-
$result = vfsStream::inspect($visitor, $this->root)->getStructure();
37+
$result = vfsStream::inspect($visitor, $this->root)->getStructure(); // @phpstan-ignore-line
3838

3939
$this->assertEquals($expected, $result);
4040
}
@@ -48,7 +48,7 @@ public function testRecursiveFlatten()
4848
$this->assertTrue($result);
4949

5050
$visitor = new vfsStreamStructureVisitor();
51-
$result = vfsStream::inspect($visitor, $this->root)->getStructure();
51+
$result = vfsStream::inspect($visitor, $this->root)->getStructure(); // @phpstan-ignore-line
5252

5353
$this->assertTrue($this->root->hasChild('assets/vendor/frontend/frontend.css'));
5454
$this->assertTrue($this->root->hasChild('assets/vendor/frontend/frontend.js'));

0 commit comments

Comments
 (0)