Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* A fluent interface isn't generated anymore by default unless you set the `fluentMutatorMethods` config flag to `true`
* Useless PHPDoc (`@param` and `@return` annotations when a typehint exist and mutator description) isn't generated anymore
* `DateTimeInterface` is used instead of `DateTime` when possible
* Add the ability to not generate mutator methods (useful when generating public properties)
* Add the ability to not generate accessor methods (useful when generating public properties)
* The `extract-cardinalities` gains two new options: one to configure the Schema.org's file to use, the other for the GoodRelations one
* The annotation generator for API Platform v1 has been dropped. Only API Platform v2 is now supported.
* Parent class is not generated by default anymore (using inheritance for entity is discouraged)
Expand Down
2 changes: 1 addition & 1 deletion src/TypesGeneratorConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function ($rdfa) {
->end()
->scalarNode('author')->defaultFalse()->info('The value of the phpDoc\'s @author annotation')->example('Kévin Dunglas <dunglas@gmail.com>')->end()
->enumNode('fieldVisibility')->values(['private', 'protected', 'public'])->defaultValue('private')->cannotBeEmpty()->info('Visibility of entities fields')->end()
->booleanNode('mutatorMethods')->defaultTrue()->info('Set this flag to false to not generate getter, setter, adder and remover methods')->end()
->booleanNode('accessorMethods')->defaultTrue()->info('Set this flag to false to not generate getter, setter, adder and remover methods')->end()
->booleanNode('fluentMutatorMethods')->defaultFalse()->info('Set this flag to true to generate fluent setter, adder and remover methods')->end()
->arrayNode('types')
->beforeNormalization()
Expand Down
2 changes: 1 addition & 1 deletion templates/class.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use {{ use }};
}
{% endif %}

{% if config.mutatorMethods %}
{% if config.accessorMethods %}
{% for field in class.fields %}
{% if field.isArray %}
/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Command/DumpConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ interface: AppBundle\Model # Example: Acme\Model
fieldVisibility: private # One of "private"; "protected"; "public"

# Set this flag to false to not generate getter, setter, adder and remover methods
mutatorMethods: true
accessorMethods: true

# Set this flag to true to generate fluent setter, adder and remover methods
fluentMutatorMethods: false
Expand Down
25 changes: 18 additions & 7 deletions tests/Command/GenerateTypesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public function getArguments()
[__DIR__.'/../../build/blog/', __DIR__.'/../config/blog.yaml'],
[__DIR__.'/../../build/ecommerce/', __DIR__.'/../config/ecommerce.yaml'],
[__DIR__.'/../../build/vgo/', __DIR__.'/../config/vgo.yaml'],
[__DIR__.'/../../build/public-properties/', __DIR__.'/../config/public-properties.yaml'],
[__DIR__.'/../../build/mongodb/address-book/', __DIR__.'/../config/mongodb/address-book.yaml'],
[__DIR__.'/../../build/mongodb/ecommerce/', __DIR__.'/../config/mongodb/ecommerce.yaml'],
];
Expand All @@ -61,14 +60,10 @@ public function testFluentMutators()
{
$outputDir = __DIR__.'/../../build/fluent-mutators';
$config = __DIR__.'/../config/fluent-mutators.yaml';

$this->fs->mkdir($outputDir);

$commandTester = new CommandTester(new GenerateTypesCommand());
$this->assertEquals(0, $commandTester->execute(['output' => $outputDir, 'config' => $config]));

$organization = file_get_contents($outputDir.'/AppBundle/Entity/Person.php');

$this->assertContains(<<<'PHP'
public function setUrl(?string $url): self
{
Expand All @@ -77,8 +72,7 @@ public function setUrl(?string $url): self
return $this;
}
PHP
, $organization);

, $organization);
$this->assertContains(<<<'PHP'
public function addFriends(Person $friends): self
{
Expand All @@ -96,4 +90,21 @@ public function removeFriends(Person $friends): self
PHP
, $organization);
}

public function testDoNotGenerateAccessorMethods()
{
$outputDir = __DIR__.'/../../build/public-properties';
$config = __DIR__.'/../config/public-properties.yaml';

$this->fs->mkdir($outputDir);

$commandTester = new CommandTester(new GenerateTypesCommand());
$this->assertEquals(0, $commandTester->execute(['output' => $outputDir, 'config' => $config]));

$organization = file_get_contents($outputDir.'/AppBundle/Entity/Person.php');
$this->assertNotContains('function get', $organization);
$this->assertNotContains('function set', $organization);
$this->assertNotContains('function add', $organization);
$this->assertNotContains('function remove', $organization);
}
}
2 changes: 1 addition & 1 deletion tests/config/public-properties.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ rdfa: [{ uri: tests/data/schema.rdfa, format: rdfa }]
relations: [tests/data/v1.owl]

fieldVisibility: public
mutatorMethods: false
accessorMethods: false
types:
Person:
properties:
Expand Down