Skip to content

Commit

Permalink
Merge pull request #2 from Fundacion-Cibervoluntarios/main
Browse files Browse the repository at this point in the history
Removing unsupported versions of PHP and Symfony
  • Loading branch information
cristoforocervino committed Jul 28, 2023
2 parents db9f6ce + 1aa73b9 commit ebebe80
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 95 deletions.
21 changes: 5 additions & 16 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,16 @@ jobs:
strategy:
matrix:
name:
- 'PHP 7.4 tests (Symfony 4.4)'
- 'PHP 7.4 tests (Symfony 5.1)'
- 'PHP 8.0 tests (Symfony 5.2)'
- 'PHP 8.0 tests (Symfony 5.3)'
- 'PHP 8.0 tests (Symfony 5.4)'
- 'PHP 8.0 tests (Symfony 6.0)'
- 'PHP 8.1 tests (Symfony 6.2)'
- 'PHP 8.1 tests (Symfony 6.3)'
include:
- php: '7.4'
symfony: 4.4.*
- php: '7.4'
symfony: 5.1.*
- php: '8.0'
symfony: 5.2.*
- php: '8.0'
symfony: 5.3.*
- php: '8.0'
symfony: 5.4.*
- php: '8.0'
symfony: 6.0.*
- php: '8.1'
symfony: 6.0.*
symfony: 6.2.*
- php: '8.1'
symfony: 6.3.*
name: ${{ matrix.name }}
steps:
- name: Checkout
Expand Down
13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"doctrine-orm",
"timestampable",
"php",
"php7",
"php74"
"php8"
],
"type": "symfony-bundle",
"license": "MIT",
Expand All @@ -28,17 +27,17 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"symfony/framework-bundle": "^4.4 | ^5.0 | ^6.0",
"php": "^8.0",
"symfony/framework-bundle": "^5.0 | ^6.0",
"doctrine/common": "^2.13 || ^3.0",
"doctrine/event-manager": "^1.0"
"doctrine/event-manager": "^1.2 | ^2.0"
},
"require-dev": {
"ext-json": "*",
"roave/security-advisories": "dev-master",
"doctrine/orm": "^2.6.3",
"doctrine/orm": "^2.15.3",
"phpunit/phpunit": "^9.5",
"doctrine/doctrine-bundle": "^2.2",
"doctrine/doctrine-bundle": "^2.10",
"symfony/yaml": "^4.4 | ^5.0 | ^6.0",
"phpstan/phpstan": "^1.2",
"phpstan/phpstan-phpunit": "^1.0",
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('andante_timestampable');

//@formatter:off
// @formatter:off
/** @var ArrayNodeDefinition $node */
$node = $treeBuilder->getRootNode();
$node->children()
Expand Down Expand Up @@ -63,7 +63,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->end()
->end()
->end();
//@formatter:on
// @formatter:on

return $treeBuilder;
}
Expand Down
9 changes: 4 additions & 5 deletions src/EventSubscriber/TimestampableEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
use Andante\TimestampableBundle\Config\Configuration;
use Andante\TimestampableBundle\Timestampable\CreatedAtTimestampableInterface;
use Andante\TimestampableBundle\Timestampable\UpdatedAtTimestampableInterface;
use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
use Doctrine\Common\EventSubscriber;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Events;
use Doctrine\Persistence\Event\LifecycleEventArgs;

class TimestampableEventSubscriber implements EventSubscriber, EventSubscriberInterface
class TimestampableEventSubscriber implements EventSubscriber
{
private Configuration $configuration;

Expand All @@ -34,15 +33,15 @@ public function getSubscribedEvents(): array

public function prePersist(LifecycleEventArgs $onFlushEventArgs): void
{
$entity = $onFlushEventArgs->getEntity();
$entity = $onFlushEventArgs->getObject();
if ($entity instanceof CreatedAtTimestampableInterface && null === $entity->getCreatedAt()) {
$entity->setCreatedAt(new \DateTimeImmutable());
}
}

public function preUpdate(LifecycleEventArgs $onFlushEventArgs): void
{
$entity = $onFlushEventArgs->getEntity();
$entity = $onFlushEventArgs->getObject();
if ($entity instanceof UpdatedAtTimestampableInterface) {
$entity->setUpdatedAt(new \DateTimeImmutable());
}
Expand Down
16 changes: 5 additions & 11 deletions tests/Fixtures/Entity/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,15 @@
use Andante\TimestampableBundle\Timestampable\TimestampableInterface;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity()
*/
#[ORM\Entity]
class Address implements TimestampableInterface
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;

/**
* @ORM\Column(type="string", nullable=true)
*/
#[ORM\Column(type: 'string')]
private ?string $name = null;

private ?\DateTimeImmutable $created = null;
Expand Down
16 changes: 5 additions & 11 deletions tests/Fixtures/Entity/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,17 @@
use Andante\TimestampableBundle\Timestampable\TimestampableTrait;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity()
*/
#[ORM\Entity]
class Organization implements TimestampableInterface
{
use TimestampableTrait;

/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;

/**
* @ORM\Column(type="string", nullable=true)
*/
#[ORM\Column(type: 'string')]
private ?string $name = null;

public function getId(): ?int
Expand Down
31 changes: 11 additions & 20 deletions tests/Functional/SetupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Andante\TimestampableBundle\Tests\Functional;

use Andante\TimestampableBundle\DependencyInjection\Compiler\DoctrineEventSubscriberPass;
use Andante\TimestampableBundle\EventSubscriber\TimestampableEventSubscriber;
use Andante\TimestampableBundle\Tests\HttpKernel\AndanteTimestampableKernel;
use Andante\TimestampableBundle\Tests\KernelTestCase;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Events;
use Doctrine\Persistence\ManagerRegistry;

class SetupTest extends KernelTestCase
Expand All @@ -35,26 +35,17 @@ public function testSubscriberSetup(): void
/** @var EntityManagerInterface $em */
foreach ($managerRegistry->getManagers() as $em) {
$evm = $em->getEventManager();
$r = new \ReflectionProperty($evm, 'subscribers');
$r->setAccessible(true);
$subscribers = $r->getValue($evm);
$serviceIdRegistered = \in_array(
DoctrineEventSubscriberPass::TIMESTAMPABLE_SUBSCRIBER_SERVICE_ID,
$subscribers,
true
);
$serviceRegistered = \array_reduce($subscribers, static fn (
bool $carry,
$service
) => $carry ? $carry : $service instanceof TimestampableEventSubscriber, false);
/** @var array<object> $listeners */
$listeners = $evm->getListeners()['loadClassMetadata'] ?? [];
$listenerRegistered = \array_reduce($listeners, static fn (
bool $carry,
$service
) => $carry ? $carry : $service instanceof TimestampableEventSubscriber, false);

self::assertTrue($serviceIdRegistered || $serviceRegistered || $listenerRegistered);
$allListeners = $evm->getAllListeners();
foreach ($allListeners as $name => $listeners) {
if (\in_array($name, [Events::prePersist, Events::preUpdate, Events::loadClassMetadata])) {
$listenerRegistered = \array_reduce($listeners, static fn (
bool $carry, $service
) => $carry ? $carry : $service instanceof TimestampableEventSubscriber, false);

self::assertTrue($listenerRegistered);
}
}
}
}
}
4 changes: 2 additions & 2 deletions tests/Functional/TimestampableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testShouldSetTimestamps(): void

\sleep(2);
$em->flush();
\sleep(2); //Giving time to mysqlite to update file
\sleep(2); // Giving time to mysqlite to update file

/** @var Address|null $address1 */
$address1 = $addressRepository->findOneBy(['name' => 'Address1-updated']);
Expand Down Expand Up @@ -101,7 +101,7 @@ public function testShouldSetTimestamps(): void

\sleep(2);
$em->flush();
\sleep(2); //Giving time to mysqlite to update file
\sleep(2); // Giving time to mysqlite to update file

/** @var Address|null $address1 */
$address1 = $addressRepository->findOneBy(['name' => 'Address1-updated2']);
Expand Down
2 changes: 1 addition & 1 deletion tests/HttpKernel/AndanteTimestampableKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void

public function getCacheDir(): string
{
return \sprintf(__DIR__.'/../../var/cache/test/%s/', \hash('crc32b', ((string) \json_encode($this->configs))));
return \sprintf(__DIR__.'/../../var/cache/test/%s/', \hash('crc32b', (string) \json_encode($this->configs)));
}

public function getLogDir(): string
Expand Down
2 changes: 1 addition & 1 deletion tests/HttpKernel/config/config_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ doctrine:
auto_mapping: true
mappings:
fixtures:
type: annotation
type: attribute
prefix: 'Andante\TimestampableBundle\Tests\Fixtures\Entity'
dir: '%kernel.project_dir%/tests/Fixtures/Entity/'
is_bundle: false
19 changes: 0 additions & 19 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
<?php

declare(strict_types=1);

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Annotations\CachedReader;
use Doctrine\Common\Cache\ArrayCache;

if (\class_exists('Doctrine\Common\Cache\ArrayCache')) {
\define('TESTS_PATH', __DIR__);
\define('VENDOR_PATH', \dirname(__DIR__).'/vendor');

AnnotationRegistry::registerFile(
__DIR__.'/../vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'
);

$reader = new AnnotationReader();
/** @phpstan-ignore-next-line */
$reader = new CachedReader($reader, new ArrayCache());
$_ENV['annotation_reader'] = $reader;
}

0 comments on commit ebebe80

Please sign in to comment.