Skip to content

Commit 6586378

Browse files
authored
Merge pull request #12 from tattersoftware/tests-refector
Tests refactor
2 parents 6b561ef + d696bbc commit 6586378

File tree

24 files changed

+155
-104
lines changed

24 files changed

+155
-104
lines changed

.github/workflows/test.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: PHPUnit
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- develop
7+
8+
jobs:
9+
main:
10+
name: Build and test
11+
12+
strategy:
13+
matrix:
14+
php-versions: ['7.2', '7.3', '7.4']
15+
16+
runs-on: ubuntu-latest
17+
18+
if: "!contains(github.event.head_commit.message, '[ci skip]')"
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v2
23+
24+
- name: Setup PHP, with composer and extensions
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: ${{ matrix.php-versions }}
28+
tools: composer, pecl, phpunit
29+
extensions: intl, json, mbstring, mysqlnd, xdebug, xml, sqlite3
30+
coverage: xdebug
31+
32+
- name: Get composer cache directory
33+
id: composer-cache
34+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
35+
36+
- name: Cache composer dependencies
37+
uses: actions/cache@v1
38+
with:
39+
path: ${{ steps.composer-cache.outputs.dir }}
40+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
41+
restore-keys: ${{ runner.os }}-composer-
42+
43+
- name: Install dependencies
44+
run: composer install --no-progress --no-suggest --no-interaction --prefer-dist --optimize-autoloader
45+
env:
46+
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
47+
48+
- name: Test with phpunit
49+
run: vendor/bin/phpunit --coverage-text

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
vendor/
1+
/vendor/
22
build/
33
phpunit*.xml
44
phpunit
5+
*.cache
56
composer.lock
67
.DS_Store

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Tatter\Assets
2+
23
Lightweight asset loader for CodeIgniter 4
34

5+
[![](https://github.com/tattersoftware/codeigniter4-assets/workflows/PHPUnit/badge.svg)](https://github.com/tattersoftware/codeigniter4-assets/actions?query=workflow%3A%22PHPUnit)
6+
47
## Quick Start
58

69
1. Install with Composer: `> composer require tatter/assets`

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626
}
2727
],
2828
"minimum-stability": "dev",
29+
"prefer-stable": true,
2930
"require": {
3031
"php" : ">=7.2"
3132
},
3233
"require-dev": {
3334
"codeigniter4/codeigniter4": "dev-develop",
35+
"fzaninotto/faker": "^1.9@dev",
3436
"mikey179/vfsstream": "1.6.*",
35-
"mockery/mockery": "^1.0",
36-
"phpunit/phpunit" : "^7.0"
37+
"phpunit/phpunit" : "^8.5"
3738
},
3839
"autoload": {
3940
"psr-4": {
@@ -42,7 +43,7 @@
4243
},
4344
"autoload-dev": {
4445
"psr-4": {
45-
"ModuleTests\\Support\\": "tests/_support"
46+
"Tests\\Support\\": "tests/_support"
4647
}
4748
},
4849
"scripts": {

phpunit.xml.dist

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="tests/_support/bootstrap.php"
3-
backupGlobals="false"
4-
colors="true"
5-
convertErrorsToExceptions="true"
6-
convertNoticesToExceptions="true"
7-
convertWarningsToExceptions="true"
8-
stopOnError="false"
9-
stopOnFailure="false"
10-
stopOnIncomplete="false"
11-
stopOnSkipped="false">
2+
<phpunit bootstrap="vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php"
3+
backupGlobals="false"
4+
colors="true"
5+
convertErrorsToExceptions="true"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true"
8+
stopOnError="false"
9+
stopOnFailure="false"
10+
stopOnIncomplete="false"
11+
stopOnSkipped="false">
1212
<testsuites>
13-
<testsuite name="all">
13+
<testsuite name="app">
1414
<directory>./tests</directory>
1515
</testsuite>
1616
</testsuites>
@@ -24,7 +24,7 @@
2424
</exclude>
2525
</whitelist>
2626
</filter>
27-
27+
2828
<logging>
2929
<log type="coverage-html" target="build/logs/html"/>
3030
<log type="coverage-clover" target="build/logs/clover.xml"/>
@@ -36,8 +36,21 @@
3636
</logging>
3737

3838
<php>
39-
<env name="app.baseURL" value="http://example.com"/>
40-
<env name="CI_ENVIRONMENT" value="testing"/>
39+
<server name="app.baseURL" value="http://example.com"/>
40+
41+
<!-- Directory containing phpunit.xml -->
42+
<const name="HOMEPATH" value="./"/>
43+
44+
<!-- Directory containing the Paths config file -->
45+
<const name="CONFIGPATH" value="./vendor/codeigniter4/codeigniter4/app/Config/"/>
46+
47+
<!-- Directory containing the front controller (index.php) -->
48+
<const name="PUBLICPATH" value="./vendor/codeigniter4/codeigniter4/public/"/>
49+
50+
<!-- https://getcomposer.org/xdebug -->
51+
<env name="COMPOSER_DISABLE_XDEBUG_WARN" value="1"/>
52+
53+
<!-- Database configuration -->
4154
<!-- <env name="database.tests.hostname" value="localhost"/> -->
4255
<!-- <env name="database.tests.database" value="tests"/> -->
4356
<!-- <env name="database.tests.username" value="tests_user"/> -->

src/Handlers/ConfigHandler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use CodeIgniter\Config\BaseConfig;
44
use Config\Services;
5+
use Tatter\Assets\Exceptions\AssetsException;
56
use Tatter\Assets\Handlers\DirectoryHandler;
67
use Tatter\Assets\Interfaces\AssetHandlerInterface;
78

tests/_support/AssetsTestCase.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
<?php namespace ModuleTests\Support;
1+
<?php namespace Tests\Support;
22

3-
class AssetsTestCase extends \CodeIgniter\Test\CIUnitTestCase
3+
use CodeIgniter\Test\CIUnitTestCase;
4+
use Tatter\Assets\Libraries\Assets;
5+
6+
class AssetsTestCase extends CIUnitTestCase
47
{
58
/**
69
* @var \Tatter\Assets\Libraries\Assets
@@ -16,11 +19,11 @@ public function setUp(): void
1619
{
1720
parent::setUp();
1821

19-
$this->config = new \Tatter\Assets\Config\Assets;
22+
$this->config = new \Tatter\Assets\Config\Assets();
2023
$this->config->silent = false;
21-
$this->config->fileBase = MODULESUPPORTPATH . 'assets/';
24+
$this->config->fileBase = SUPPORTPATH . 'assets/';
2225

2326
// Create the service
24-
$this->assets = new \Tatter\Assets\Libraries\Assets($this->config);
27+
$this->assets = new Assets($this->config);
2528
}
2629
}

tests/_support/ManifestsTestCase.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
<?php namespace ModuleTests\Support;
1+
<?php namespace Tests\Support;
22

3+
use CodeIgniter\Test\CIUnitTestCase;
4+
use Tatter\Assets\Libraries\Manifests;
35
use org\bovigo\vfs\vfsStream;
46

5-
class ManifestsTestCase extends \CodeIgniter\Test\CIUnitTestCase
7+
class ManifestsTestCase extends CIUnitTestCase
68
{
79
/**
810
* @var \Tatter\Assets\Libraries\Manifests
@@ -21,13 +23,13 @@ public function setUp(): void
2123
// Start the virtual filesystem
2224
$this->root = vfsStream::setup();
2325

24-
$this->config = new \Tatter\Assets\Config\Assets;
26+
$this->config = new \Tatter\Assets\Config\Assets();
2527
$this->config->silent = false;
2628
$this->config->fileBase = $this->root->url() . '/assets/';
27-
$this->config->publishBase = MODULESUPPORTPATH;
29+
$this->config->publishBase = SUPPORTPATH;
2830

2931
// Create the service
30-
$this->manifests = new \Tatter\Assets\Libraries\Manifests($this->config);
32+
$this->manifests = new Manifests($this->config);
3133

3234
// Create an example manifest (equivalent to Widgets.json)
3335
$this->testManifest = (object)[

tests/_support/assets/vendor/widget/colorful.css

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
backgorund-color: black;
3+
}

0 commit comments

Comments
 (0)