Skip to content

Commit 7839772

Browse files
committed
chubbyphp-mongo
1 parent 6003b1d commit 7839772

File tree

29 files changed

+584
-717
lines changed

29 files changed

+584
-717
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,75 +33,72 @@ jobs:
3333
name: PHP 8.3
3434
runs-on: blacksmith-4vcpu-ubuntu-2404
3535
services:
36-
postgres:
37-
image: postgres:17
36+
mongo:
37+
image: mongo:8
3838
env:
39-
POSTGRES_DB: petstore
40-
POSTGRES_PASSWORD: KVKtkrTHhKuTJTor8pCP
41-
POSTGRES_USER: petstore
39+
MONGO_INITDB_ROOT_USERNAME: petstore
40+
MONGO_INITDB_ROOT_PASSWORD: KVKtkrTHhKuTJTor8pCP
4241
ports:
43-
- 5432:5432
42+
- 27017:27017
4443
steps:
4544
- name: checkout
4645
uses: actions/checkout@v4
4746
- name: wait for databases
4847
run: |
49-
while ! nc -z localhost 5432; do sleep 0.1; done
48+
while ! nc -z localhost 27017; do sleep 0.1; done
5049
- name: composer test
5150
uses: docker://ghcr.io/chubbyphp/ci-php83:latest
5251
env:
5352
APP_ENV: phpunit
54-
POSTGRES_URI: 'pgsql://petstore:[email protected]:5432/petstore?charset=utf8'
53+
MONGO_URI: mongodb://petstore:[email protected]:27017
5554
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5655
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
5756
php84:
5857
name: PHP 8.4
5958
runs-on: blacksmith-4vcpu-ubuntu-2404
6059
services:
61-
postgres:
62-
image: postgres:17
60+
mongo:
61+
image: mongo:8
6362
env:
64-
POSTGRES_DB: petstore
65-
POSTGRES_PASSWORD: KVKtkrTHhKuTJTor8pCP
66-
POSTGRES_USER: petstore
63+
MONGO_INITDB_ROOT_USERNAME: petstore
64+
MONGO_INITDB_ROOT_PASSWORD: KVKtkrTHhKuTJTor8pCP
6765
ports:
68-
- 5432:5432
66+
- 27017:27017
6967
steps:
7068
- name: checkout
7169
uses: actions/checkout@v4
7270
- name: wait for databases
7371
run: |
74-
while ! nc -z localhost 5432; do sleep 0.1; done
72+
while ! nc -z localhost 27017; do sleep 0.1; done
7573
- name: composer test
7674
uses: docker://ghcr.io/chubbyphp/ci-php84:latest
7775
env:
7876
APP_ENV: phpunit
79-
POSTGRES_URI: 'pgsql://petstore:[email protected]:5432/petstore?charset=utf8'
77+
MONGO_URI: mongodb://petstore:[email protected]:27017
8078
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8179
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
8280
php85:
8381
name: PHP 8.5
8482
runs-on: blacksmith-4vcpu-ubuntu-2404
8583
services:
86-
postgres:
87-
image: postgres:17
84+
mongo:
85+
image: mongo:8
8886
env:
89-
POSTGRES_DB: petstore
90-
POSTGRES_PASSWORD: KVKtkrTHhKuTJTor8pCP
91-
POSTGRES_USER: petstore
87+
MONGO_INITDB_ROOT_USERNAME: petstore
88+
MONGO_INITDB_ROOT_PASSWORD: KVKtkrTHhKuTJTor8pCP
9289
ports:
93-
- 5432:5432
90+
- 27017:27017
9491
steps:
9592
- name: checkout
9693
uses: actions/checkout@v4
9794
- name: wait for databases
9895
run: |
99-
while ! nc -z localhost 5432; do sleep 0.1; done
96+
while ! nc -z localhost 27017; do sleep 0.1; done
10097
- name: composer test
10198
uses: docker://ghcr.io/chubbyphp/ci-php85:latest
10299
env:
103100
APP_ENV: phpunit
104-
POSTGRES_URI: 'pgsql://petstore:[email protected]:5432/petstore?charset=utf8'
101+
MONGO_URI: mongodb://petstore:[email protected]:27017
105102
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
106103
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
107104
- name: sonarcloud.io

README.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# petstore
22

3-
[![CI](https://github.com/chubbyphp/petstore/actions/workflows/ci.yml/badge.svg?branch=chubbyphp)](https://github.com/chubbyphp/petstore/actions/workflows/ci.yml)
4-
[![Coverage Status](https://coveralls.io/repos/github/chubbyphp/petstore/badge.svg?branch=chubbyphp)](https://coveralls.io/github/chubbyphp/petstore?branch=chubbyphp)
5-
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fchubbyphp%2Fpetstore%2Fchubbyphp)](https://dashboard.stryker-mutator.io/reports/github.com/chubbyphp/petstore/chubbyphp)
3+
[![CI](https://github.com/chubbyphp/petstore/actions/workflows/ci.yml/badge.svg?branch=chubbyphp-mongo)](https://github.com/chubbyphp/petstore/actions/workflows/ci.yml)
4+
[![Coverage Status](https://coveralls.io/repos/github/chubbyphp/petstore/badge.svg?branch=chubbyphp-mongo)](https://coveralls.io/github/chubbyphp/petstore?branch=chubbyphp-mongo)
5+
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fchubbyphp%2Fpetstore%2Fchubbyphp-mongo)](https://dashboard.stryker-mutator.io/reports/github.com/chubbyphp/petstore/chubbyphp-mongo)
66

77
## Description
88

@@ -22,12 +22,11 @@ A simple skeleton to build api's based on the [chubbyphp-framework][1].
2222
* [chubbyphp/chubbyphp-laminas-config-factory][10]: ^1.5.1
2323
* [chubbyphp/chubbyphp-negotiation][11]: ^2.3.1
2424
* [chubbyphp/chubbyphp-parsing][12]: ^2.1.2
25-
* [doctrine/orm][13]: ^3.6.1
25+
* [doctrine/mongodb-odm][13]: ^2.15.3
2626
* [monolog/monolog][14]: ^3.10
2727
* [ramsey/uuid][15]: ^4.9.2
2828
* [slim/psr7][16]: ^1.8
2929
* [symfony/console][17]: ^7.4.3|^8.0.3
30-
* [symfony/var-exporter][18]: ^7.4.0|^8.0.0
3130

3231
## Environment
3332

@@ -89,7 +88,7 @@ composer setup:dev
8988

9089
### DBs
9190

92-
* jdbc:postgresql://localhost:5432/petstore?user=root&password=root
91+
* jdbc:mongodb://petstore:4aAUfBjDACcdZxNwJgJ6@localhost:27017/petstore
9392

9493
## Structure
9594

@@ -121,11 +120,11 @@ Models, entities, documents what ever fits your purpose the best.
121120
* [App\Core\Model][90]
122121
* [App\Pet\Model][91]
123122

124-
### ORM
123+
### ODM
125124

126-
ORM Mapping definitions.
125+
ODM Mapping definitions.
127126

128-
* [App\Pet\Orm][100]
127+
* [App\Pet\Odm][100]
129128

130129
### Parsing
131130

@@ -215,12 +214,11 @@ curl -XPUT 'https://admin:98T722Eqw99oqFCSJCnB@localhost:9200/_plugins/_ism/poli
215214
[10]: https://packagist.org/packages/chubbyphp/chubbyphp-laminas-config-factory
216215
[11]: https://packagist.org/packages/chubbyphp/chubbyphp-negotiation
217216
[12]: https://packagist.org/packages/chubbyphp/chubbyphp-parsing
218-
[13]: https://packagist.org/packages/doctrine/orm
217+
[13]: https://packagist.org/packages/doctrine/mongodb-odm
219218
[14]: https://packagist.org/packages/monolog/monolog
220219
[15]: https://packagist.org/packages/ramsey/uuid
221220
[16]: https://packagist.org/packages/slim/psr7
222221
[17]: https://packagist.org/packages/symfony/console
223-
[18]: https://packagist.org/packages/symfony/var-exporter
224222

225223
[60]: src/Core/Collection
226224
[61]: src/Pet/Collection
@@ -233,7 +231,7 @@ curl -XPUT 'https://admin:98T722Eqw99oqFCSJCnB@localhost:9200/_plugins/_ism/poli
233231
[90]: src/Core/Model
234232
[91]: src/Pet/Model
235233

236-
[100]: src/Pet/Orm
234+
[100]: src/Pet/Odm
237235

238236
[110]: src/Core/Parsing
239237
[111]: src/Pet/Parsing

composer.json

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@
2626
"chubbyphp/chubbyphp-laminas-config-factory": "^1.5.1",
2727
"chubbyphp/chubbyphp-negotiation": "^2.3.1",
2828
"chubbyphp/chubbyphp-parsing": "^2.1.2",
29-
"doctrine/orm": "^3.6.1",
29+
"doctrine/mongodb-odm": "^2.15.3",
3030
"monolog/monolog": "^3.10",
3131
"ramsey/uuid": "^4.9.2",
3232
"slim/psr7": "^1.8",
33-
"symfony/console": "^7.4.3|^8.0.3",
34-
"symfony/var-exporter": "^7.4.0|^8.0.0"
33+
"symfony/console": "^7.4.3|^8.0.3"
3534
},
3635
"require-dev": {
3736
"chubbyphp/chubbyphp-dev-helper": "dev-master",
@@ -62,23 +61,18 @@
6261
},
6362
"scripts": {
6463
"clean-directories": "bin/console clean-directories cache log",
65-
"database:create": "bin/console dbal:database:create --if-not-exists",
66-
"database:drop": "bin/console dbal:database:drop --if-exists --force",
67-
"database:schema:update": "bin/console orm:schema-tool:update --force --dump-sql",
68-
"database:schema:validate": "bin/console orm:validate-schema",
64+
"database:schema:drop": "bin/console odm:schema:drop --db",
65+
"database:schema:update": "bin/console odm:schema:update",
66+
"database:schema:validate": "bin/console odm:schema:validate",
6967
"fix:cs": "mkdir -p build && vendor/bin/php-cs-fixer fix --cache-file=build/phpcs.cache",
7068
"setup:dev": [
71-
"@database:drop --env=dev",
72-
"@database:create --env=dev",
69+
"@database:schema:drop --env=dev",
7370
"@database:schema:update --env=dev",
74-
"@database:schema:validate --env=dev",
7571
"@clean-directories --env=dev"
7672
],
7773
"setup:phpunit": [
78-
"@database:drop --env=phpunit",
79-
"@database:create --env=phpunit",
74+
"@database:schema:drop --env=phpunit",
8075
"@database:schema:update --env=phpunit",
81-
"@database:schema:validate --env=phpunit",
8276
"@clean-directories --env=phpunit"
8377
],
8478
"test": [

config/phpunit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
declare(strict_types=1);
44

55
$config = require __DIR__.'/dev.php';
6-
$config['doctrine']['dbal']['connection']['dbname'] .= '_phpunit';
6+
$config['doctrine']['mongodbOdm']['configuration']['defaultDB'] .= '_phpunit';
77

88
return $config;

config/prod.php

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
use App\Core\ServiceFactory\RequestHandler\PingRequestHandlerFactory;
3333
use App\Pet\Model\Pet;
3434
use App\Pet\Model\Vaccination;
35-
use App\Pet\Orm\PetMapping;
36-
use App\Pet\Orm\VaccinationMapping;
35+
use App\Pet\Odm\PetMapping;
36+
use App\Pet\Odm\VaccinationMapping;
3737
use App\Pet\Parsing\PetParsing;
3838
use App\Pet\Repository\PetRepository;
3939
use App\Pet\ServiceFactory\Framework\PetRoutesDelegator;
@@ -59,10 +59,7 @@
5959
use Chubbyphp\Framework\Router\RoutesByNameInterface;
6060
use Chubbyphp\Framework\Router\UrlGeneratorInterface;
6161
use Chubbyphp\Laminas\Config\Doctrine\ServiceFactory\Common\Cache\ApcuAdapterFactory;
62-
use Chubbyphp\Laminas\Config\Doctrine\ServiceFactory\DBAL\ConnectionFactory;
63-
use Chubbyphp\Laminas\Config\Doctrine\ServiceFactory\DBAL\Tools\Console\ContainerConnectionProviderFactory;
64-
use Chubbyphp\Laminas\Config\Doctrine\ServiceFactory\ORM\EntityManagerFactory;
65-
use Chubbyphp\Laminas\Config\Doctrine\ServiceFactory\ORM\Tools\Console\ContainerEntityManagerProviderFactory;
62+
use Chubbyphp\Laminas\Config\Doctrine\ServiceFactory\ODM\MongoDB\DocumentManagerFactory;
6663
use Chubbyphp\Laminas\Config\Doctrine\ServiceFactory\Persistence\Mapping\Driver\ClassMapDriverFactory;
6764
use Chubbyphp\Negotiation\AcceptNegotiatorInterface;
6865
use Chubbyphp\Negotiation\ContentTypeNegotiatorInterface;
@@ -73,12 +70,7 @@
7370
use Chubbyphp\Negotiation\ServiceFactory\ContentTypeMiddlewareFactory;
7471
use Chubbyphp\Negotiation\ServiceFactory\ContentTypeNegotiatorFactory;
7572
use Chubbyphp\Parsing\ParserInterface;
76-
use Doctrine\DBAL\Connection;
77-
use Doctrine\DBAL\Tools\Console\ConnectionProvider;
78-
use Doctrine\DBAL\Tools\DsnParser;
79-
use Doctrine\ORM\EntityManager;
80-
use Doctrine\ORM\EntityManagerInterface;
81-
use Doctrine\ORM\Tools\Console\EntityManagerProvider;
73+
use Doctrine\ODM\MongoDB\DocumentManager;
8274
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
8375
use Monolog\Level;
8476
use Psr\Cache\CacheItemPoolInterface;
@@ -105,26 +97,21 @@
10597
],
10698
'debug' => false,
10799
'dependencies' => [
108-
'aliases' => [
109-
EntityManager::class => EntityManagerInterface::class,
110-
],
111100
'factories' => [
112101
AcceptMiddleware::class => AcceptMiddlewareFactory::class,
113-
AcceptNegotiatorInterface::class => AcceptNegotiatorFactory::class,
114102
AcceptNegotiatorInterface::class.'supportedMediaTypes[]' => AcceptNegotiatorSupportedMediaTypesFactory::class,
103+
AcceptNegotiatorInterface::class.'supportedMediaTypes[]' => AcceptNegotiatorSupportedMediaTypesFactory::class,
104+
AcceptNegotiatorInterface::class => AcceptNegotiatorFactory::class,
115105
ApiExceptionMiddleware::class => ApiExceptionMiddlewareFactory::class,
116106
CacheItemPoolInterface::class => ApcuAdapterFactory::class,
117107
Command::class.'[]' => CommandsFactory::class,
118-
Connection::class => ConnectionFactory::class,
119-
ConnectionProvider::class => ContainerConnectionProviderFactory::class,
120108
ContentTypeMiddleware::class => ContentTypeMiddlewareFactory::class,
121-
ContentTypeNegotiatorInterface::class => ContentTypeNegotiatorFactory::class,
122109
ContentTypeNegotiatorInterface::class.'supportedMediaTypes[]' => ContentTypeNegotiatorSupportedMediaTypesFactory::class,
110+
ContentTypeNegotiatorInterface::class => ContentTypeNegotiatorFactory::class,
123111
CorsMiddleware::class => CorsMiddlewareFactory::class,
124112
DecoderInterface::class => DecoderFactory::class,
113+
DocumentManager::class => DocumentManagerFactory::class,
125114
EncoderInterface::class => EncoderFactory::class,
126-
EntityManagerInterface::class => EntityManagerFactory::class,
127-
EntityManagerProvider::class => ContainerEntityManagerProviderFactory::class,
128115
ExceptionMiddleware::class => ExceptionMiddlewareFactory::class,
129116
LoggerInterface::class => LoggerFactory::class,
130117
MappingDriver::class => ClassMapDriverFactory::class,
@@ -140,10 +127,10 @@
140127
PetRepository::class => PetRepositoryFactory::class,
141128
PingRequestHandler::class => PingRequestHandlerFactory::class,
142129
ResponseFactoryInterface::class => ResponseFactoryFactory::class,
143-
RouteInterface::class.'[]' => RoutesFactory::class,
144130
RouteMatcherInterface::class => RouteMatcherFactory::class,
145131
RouteMatcherMiddleware::class => RouteMatcherMiddlewareFactory::class,
146132
RoutesByNameInterface::class => RoutesByNameFactory::class,
133+
RouteInterface::class.'[]' => RoutesFactory::class,
147134
StreamFactoryInterface::class => StreamFactoryFactory::class,
148135
TypeDecoderInterface::class.'[]' => TypeDecodersFactory::class,
149136
TypeEncoderInterface::class.'[]' => TypeEncodersFactory::class,
@@ -166,9 +153,6 @@
166153
'namespace' => 'doctrine',
167154
],
168155
],
169-
'dbal' => [
170-
'connection' => (new DsnParser(['pgsql' => 'pdo_pgsql']))->parse(getenv('POSTGRES_URI')),
171-
],
172156
'driver' => [
173157
'classMap' => [
174158
'map' => [
@@ -177,12 +161,26 @@
177161
],
178162
],
179163
],
180-
'orm' => [
164+
'mongodb' => [
165+
'client' => [
166+
'uri' => getenv('MONGO_URI'),
167+
'driverOptions' => [
168+
'typeMap' => DocumentManager::CLIENT_TYPEMAP,
169+
'driver' => [
170+
'name' => 'doctrine-odm',
171+
],
172+
],
173+
],
174+
],
175+
'mongodbOdm' => [
181176
'configuration' => [
182177
'metadataDriverImpl' => MappingDriver::class,
183-
'proxyDir' => $cacheDir.'/doctrine/orm/proxies',
184-
'proxyNamespace' => 'DoctrineORMProxy',
178+
'proxyDir' => $cacheDir.'/doctrine/mongodbOdm/proxies',
179+
'proxyNamespace' => 'DoctrineMongoDBODMProxy',
180+
'hydratorDir' => $cacheDir.'/doctrine/mongodbOdm/hydrators',
181+
'hydratorNamespace' => 'DoctrineMongoDBODMHydrators',
185182
'metadataCache' => CacheItemPoolInterface::class,
183+
'defaultDB' => 'petstore',
186184
],
187185
],
188186
],

0 commit comments

Comments
 (0)