Skip to content

Commit

Permalink
Topic 112 (#328)
Browse files Browse the repository at this point in the history
* Topic 112

* cs-fixer

* disable get_class_to_class_keyword

* Fix tests

Co-authored-by: a.dmitryuk <[email protected]>
  • Loading branch information
dmitryuk and a.dmitryuk authored Oct 31, 2022
1 parent 6e08cd7 commit 90cc5ad
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci-5.x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ jobs:
if: matrix.symfony == '5.*'
run: SYMFONY_REQUIRE="^5.4" composer update --no-progress --ansi --prefer-stable

- name: Install auditor from source
run: composer reinstall damienharper/auditor --prefer-install=source

- name: Install PHPStan
run: composer install --no-progress --ansi --working-dir=tools/phpstan

Expand Down Expand Up @@ -153,6 +156,9 @@ jobs:
if: matrix.symfony == '6.*'
run: SYMFONY_REQUIRE="^6.0" composer update --no-progress --ansi --prefer-stable

- name: Install auditor from source
run: composer reinstall damienharper/auditor --prefer-install=source

- name: Install PHPStan
run: composer install --no-progress --ansi --working-dir=tools/phpstan

Expand Down
1 change: 1 addition & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
'simplified_if_return' => true,
'simplified_null_return' => false,
'static_lambda' => true,
'get_class_to_class_keyword' => false,
])
->setFinder(PhpCsFixer\Finder::create()
->in(__DIR__)
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"symfony/framework-bundle": "^4.4|^5.0|^6.0",
"symfony/var-dumper": "^4.0|^5.0|^6.0",
"symfony/webpack-encore-bundle": "^1.12",
"twig/extensions": "^1.5"
"twig/extensions": "^1.5",
"doctrine/data-fixtures": "^1.4"
},
"conflict": {
"doctrine/persistence": "<1.3"
Expand Down
5 changes: 3 additions & 2 deletions src/Resources/views/Audit/helpers/helper.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@
{% set target_subject = '' %}
{% set target_label = '' %}
{% if target is defined and target is not null %}
{% set target_subject = target.class ~ '#' ~ target.id %}
{% set target_link = path('dh_auditor_show_entity_history', { 'entity': helper.namespaceToParam(target.class), 'id': target.id }) %}
{% set target_id = target.pkName is defined ? target[target.pkName] : target.id %}
{% set target_subject = target.class ~ '#' ~ target_id %}
{% set target_link = path('dh_auditor_show_entity_history', { 'entity': helper.namespaceToParam(target.class), 'id': target_id }) %}
{% if target_subject != target.label %}
{% set target_label = '(' ~ helper.dump(target)|trim ~ ')' %}
{% endif %}
Expand Down
76 changes: 76 additions & 0 deletions tests/Twig/Views/MacrosTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

declare(strict_types=1);

namespace DH\AuditorBundle\Tests\Twig\Views;

use DH\Auditor\Model\Entry;
use DH\Auditor\Provider\Doctrine\Auditing\Transaction\AuditTrait;
use DH\Auditor\Tests\Provider\Doctrine\Fixtures\Issue112\DummyEntity;
use DH\Auditor\Tests\Provider\Doctrine\Traits\Schema\SchemaSetupTrait;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Twig\Environment;
use Twig\Extension\StringLoaderExtension;

/**
* @internal
*
* @small
*/
final class MacrosTest extends KernelTestCase
{
use AuditTrait;
use SchemaSetupTrait;

public function testSummarizeOnTargetWithUnusualPK(): void
{
self::bootKernel();
$container = method_exists(self::class, 'getContainer') ? self::getContainer() : self::$container;
$twig = $container->get('twig');
if (!$twig instanceof Environment) {
self::markTestIncomplete('Twig missing');
}
$twig->addExtension(new StringLoaderExtension());
$em = $this->createEntityManager([
__DIR__.'/../../../vendor/damienharper/auditor/tests/Provider/Doctrine/Fixtures/Issue112',
]);
$entity = new DummyEntity();
$entity->setPrimaryKey(1);
$entry = Entry::fromArray([
'diffs' => json_encode([
'source' => [
'label' => 'Example1',
],
'target' => $this->summarize($em, $entity),
]),
'type' => 'associate',
'object_id' => '2',
]);

$template = twig_template_from_string($twig, $this->getTemplateAsString());
$response = $template->render([
'entry' => $entry,
'entity' => \get_class($entity),
]);
self::assertSame($this->getExpected(), trim($response));
}

private function getTemplateAsString(): string
{
return <<<'TWIG'
{% import '@DHAuditor/Audit/helpers/helper.html.twig' as helper %}
{{ helper.summarize(entity, entry) }}
TWIG;
}

private function getExpected(): string
{
return <<<'EXPECTED'
<code class="text-pink-500">
<a href="/audit/DH-Auditor-Tests-Provider-Doctrine-Fixtures-Issue112-DummyEntity/2" class="code">DH\Auditor\Tests\Provider\Doctrine\Fixtures\Issue112\DummyEntity#2</a>
</code> <em>(Example1)</em> has been <b>associated</b> to <code class="text-pink-500">
<a href="/audit/DH-Auditor-Tests-Provider-Doctrine-Fixtures-Issue112-DummyEntity/1" class="code">DH\Auditor\Tests\Provider\Doctrine\Fixtures\Issue112\DummyEntity#1</a>
</code> <em></em> by <b>an anonymous user</b>
EXPECTED;
}
}

0 comments on commit 90cc5ad

Please sign in to comment.