Skip to content

Commit

Permalink
Merge 5dfb772 into afb733d
Browse files Browse the repository at this point in the history
  • Loading branch information
MGatner committed Apr 8, 2021
2 parents afb733d + 5dfb772 commit b4aea12
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
with:
php-version: ${{ matrix.php-versions }}
tools: composer, pecl, phpunit
extensions: intl, json, mbstring, mysqlnd, xdebug, xml, sqlite3
extensions: intl, json, mbstring, gd, mysqlnd, xdebug, xml, sqlite3

- name: Get composer cache directory
id: composer-cache
Expand Down
25 changes: 18 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
with:
php-version: ${{ matrix.php-versions }}
tools: composer, pecl, phpunit
extensions: intl, json, mbstring, mysqlnd, xdebug, xml, sqlite3
extensions: intl, json, mbstring, gd, mysqlnd, xdebug, xml, sqlite3
coverage: xdebug

- name: Get composer cache directory
Expand All @@ -48,24 +48,35 @@ jobs:
env:
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}

- name: Enable Tachycardia
run: echo "TACHYCARDIA_MONITOR_GA=enabled" >> $GITHUB_ENV

- name: Test with PHPUnit
run: vendor/bin/phpunit --verbose --coverage-text
env:
TERM: xterm-256color

- if: matrix.php-versions == '7.4'
name: Run Coveralls
- if: matrix.php-versions == '8.0'
name: Mutate with Infection
run: |
composer global require php-coveralls/php-coveralls:^2.4
php-coveralls --coverage_clover=build/logs/clover.xml -v
composer global require infection/infection
git fetch --depth=1 origin $GITHUB_BASE_REF
infection --threads=2 --skip-initial-tests --coverage=build/phpunit --git-diff-base=origin/$GITHUB_BASE_REF --git-diff-filter=AM --logger-github --ignore-msi-with-no-mutations
- if: matrix.php-versions == '8.0'
name: Run Coveralls
run: vendor/bin/php-coveralls --verbose --coverage_clover=build/phpunit/clover.xml --json_path build/phpunit/coveralls-upload.json
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: PHP ${{ matrix.php-versions }} - ${{ matrix.db-platforms }}
COVERALLS_FLAG_NAME: PHP ${{ matrix.php-versions }}

coveralls:
needs: [main]
name: Coveralls Finished
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
- name: Upload Coveralls results
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"require-dev": {
"codeigniter4/codeigniter4": "dev-develop",
"tatter/tools": "^1.4"
"tatter/tools": "^1.7"
},
"autoload": {
"psr-4": {
Expand All @@ -49,6 +49,7 @@
"prefer-stable": true,
"scripts": {
"analyze": "phpstan analyze",
"mutate": "infection --threads=2 --skip-initial-tests --coverage=build/phpunit",
"style": "phpcbf --standard=./vendor/codeigniter4/codeigniter4-standard/CodeIgniter4 tests/ src/",
"test": "phpunit"
}
Expand Down
19 changes: 19 additions & 0 deletions infection.json.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"source": {
"directories": [
"src"
],
"excludes": [
"Config",
"Database/Migrations",
"Views"
]
},
"logs": {
"text": "build/infection.log"
},
"mutators": {
"@default": true
},
"bootstrap": "vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php"
}
89 changes: 62 additions & 27 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,41 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php"
backupGlobals="false"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnError="false"
executionOrder="random"
failOnRisky="true"
failOnWarning="true"
stopOnError="true"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false">
stopOnSkipped="false"
verbose="true">

<coverage includeUncoveredFiles="true" processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<directory suffix=".php">./src/Views</directory>
<file>./src/Config/Routes.php</file>
</exclude>
<report>
<clover outputFile="build/phpunit/clover.xml"/>
<html outputDirectory="build/phpunit/html"/>
<php outputFile="build/phpunit/coverage.serialized"/>
<text outputFile="php://stdout" showUncoveredFiles="false"/>
<xml outputDirectory="build/phpunit/xml-coverage"/>
</report>
</coverage>

<testsuites>
<testsuite name="app">
<directory>./tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
<exclude>
<directory suffix=".php">./src/Views</directory>
<file>./src/Config/Routes.php</file>
</exclude>
</whitelist>
</filter>
<extensions>
<extension class="Nexus\PHPUnit\Extension\Tachycardia">
<arguments>
<array>
<element key="timeLimit">
<double>0.50</double>
</element>
<element key="reportable">
<integer>30</integer>
</element>
<element key="precision">
<integer>2</integer>
</element>
<element key="tabulate">
<boolean>true</boolean>
</element>
</array>
</arguments>
</extension>
</extensions>

<logging>
<log type="coverage-html" target="build/logs/html"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="coverage-php" target="build/logs/coverage.serialized"/>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
<log type="testdox-html" target="build/logs/testdox.html"/>
<log type="testdox-text" target="build/logs/testdox.txt"/>
<log type="junit" target="build/logs/logfile.xml"/>
<testdoxHtml outputFile="build/phpunit/testdox.html"/>
<testdoxText outputFile="build/phpunit/testdox.txt"/>
<junit outputFile="build/phpunit/junit.xml"/>
</logging>

<php>
<env name="XDEBUG_MODE" value="coverage"/>
<server name="app.baseURL" value="http://example.com"/>

<!-- Directory containing phpunit.xml -->
Expand All @@ -51,13 +86,13 @@
<env name="COMPOSER_DISABLE_XDEBUG_WARN" value="1"/>

<!-- Database configuration -->
<!-- <env name="database.tests.hostname" value="localhost"/> -->
<!-- <env name="database.tests.database" value="tests"/> -->
<!-- <env name="database.tests.username" value="tests_user"/> -->
<!-- <env name="database.tests.password" value=""/> -->
<!-- <env name="database.tests.DBDriver" value="MySQLi"/> -->
<!-- <env name="database.tests.DBPrefix" value="tests_"/> -->
<env name="database.tests.database" value=":memory:"/>
<env name="database.tests.DBDriver" value="SQLite3"/>
<!-- Uncomment to use alternate testing database configuration
<env name="database.tests.hostname" value="localhost"/>
<env name="database.tests.database" value="tests"/>
<env name="database.tests.username" value="tests_user"/>
<env name="database.tests.password" value=""/>
<env name="database.tests.DBDriver" value="MySQLi"/>
<env name="database.tests.DBPrefix" value="tests_"/>
-->
</php>
</phpunit>
12 changes: 6 additions & 6 deletions src/Database/Migrations/20190404090152_create_table_audits.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ public function up()
{
// audit logs
$fields = [
'source' => ['type' => 'VARCHAR', 'constraint' => 63],
'source_id' => ['type' => 'INT', 'unsigned' => true],
'user_id' => ['type' => 'INT', 'unsigned' => true, 'null' => true],
'event' => ['type' => 'VARCHAR', 'constraint' => 31],
'summary' => ['type' => 'VARCHAR', 'constraint' => 255],
'created_at' => ['type' => 'DATETIME', 'null' => true],
'source' => ['type' => 'varchar', 'constraint' => 63],
'source_id' => ['type' => 'int', 'unsigned' => true],
'user_id' => ['type' => 'int', 'unsigned' => true, 'null' => true],
'event' => ['type' => 'varchar', 'constraint' => 31],
'summary' => ['type' => 'varchar', 'constraint' => 255],
'created_at' => ['type' => 'datetime', 'null' => true],
];

$this->forge->addField('id');
Expand Down
15 changes: 15 additions & 0 deletions src/Entities/Audit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php namespace Tatter\Audits\Entities;

use CodeIgniter\Entity;

class Audit extends Entity
{
protected $table = 'audits';
protected $primaryKey = 'id';

protected $dates = ['created_at'];
protected $casts = [
'source_id' => 'int',
'user_id' => 'int',
];
}
10 changes: 4 additions & 6 deletions src/Models/AuditModel.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
<?php namespace Tatter\Audits\Models;

use CodeIgniter\Model;
use Tatter\Audits\Entities\Audit;

class AuditModel extends Model
{
protected $table = 'audits';
protected $primaryKey = 'id';
protected $returnType = Audit::class;

protected $returnType = 'Tatter\Audits\Entities\Audit';
protected $useTimestamps = false;
protected $useSoftDeletes = false;
protected $skipValidation = true;

protected $allowedFields = ['source', 'source_id', 'user_id', 'event', 'summary', 'created_at'];

protected $useTimestamps = false;

protected $validationRules = [];
protected $validationMessages = [];
protected $skipValidation = false;
}
9 changes: 6 additions & 3 deletions tests/_support/DatabaseTestCase.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<?php namespace Tests\Support;

use CodeIgniter\Test\CIDatabaseTestCase;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\DatabaseTestTrait;
use CodeIgniter\Test\Fabricator;
use Config\Services;
use Tatter\Audits\Audits;
use Tatter\Audits\Config\Audits as AuditsConfig;
use Tests\Support\Models\WidgetModel;

class DatabaseTestCase extends CIDatabaseTestCase
class DatabaseTestCase extends CIUnitTestCase
{
use DatabaseTestTrait;

/**
* Should the database be refreshed before each test?
*
Expand Down Expand Up @@ -41,7 +44,7 @@ public function setUp(): void
{
parent::setUp();

$config = new \Tatter\Audits\Config\Audits();
$config = new AuditsConfig();
$config->silent = false;
$this->config = $config;

Expand Down
6 changes: 0 additions & 6 deletions tests/unit/TraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@

class TraitTest extends DatabaseTestCase
{
public function setUp(): void
{
parent::setUp();

}

public function testInsertAddsAudit()
{
$widget = $this->fabricator->make();
Expand Down

0 comments on commit b4aea12

Please sign in to comment.