Skip to content

Commit 178bea6

Browse files
authored
Merge pull request #94 from dunglas/fix-accessorMethods
Rename the mutatorMethods option to accessorMethods. Add a test.
2 parents 2560f5c + 7218ad0 commit 178bea6

File tree

6 files changed

+23
-12
lines changed

6 files changed

+23
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* A fluent interface isn't generated anymore by default unless you set the `fluentMutatorMethods` config flag to `true`
88
* Useless PHPDoc (`@param` and `@return` annotations when a typehint exist and mutator description) isn't generated anymore
99
* `DateTimeInterface` is used instead of `DateTime` when possible
10-
* Add the ability to not generate mutator methods (useful when generating public properties)
10+
* Add the ability to not generate accessor methods (useful when generating public properties)
1111
* The `extract-cardinalities` gains two new options: one to configure the Schema.org's file to use, the other for the GoodRelations one
1212
* The annotation generator for API Platform v1 has been dropped. Only API Platform v2 is now supported.
1313
* Parent class is not generated by default anymore (using inheritance for entity is discouraged)

src/TypesGeneratorConfiguration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function ($rdfa) {
100100
->end()
101101
->scalarNode('author')->defaultFalse()->info('The value of the phpDoc\'s @author annotation')->example('Kévin Dunglas <[email protected]>')->end()
102102
->enumNode('fieldVisibility')->values(['private', 'protected', 'public'])->defaultValue('private')->cannotBeEmpty()->info('Visibility of entities fields')->end()
103-
->booleanNode('mutatorMethods')->defaultTrue()->info('Set this flag to false to not generate getter, setter, adder and remover methods')->end()
103+
->booleanNode('accessorMethods')->defaultTrue()->info('Set this flag to false to not generate getter, setter, adder and remover methods')->end()
104104
->booleanNode('fluentMutatorMethods')->defaultFalse()->info('Set this flag to true to generate fluent setter, adder and remover methods')->end()
105105
->arrayNode('types')
106106
->beforeNormalization()

templates/class.php.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use {{ use }};
5959
}
6060
{% endif %}
6161
62-
{% if config.mutatorMethods %}
62+
{% if config.accessorMethods %}
6363
{% for field in class.fields %}
6464
{% if field.isArray %}
6565
/**

tests/Command/DumpConfigurationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ interface: AppBundle\Model # Example: Acme\Model
9696
fieldVisibility: private # One of "private"; "protected"; "public"
9797
9898
# Set this flag to false to not generate getter, setter, adder and remover methods
99-
mutatorMethods: true
99+
accessorMethods: true
100100
101101
# Set this flag to true to generate fluent setter, adder and remover methods
102102
fluentMutatorMethods: false

tests/Command/GenerateTypesCommandTest.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public function getArguments()
5151
[__DIR__.'/../../build/blog/', __DIR__.'/../config/blog.yaml'],
5252
[__DIR__.'/../../build/ecommerce/', __DIR__.'/../config/ecommerce.yaml'],
5353
[__DIR__.'/../../build/vgo/', __DIR__.'/../config/vgo.yaml'],
54-
[__DIR__.'/../../build/public-properties/', __DIR__.'/../config/public-properties.yaml'],
5554
[__DIR__.'/../../build/mongodb/address-book/', __DIR__.'/../config/mongodb/address-book.yaml'],
5655
[__DIR__.'/../../build/mongodb/ecommerce/', __DIR__.'/../config/mongodb/ecommerce.yaml'],
5756
];
@@ -61,14 +60,10 @@ public function testFluentMutators()
6160
{
6261
$outputDir = __DIR__.'/../../build/fluent-mutators';
6362
$config = __DIR__.'/../config/fluent-mutators.yaml';
64-
6563
$this->fs->mkdir($outputDir);
66-
6764
$commandTester = new CommandTester(new GenerateTypesCommand());
6865
$this->assertEquals(0, $commandTester->execute(['output' => $outputDir, 'config' => $config]));
69-
7066
$organization = file_get_contents($outputDir.'/AppBundle/Entity/Person.php');
71-
7267
$this->assertContains(<<<'PHP'
7368
public function setUrl(?string $url): self
7469
{
@@ -77,8 +72,7 @@ public function setUrl(?string $url): self
7772
return $this;
7873
}
7974
PHP
80-
, $organization);
81-
75+
, $organization);
8276
$this->assertContains(<<<'PHP'
8377
public function addFriends(Person $friends): self
8478
{
@@ -96,4 +90,21 @@ public function removeFriends(Person $friends): self
9690
PHP
9791
, $organization);
9892
}
93+
94+
public function testDoNotGenerateAccessorMethods()
95+
{
96+
$outputDir = __DIR__.'/../../build/public-properties';
97+
$config = __DIR__.'/../config/public-properties.yaml';
98+
99+
$this->fs->mkdir($outputDir);
100+
101+
$commandTester = new CommandTester(new GenerateTypesCommand());
102+
$this->assertEquals(0, $commandTester->execute(['output' => $outputDir, 'config' => $config]));
103+
104+
$organization = file_get_contents($outputDir.'/AppBundle/Entity/Person.php');
105+
$this->assertNotContains('function get', $organization);
106+
$this->assertNotContains('function set', $organization);
107+
$this->assertNotContains('function add', $organization);
108+
$this->assertNotContains('function remove', $organization);
109+
}
99110
}

tests/config/public-properties.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ rdfa: [{ uri: tests/data/schema.rdfa, format: rdfa }]
22
relations: [tests/data/v1.owl]
33

44
fieldVisibility: public
5-
mutatorMethods: false
5+
accessorMethods: false
66
types:
77
Person:
88
properties:

0 commit comments

Comments
 (0)