Skip to content

Commit

Permalink
Better JSON support (#450)
Browse files Browse the repository at this point in the history
* Updated PHPUnit config

* Adjusted `auditor` requirement

* Better viewer for changes inside JSON columns

* Tweak `phpdoc_to_comment` rule (PHP-CS-Fixer )

---------

Co-authored-by: Fabian Kropfhamer <[email protected]>
  • Loading branch information
DamienHarper and fkropfhamer authored Oct 24, 2024
1 parent 120fd50 commit bf8b9c3
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 55 deletions.
3 changes: 3 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
'phpdoc_to_param_type' => true,
'phpdoc_to_property_type' => true,
'phpdoc_to_return_type' => true,
'phpdoc_to_comment' => [
'ignored_tags' => ['todo', 'var']
],
'regular_callable_call' => true,
'simplified_if_return' => true,
'get_class_to_class_keyword' => true,
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"require": {
"php": ">=8.2",
"ext-intl": "*",
"damienharper/auditor": "^2.3|^3.0",
"damienharper/auditor": "^3.2",
"doctrine/doctrine-bundle": "^2.0",
"symfony/asset": "^5.4|^6.4|^7.0",
"symfony/doctrine-bridge": "^5.4|^6.4|^7.0",
Expand Down
50 changes: 25 additions & 25 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.3/phpunit.xsd" bootstrap="tests/bootstrap.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.4/phpunit.xsd" bootstrap="tests/bootstrap.php"
executionOrder="depends,defects" beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache"
requireCoverageMetadata="false" beStrictAboutCoverageMetadata="true">
<coverage includeUncoveredFiles="true">
<report>
<html outputDirectory="tests/coverage"/>
</report>
</coverage>
<logging/>
<php>
<ini name="error_reporting" value="-1"/>
<server name="KERNEL_CLASS" value="DH\AuditorBundle\Tests\App\Kernel"/>
<server name="APP_ENV" value="test" force="true"/>
<server name="SHELL_VERBOSITY" value="-1"/>
<!-- <server name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>-->
<env name="BOOTSTRAP_CLEAR_CACHE_ENV" value="test"/>
</php>
<testsuites>
<testsuite name="Auditor Bundle test suite">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
<coverage>
<report>
<html outputDirectory="tests/coverage"/>
</report>
</coverage>
<logging/>
<php>
<ini name="error_reporting" value="-1"/>
<server name="KERNEL_CLASS" value="DH\AuditorBundle\Tests\App\Kernel"/>
<server name="APP_ENV" value="test" force="true"/>
<server name="SHELL_VERBOSITY" value="-1"/>
<!-- <server name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>-->
<env name="BOOTSTRAP_CLEAR_CACHE_ENV" value="test"/>
</php>
<testsuites>
<testsuite name="Auditor Bundle test suite">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
44 changes: 15 additions & 29 deletions src/Resources/views/Audit/entry.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
{% import '@DHAuditor/Audit/helpers/helper.html.twig' as helper %}

{% macro displayDiffs(field, changeset) %}
{# {{ dump(field, changeset) }}#}
{% if changeset.old is defined or changeset.new is defined %}
{# NON JSON field changeset #}
{{ include('@DHAuditor/Audit/entry_diff.html.twig', {'key': field, 'values': changeset}) }}
{% else %}
{# JSON field changeset #}
{% for json_field, json_changeset in changeset %}
{{ _self.displayDiffs(field~'.'~json_field, json_changeset) }}
{% endfor %}
{% endif %}
{% endmacro %}

<div class="auditor-audit-history-entry relative pb-8">
{% if not is_last %}
<span class="absolute top-4 left-4 -ml-px h-full w-0.5 bg-gray-200" aria-hidden="true"></span>
Expand Down Expand Up @@ -46,34 +59,8 @@
</thead>
<tbody class="divide-y divide-gray-200">
{% set diffs = entry.getDiffs() %}
{% for key, values in diffs %}
<tr class="bg-white">
<td class="px-3 py-1 whitespace-nowrap text-sm font-medium text-gray-900">
<code class="text-gray-700">{{ key }}</code>
</td>
<td class="px-3 py-1 text-sm text-gray-500">
{% if values.old is defined %}
{% if values.old is null %}
<span class="bg-gray-500 px-2 py-0.5 rounded text-white">null</span>
{% else %}
<span class="text-red-500">{{ helper.dump(values.old) }}</span>
{% endif %}
{% endif %}
</td>
<td class="px-3 py-1 text-sm text-gray-500">
{% if values.new is defined %}
{% if values.new is null %}
<span class="bg-gray-500 px-2 py-0.5 rounded text-white">null</span>
{% else %}
{% if values.old is null %}
<span class="text-blue-500">{{ helper.dump(values.new) }}</span>
{% else %}
<span class="text-green-500">{{ helper.dump(values.new) }}</span>
{% endif %}
{% endif %}
{% endif %}
</td>
</tr>
{% for field, changeset in diffs %}
{{ _self.displayDiffs(field, changeset) }}
{% endfor %}
</tbody>
</table>
Expand All @@ -97,4 +84,3 @@
</div>
</div>
</div>

30 changes: 30 additions & 0 deletions src/Resources/views/Audit/entry_diff.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% import '@DHAuditor/Audit/helpers/helper.html.twig' as helper %}

<tr class="bg-white">
<td class="px-3 py-1 whitespace-nowrap text-sm font-medium text-gray-900">
{#{{ dump('entry_diff', key, values) }}#}
<code class="text-gray-700">{{ key }}</code>
</td>
<td class="px-3 py-1 text-sm text-gray-500">
{% if values.old is defined %}
{% if values.old is null %}
<span class="bg-gray-500 px-2 py-0.5 rounded text-white">null</span>
{% else %}
<span class="text-red-500">{{ helper.dump(values.old) }}</span>
{% endif %}
{% endif %}
</td>
<td class="px-3 py-1 text-sm text-gray-500">
{% if values.new is defined %}
{% if values.new is null %}
<span class="bg-gray-500 px-2 py-0.5 rounded text-white">null</span>
{% else %}
{% if values.old is not defined or values.old is null %}
<span class="text-blue-500">{{ helper.dump(values.new) }}</span>
{% else %}
<span class="text-green-500">{{ helper.dump(values.new) }}</span>
{% endif %}
{% endif %}
{% endif %}
</td>
</tr>

0 comments on commit bf8b9c3

Please sign in to comment.