Skip to content

Commit

Permalink
Remove Gedmo
Browse files Browse the repository at this point in the history
* Remove the Gedmo Doctrine Extensions and update configuration.
* Make Subscriptions add a created date in their constructor.
* Update PhpUnit configuration.
  • Loading branch information
Abban committed Jun 30, 2023
1 parent 2d1170b commit 6ed65c0
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 58 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ composer.phar
composer.lock

.phpunit.result.cache
.phpunit.cache

vendor/
coverage/
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fix-cs:
docker-compose run --rm --no-deps app ./vendor/bin/phpcbf

stan:
docker-compose run --rm --no-deps app ./vendor/bin/phpstan analyse --level=9 --no-progress src/ tests/
docker-compose run --rm --no-deps app ./vendor/bin/phpstan analyse --level=9 -c phpstan.neon --no-progress src/ tests/

setup: install-php

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"php": ">=8.1",

"doctrine/orm": "~2.7",
"gedmo/doctrine-extensions": "^3.0",
"psr/log": "^1.0|^2.0|^3.0",

"wmde/email-address": "~1.0",
Expand All @@ -15,7 +14,8 @@
"require-dev": {
"phpunit/phpunit": "~10.1.1",
"wmde/fundraising-phpcs": "~8.0",
"phpstan/phpstan": "~1.7"
"phpstan/phpstan": "~1.7",
"symfony/cache": "^6.1"
},
"repositories": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="WMDE\Fundraising\SubscriptionContext\Domain\Model\Subscription" table="subscription">
<id name="id" type="integer" column="id">
Expand All @@ -18,8 +17,6 @@
<field name="confirmationCode" type="string" column="confirmationCode" length="32" nullable="true" />
<field name="tracking" type="string" column="tracking" length="50" nullable="true" />
<field name="source" type="string" column="source" length="50" nullable="true" />
<field name="createdAt" type="datetime" column="createdAt" nullable="true">
<gedmo:timestampable on="create" />
</field>
<field name="createdAt" type="datetime" column="createdAt" nullable="true"/>
</entity>
</doctrine-mapping>
6 changes: 6 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#1 \\$value of function intval expects array\\|bool\\|float\\|int\\|resource\\|string\\|null, mixed given\\.$#"
count: 1
path: src/DataAccess/DoctrineSubscriptionRepository.php
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
includes:
- phpstan-baseline.neon
30 changes: 16 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
bootstrap="vendor/autoload.php"
backupGlobals="false"
colors="true"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
requireCoverageMetadata="true"
>
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
bootstrap="vendor/autoload.php"
backupGlobals="false"
colors="true"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
requireCoverageMetadata="true"
>
<coverage includeUncoveredFiles="true"/>
<testsuites>
<testsuite name="unit">
<directory>tests/Unit</directory>
Expand All @@ -21,4 +18,9 @@
<directory>tests/Integration</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
24 changes: 24 additions & 0 deletions phpunit.xml.dist.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
bootstrap="vendor/autoload.php"
backupGlobals="false"
colors="true"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
requireCoverageMetadata="true"
>
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="unit">
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="integration">
<directory>tests/Integration</directory>
</testsuite>
</testsuites>
</phpunit>
1 change: 1 addition & 0 deletions src/Domain/Model/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Subscription {

public function __construct() {
$this->setStatus( self::STATUS_NEW );
$this->createdAt = new DateTime();
}

public function setEmail( string $email ): self {
Expand Down
16 changes: 0 additions & 16 deletions src/SubscriptionContextFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

namespace WMDE\Fundraising\SubscriptionContext;

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\EventSubscriber;
use Gedmo\Timestampable\TimestampableListener;

class SubscriptionContextFactory {

private const DOCTRINE_CLASS_MAPPING_DIRECTORY = __DIR__ . '/../config/DoctrineClassMapping';
Expand All @@ -18,16 +14,4 @@ class SubscriptionContextFactory {
public function getDoctrineMappingPaths(): array {
return [ self::DOCTRINE_CLASS_MAPPING_DIRECTORY ];
}

/**
* @return array<class-string,EventSubscriber>
*/
public function newEventSubscribers(): array {
$timestampableListener = new TimestampableListener();
$timestampableListener->setAnnotationReader( new AnnotationReader() );
return [
TimestampableListener::class => $timestampableListener
];
}

}
22 changes: 1 addition & 21 deletions tests/TestSubscriptionContextFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@

namespace WMDE\Fundraising\SubscriptionContext\Tests;

use Doctrine\Common\EventManager;
use Doctrine\Common\EventSubscriber;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use WMDE\Fundraising\SubscriptionContext\SubscriptionContextFactory;

class TestSubscriptionContextFactory {

private Configuration $doctrineConfig;
private SubscriptionContextFactory $factory;
private Connection $connection;
private ?EntityManager $entityManager;

Expand All @@ -26,33 +22,17 @@ public function __construct( Configuration $doctrineConfig ) {
'driver' => 'pdo_sqlite',
'memory' => true,
] );
$this->factory = new SubscriptionContextFactory();
$this->entityManager = null;
}

public function getEntityManager(): EntityManager {
if ( $this->entityManager === null ) {
$eventManager = $this->setupEventSubscribers( $this->factory->newEventSubscribers() );

$this->entityManager = new EntityManager(
$this->connection,
$this->doctrineConfig,
$eventManager
$this->doctrineConfig
);
}

return $this->entityManager;
}

/**
* @param EventSubscriber[] $eventSubscribers
* @return EventManager
*/
private function setupEventSubscribers( array $eventSubscribers ): EventManager {
$eventManager = new EventManager();
foreach ( $eventSubscribers as $eventSubscriber ) {
$eventManager->addEventSubscriber( $eventSubscriber );
}
return $eventManager;
}
}

0 comments on commit 6ed65c0

Please sign in to comment.