Skip to content

Commit fef2498

Browse files
authored
Merge pull request #7 from tattersoftware/entity
Entity
2 parents afb733d + 5dfb772 commit fef2498

File tree

10 files changed

+133
-57
lines changed

10 files changed

+133
-57
lines changed

.github/workflows/analyze.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
with:
4040
php-version: ${{ matrix.php-versions }}
4141
tools: composer, pecl, phpunit
42-
extensions: intl, json, mbstring, mysqlnd, xdebug, xml, sqlite3
42+
extensions: intl, json, mbstring, gd, mysqlnd, xdebug, xml, sqlite3
4343

4444
- name: Get composer cache directory
4545
id: composer-cache

.github/workflows/test.yml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
with:
3030
php-version: ${{ matrix.php-versions }}
3131
tools: composer, pecl, phpunit
32-
extensions: intl, json, mbstring, mysqlnd, xdebug, xml, sqlite3
32+
extensions: intl, json, mbstring, gd, mysqlnd, xdebug, xml, sqlite3
3333
coverage: xdebug
3434

3535
- name: Get composer cache directory
@@ -48,24 +48,35 @@ jobs:
4848
env:
4949
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
5050

51+
- name: Enable Tachycardia
52+
run: echo "TACHYCARDIA_MONITOR_GA=enabled" >> $GITHUB_ENV
53+
5154
- name: Test with PHPUnit
5255
run: vendor/bin/phpunit --verbose --coverage-text
56+
env:
57+
TERM: xterm-256color
5358

54-
- if: matrix.php-versions == '7.4'
55-
name: Run Coveralls
59+
- if: matrix.php-versions == '8.0'
60+
name: Mutate with Infection
5661
run: |
57-
composer global require php-coveralls/php-coveralls:^2.4
58-
php-coveralls --coverage_clover=build/logs/clover.xml -v
62+
composer global require infection/infection
63+
git fetch --depth=1 origin $GITHUB_BASE_REF
64+
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
65+
66+
- if: matrix.php-versions == '8.0'
67+
name: Run Coveralls
68+
run: vendor/bin/php-coveralls --verbose --coverage_clover=build/phpunit/clover.xml --json_path build/phpunit/coveralls-upload.json
5969
env:
6070
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6171
COVERALLS_PARALLEL: true
62-
COVERALLS_FLAG_NAME: PHP ${{ matrix.php-versions }} - ${{ matrix.db-platforms }}
72+
COVERALLS_FLAG_NAME: PHP ${{ matrix.php-versions }}
6373

6474
coveralls:
6575
needs: [main]
76+
name: Coveralls Finished
6677
runs-on: ubuntu-latest
6778
steps:
68-
- name: Coveralls Finished
79+
- name: Upload Coveralls results
6980
uses: coverallsapp/github-action@master
7081
with:
7182
github-token: ${{ secrets.GITHUB_TOKEN }}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"require-dev": {
2626
"codeigniter4/codeigniter4": "dev-develop",
27-
"tatter/tools": "^1.4"
27+
"tatter/tools": "^1.7"
2828
},
2929
"autoload": {
3030
"psr-4": {
@@ -49,6 +49,7 @@
4949
"prefer-stable": true,
5050
"scripts": {
5151
"analyze": "phpstan analyze",
52+
"mutate": "infection --threads=2 --skip-initial-tests --coverage=build/phpunit",
5253
"style": "phpcbf --standard=./vendor/codeigniter4/codeigniter4-standard/CodeIgniter4 tests/ src/",
5354
"test": "phpunit"
5455
}

infection.json.dist

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"source": {
3+
"directories": [
4+
"src"
5+
],
6+
"excludes": [
7+
"Config",
8+
"Database/Migrations",
9+
"Views"
10+
]
11+
},
12+
"logs": {
13+
"text": "build/infection.log"
14+
},
15+
"mutators": {
16+
"@default": true
17+
},
18+
"bootstrap": "vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php"
19+
}

phpunit.xml.dist

Lines changed: 62 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,76 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
4+
bootstrap="vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php"
35
backupGlobals="false"
6+
beStrictAboutCoversAnnotation="true"
7+
beStrictAboutOutputDuringTests="true"
8+
beStrictAboutTodoAnnotatedTests="true"
49
colors="true"
510
convertErrorsToExceptions="true"
611
convertNoticesToExceptions="true"
712
convertWarningsToExceptions="true"
8-
stopOnError="false"
13+
executionOrder="random"
14+
failOnRisky="true"
15+
failOnWarning="true"
16+
stopOnError="true"
917
stopOnFailure="false"
1018
stopOnIncomplete="false"
11-
stopOnSkipped="false">
19+
stopOnSkipped="false"
20+
verbose="true">
21+
22+
<coverage includeUncoveredFiles="true" processUncoveredFiles="true">
23+
<include>
24+
<directory suffix=".php">./src</directory>
25+
</include>
26+
<exclude>
27+
<directory suffix=".php">./src/Views</directory>
28+
<file>./src/Config/Routes.php</file>
29+
</exclude>
30+
<report>
31+
<clover outputFile="build/phpunit/clover.xml"/>
32+
<html outputDirectory="build/phpunit/html"/>
33+
<php outputFile="build/phpunit/coverage.serialized"/>
34+
<text outputFile="php://stdout" showUncoveredFiles="false"/>
35+
<xml outputDirectory="build/phpunit/xml-coverage"/>
36+
</report>
37+
</coverage>
38+
1239
<testsuites>
1340
<testsuite name="app">
1441
<directory>./tests</directory>
1542
</testsuite>
1643
</testsuites>
1744

18-
<filter>
19-
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="true">
20-
<directory suffix=".php">./src</directory>
21-
<exclude>
22-
<directory suffix=".php">./src/Views</directory>
23-
<file>./src/Config/Routes.php</file>
24-
</exclude>
25-
</whitelist>
26-
</filter>
45+
<extensions>
46+
<extension class="Nexus\PHPUnit\Extension\Tachycardia">
47+
<arguments>
48+
<array>
49+
<element key="timeLimit">
50+
<double>0.50</double>
51+
</element>
52+
<element key="reportable">
53+
<integer>30</integer>
54+
</element>
55+
<element key="precision">
56+
<integer>2</integer>
57+
</element>
58+
<element key="tabulate">
59+
<boolean>true</boolean>
60+
</element>
61+
</array>
62+
</arguments>
63+
</extension>
64+
</extensions>
2765

2866
<logging>
29-
<log type="coverage-html" target="build/logs/html"/>
30-
<log type="coverage-clover" target="build/logs/clover.xml"/>
31-
<log type="coverage-php" target="build/logs/coverage.serialized"/>
32-
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
33-
<log type="testdox-html" target="build/logs/testdox.html"/>
34-
<log type="testdox-text" target="build/logs/testdox.txt"/>
35-
<log type="junit" target="build/logs/logfile.xml"/>
67+
<testdoxHtml outputFile="build/phpunit/testdox.html"/>
68+
<testdoxText outputFile="build/phpunit/testdox.txt"/>
69+
<junit outputFile="build/phpunit/junit.xml"/>
3670
</logging>
3771

3872
<php>
73+
<env name="XDEBUG_MODE" value="coverage"/>
3974
<server name="app.baseURL" value="http://example.com"/>
4075

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

5388
<!-- Database configuration -->
54-
<!-- <env name="database.tests.hostname" value="localhost"/> -->
55-
<!-- <env name="database.tests.database" value="tests"/> -->
56-
<!-- <env name="database.tests.username" value="tests_user"/> -->
57-
<!-- <env name="database.tests.password" value=""/> -->
58-
<!-- <env name="database.tests.DBDriver" value="MySQLi"/> -->
59-
<!-- <env name="database.tests.DBPrefix" value="tests_"/> -->
60-
<env name="database.tests.database" value=":memory:"/>
61-
<env name="database.tests.DBDriver" value="SQLite3"/>
89+
<!-- Uncomment to use alternate testing database configuration
90+
<env name="database.tests.hostname" value="localhost"/>
91+
<env name="database.tests.database" value="tests"/>
92+
<env name="database.tests.username" value="tests_user"/>
93+
<env name="database.tests.password" value=""/>
94+
<env name="database.tests.DBDriver" value="MySQLi"/>
95+
<env name="database.tests.DBPrefix" value="tests_"/>
96+
-->
6297
</php>
6398
</phpunit>

src/Database/Migrations/20190404090152_create_table_audits.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ public function up()
88
{
99
// audit logs
1010
$fields = [
11-
'source' => ['type' => 'VARCHAR', 'constraint' => 63],
12-
'source_id' => ['type' => 'INT', 'unsigned' => true],
13-
'user_id' => ['type' => 'INT', 'unsigned' => true, 'null' => true],
14-
'event' => ['type' => 'VARCHAR', 'constraint' => 31],
15-
'summary' => ['type' => 'VARCHAR', 'constraint' => 255],
16-
'created_at' => ['type' => 'DATETIME', 'null' => true],
11+
'source' => ['type' => 'varchar', 'constraint' => 63],
12+
'source_id' => ['type' => 'int', 'unsigned' => true],
13+
'user_id' => ['type' => 'int', 'unsigned' => true, 'null' => true],
14+
'event' => ['type' => 'varchar', 'constraint' => 31],
15+
'summary' => ['type' => 'varchar', 'constraint' => 255],
16+
'created_at' => ['type' => 'datetime', 'null' => true],
1717
];
1818

1919
$this->forge->addField('id');

src/Entities/Audit.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php namespace Tatter\Audits\Entities;
2+
3+
use CodeIgniter\Entity;
4+
5+
class Audit extends Entity
6+
{
7+
protected $table = 'audits';
8+
protected $primaryKey = 'id';
9+
10+
protected $dates = ['created_at'];
11+
protected $casts = [
12+
'source_id' => 'int',
13+
'user_id' => 'int',
14+
];
15+
}

src/Models/AuditModel.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
<?php namespace Tatter\Audits\Models;
22

33
use CodeIgniter\Model;
4+
use Tatter\Audits\Entities\Audit;
45

56
class AuditModel extends Model
67
{
78
protected $table = 'audits';
89
protected $primaryKey = 'id';
10+
protected $returnType = Audit::class;
911

10-
protected $returnType = 'Tatter\Audits\Entities\Audit';
12+
protected $useTimestamps = false;
1113
protected $useSoftDeletes = false;
14+
protected $skipValidation = true;
1215

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

15-
protected $useTimestamps = false;
16-
17-
protected $validationRules = [];
18-
protected $validationMessages = [];
19-
protected $skipValidation = false;
2018
}

tests/_support/DatabaseTestCase.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
<?php namespace Tests\Support;
22

3-
use CodeIgniter\Test\CIDatabaseTestCase;
3+
use CodeIgniter\Test\CIUnitTestCase;
4+
use CodeIgniter\Test\DatabaseTestTrait;
45
use CodeIgniter\Test\Fabricator;
56
use Config\Services;
67
use Tatter\Audits\Audits;
78
use Tatter\Audits\Config\Audits as AuditsConfig;
89
use Tests\Support\Models\WidgetModel;
910

10-
class DatabaseTestCase extends CIDatabaseTestCase
11+
class DatabaseTestCase extends CIUnitTestCase
1112
{
13+
use DatabaseTestTrait;
14+
1215
/**
1316
* Should the database be refreshed before each test?
1417
*
@@ -41,7 +44,7 @@ public function setUp(): void
4144
{
4245
parent::setUp();
4346

44-
$config = new \Tatter\Audits\Config\Audits();
47+
$config = new AuditsConfig();
4548
$config->silent = false;
4649
$this->config = $config;
4750

tests/unit/TraitTest.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44

55
class TraitTest extends DatabaseTestCase
66
{
7-
public function setUp(): void
8-
{
9-
parent::setUp();
10-
11-
}
12-
137
public function testInsertAddsAudit()
148
{
159
$widget = $this->fabricator->make();

0 commit comments

Comments
 (0)