Skip to content

Commit

Permalink
feat: support doctrine/orm 3 and doctrine/dbal 4 (#176)
Browse files Browse the repository at this point in the history
* feat: support doctrine/orm 3 and doctrine/dbal 4

* Update change-log-6.0-and-versions.md

---------

Co-authored-by: Christopher Georg <christopher.georg@sr-travel.de>
Co-authored-by: Johan Wilfer <johan@jttech.se>
  • Loading branch information
3 people authored Apr 19, 2024
1 parent d7ace69 commit 8d8448e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 21 deletions.
8 changes: 1 addition & 7 deletions Tests/DatabaseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ trait DatabaseTrait

public function setupDatabase(): void
{
self::dropDatabase();
$this->dropDatabase();
self::createDatabase();
}

Expand All @@ -31,12 +31,6 @@ private static function createDatabase(): void
$application = new Application($kernel);
$application->setAutoExit(false);

$code = $application->run(new ArrayInput([
'command' => 'doctrine:database:create',
'--quiet' => true,
]), new NullOutput());
self::assertSame(Command::SUCCESS, $code);

$code = $application->run(new ArrayInput([
'command' => 'doctrine:schema:create',
'--quiet' => true,
Expand Down
2 changes: 1 addition & 1 deletion Tests/PairHistory/PairHistoryManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function setUp(): void
'EUR'
);
$this->ratioHistoryRepo = $this->em->getRepository(RatioHistory::class);
$this->createDatabase();
self::createDatabase();
}

protected function tearDown(): void
Expand Down
13 changes: 10 additions & 3 deletions Tests/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ doctrine:
driver: "pdo_sqlite"
memory: true
path: "%kernel.cache_dir%/sqlite-tbbc-money-test.db"
use_savepoints: true

orm:
entity_managers:
default:
auto_mapping: true
auto_generate_proxy_classes: true
enable_lazy_ghost_objects: true
report_fields_where_declared: true
validate_xml_mapping: true
auto_mapping: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware

controller_resolver:
auto_mapping: true

doctrine_mongodb:
connections:
Expand Down
9 changes: 4 additions & 5 deletions change-log-6.0-and-versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ Versions from 6.0
### Not yet released!

**New features**
- Bumped minimum PHP version to PHP ^8.1
- Add support for MongoDB
- Add support for doctrine/orm 3 and doctrine/dbal 4

**BC breaking changes**
- Bumped minimum PHP version to PHP ^8.1
- Drop support for moneyphp/money < 4.5
- Drop `symfony/templating` and template function (use twig)
- Make `PairManagerInterface` readonly in commands

**Internal Developer things**
- Drop PHPUnit 9 support
- bump dev dependencies
- Migrate phpUnit config to version 10.
- Remove support for moneyphp/money < 4.5
- Migrate PHPUnit to version 10.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
"require-dev": {
"ext-sqlite3": "*",
"symfony/browser-kit": "^5.4|^6.0|^7.0",
"doctrine/doctrine-bundle": "^2.11",
"doctrine/doctrine-bundle": "^2.12",
"doctrine/mongodb-odm-bundle": "^4.6|^5.0",
"doctrine/orm": "^2.11",
"doctrine/orm": "^2.19.3|^3.0",
"florianv/exchanger": "^2.8.1",
"php-http/message": "^1.0",
"php-http/guzzle7-adapter": "^1.0",
Expand All @@ -62,9 +62,9 @@
]
},
"suggest": {
"doctrine/doctrine-bundle": "~2.11",
"doctrine/doctrine-bundle": "~2.12",
"doctrine/mongodb-odm-bundle": "For usage with MongoDB",
"doctrine/orm": "~2.17",
"doctrine/orm": "~2.19",
"florianv/exchanger": "Exchanger is a PHP framework to work with currency exchange rates from various services."
},
"config": {
Expand Down
7 changes: 6 additions & 1 deletion src/Type/MoneyType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\Exception\ValueNotConvertible;
use Doctrine\DBAL\Types\Type;
use Money\Currency;
use Money\Money;
Expand Down Expand Up @@ -59,7 +60,11 @@ public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform)
return $value->getCurrency().' '.$value->getAmount();
}

throw ConversionException::conversionFailed((string) $value, self::NAME);
# BC Layer Doctrine dbal 3/4
/** @psalm-suppress UndefinedMethod **/
throw class_exists(ValueNotConvertible::class) ?
ValueNotConvertible::new($value, self::NAME) :
ConversionException::conversionFailed($value, self::NAME);
}

public function getName(): string
Expand Down

0 comments on commit 8d8448e

Please sign in to comment.