Skip to content

Commit 6de776b

Browse files
author
Andrew Meshchanchuk
committed
Create tests for MongoDB annotation generator
1 parent ab25b1c commit 6de776b

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# The PHP namespace of generated entities
2+
namespaces:
3+
entity: 'AddressBook\Document'
4+
# Enable DunglasApiAnnotationGenerator
5+
annotationGenerators:
6+
- ApiPlatform\SchemaGenerator\AnnotationGenerator\PhpDocAnnotationGenerator
7+
- ApiPlatform\SchemaGenerator\AnnotationGenerator\DoctrineMongoDBAnnotationGenerator
8+
- ApiPlatform\SchemaGenerator\AnnotationGenerator\ConstraintAnnotationGenerator
9+
- ApiPlatform\SchemaGenerator\AnnotationGenerator\DunglasApiAnnotationGenerator
10+
# The list of types and properties we want to use
11+
types:
12+
Person:
13+
parent: false
14+
properties:
15+
name: ~
16+
familyName: ~
17+
givenName: ~
18+
additionalName: ~
19+
gender: ~
20+
address: { range: PostalAddress }
21+
birthDate: ~
22+
telephone: ~
23+
email: ~
24+
jobTitle: ~
25+
# Default relation table name would be "person_organization" for all following fields, but we customize them
26+
affiliation: ~
27+
brand: { relationTableName: "person_brand"}
28+
memberOf: { range: "Organization", cardinality: (1..*), relationTableName: "person_memberof"}
29+
worksFor: { range: "Organization", cardinality: (0..*), relationTableName: "person_worksfor"}
30+
# url field is a custom one without definition, it should render error
31+
url: ~
32+
friends: { range: "Person", cardinality: (0..*) }
33+
PostalAddress:
34+
# Disable the generation of the class hierarchy for this type
35+
parent: false
36+
properties:
37+
# Force the type of the addressCountry property to text
38+
addressCountry: { range: "Text" }
39+
addressLocality: ~
40+
addressRegion: ~
41+
postOfficeBoxNumber: ~
42+
postalCode: ~
43+
streetAddress: ~
44+
Organization:
45+
parent: false
46+
properties:
47+
name: ~

tests/config/mongodb/ecommerce.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
header: |
2+
/*
3+
* This file is part of the Ecommerce package.
4+
*
5+
* (c) Kévin Dunglas <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
rdfa:
11+
-
12+
uri: tests/data/schema.rdfa
13+
format: rdfa
14+
relations:
15+
- tests/data/v1.owl
16+
namespaces:
17+
entity: 'Dunglas\EcommerceBundle\Document'
18+
enum: 'Dunglas\EcommerceBundle\Enum'
19+
interface: 'Dunglas\EcommerceBundle\Model'
20+
annotationGenerators:
21+
- ApiPlatform\SchemaGenerator\AnnotationGenerator\PhpDocAnnotationGenerator
22+
- ApiPlatform\SchemaGenerator\AnnotationGenerator\ConstraintAnnotationGenerator
23+
- ApiPlatform\SchemaGenerator\AnnotationGenerator\DoctrineMongoDBAnnotationGenerator
24+
author: "Kévin Dunglas <[email protected]>"
25+
debug: true
26+
useInterface: true
27+
checkIsGoodRelations: true
28+
types:
29+
Thing:
30+
properties:
31+
name: ~
32+
description: ~
33+
image: { range: ImageObject }
34+
additionalType: ~
35+
Product:
36+
properties:
37+
sku:
38+
cardinality: "(0..1)"
39+
url: ~
40+
brand: ~
41+
productID: ~
42+
releaseDate: ~
43+
offers: ~
44+
itemCondition: ~
45+
gtin13: ~
46+
gtin14: ~
47+
gtin8: ~
48+
mpn: ~
49+
color: ~
50+
depth: { range: "Text" }
51+
height: { range: "Text" }
52+
weight: { range: "Text" }
53+
width: { range: "Text" }
54+
seller: { range: "Seller" }
55+
Brand:
56+
parent: "Thing"
57+
properties:
58+
logo: { range: "ImageObject" }
59+
Seller:
60+
parent: false
61+
guessFrom: Person
62+
properties:
63+
name: ~
64+
birthDate: ~
65+
ImageObject:
66+
parent: Thing
67+
properties:
68+
caption: ~
69+
ProductModel:
70+
properties:
71+
isVariantOf: ~
72+
Offer:
73+
parent: Thing
74+
properties:
75+
acceptedPaymentMethod: ~
76+
availability: ~
77+
availabilityStarts: ~
78+
availabilityEnds: ~
79+
availableDeliveryMethod: ~
80+
category: { range: "Text" }
81+
deliveryLeadTime: ~
82+
inventoryLevel: ~
83+
itemCondition: ~
84+
price: { range: Number }
85+
priceCurrency: ~
86+
validFrom: ~
87+
validThrough: ~
88+
DeliveryChargeSpecification: { parent: false }
89+
PaymentChargeSpecification: { parent: false }
90+
OfferItemCondition: ~
91+
PaymentMethod: ~
92+
ItemAvailability: ~
93+
DeliveryMethod: ~
94+
QuantitativeValue: { parent: false }

tests/run-tests.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ bin/schema generate-types build/address-book/ tests/config/address-book.yml
1111
bin/schema generate-types build/ecommerce/ tests/config/ecommerce.yml
1212
bin/schema generate-types build/vgo/ tests/config/vgo.yml
1313

14+
mkdir -p build/mongodb/ecommerce/ build/mongodb/address-book/
15+
bin/schema generate-types build/mongodb/address-book/ tests/config/mongodb/address-book.yml
16+
bin/schema generate-types build/mongodb/ecommerce/ tests/config/mongodb/ecommerce.yml
17+
1418
# Check code CS
1519
vendor/bin/php-cs-fixer --dry-run --diff -vvv fix src/
1620

0 commit comments

Comments
 (0)