Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapped entity listeners are now processed by metadata exporters #6593

Merged
merged 7 commits into from
Aug 16, 2017

Conversation

tPl0ch
Copy link
Contributor

@tPl0ch tPl0ch commented Aug 1, 2017

The current implementation of the exporters are not taking the entity
listeners into account. I have added test cases for most of the edge
cases I could think of and implemented the Exporter handling.

This PR originates from #5864,
I was overwhelmed by the amount of conflicts I had to resolve so I
started anew on a clean master HEAD.

$lines[] = sprintf(
'$metadata->addEntityListener(\'%s\', \'%s\', \'%s\');',
$event,
$entityListener['class'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this code tested? Can't seem to find it. Also, use var_export() instead of single quotes around a %s

$entityListenerXml->addAttribute('class', $entityListener['class']);
$entityListenersXmlMap[$entityListener['class']] = $entityListenerXml;
} else {
$entityListenerXml = $entityListenersXmlMap[$entityListener['class']];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use an early return. Swap the negation on the if to get rid of the else overall

*
* @return array
*/
private function processEntityListeners(ClassMetadataInfo $metadata, $array)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can now add return hints (we're on PHP 7.1 ;-) )

*
* @return string
*/
protected function generateEntityListenerAnnotation(ClassMetadataInfo $metadata)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return type

* @param ClassMetadataInfo $metadata
* @param array &$lines
*/
private function processEntityListeners(ClassMetadataInfo $metadata, &$lines)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the by-ref usage, and instead use array_merge() in the caller?

*
* @return array
*/
private function processEntityListenerConfig($array, $entityListenerConfig, $event)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return type

*
* @param ClassMetadata $class
*/
public function testEntityListenersGetExported($class)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

: void

@@ -371,6 +373,26 @@ public function testCascadeAllCollapsed()
}
}

/**
* @depends testExportedMetadataCanBeReadBackIn
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really want to use @depends here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's how all other export tests are structured, so I just adhered to the structure within the test case.

$this->assertNotEmpty($class->entityListeners);
$this->assertCount(2, $class->entityListeners[Events::prePersist]);
$this->assertCount(2, $class->entityListeners[Events::postPersist]);
$this->assertEquals(UserListener::class, $class->entityListeners[Events::prePersist][0]['class']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this is the test that I was missing.

@@ -5,6 +5,11 @@
/**
* @Entity
* @HasLifecycleCallbacks
* @EntityListeners({
* Doctrine\Tests\ORM\Tools\Export\UserListener::class,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should probably be prefixed with \ to avoid import collisions

Copy link
Contributor Author

@tPl0ch tPl0ch Aug 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a weird issue with this, the resulting string is "\Doctrine\Tests\ORM\Tools\Export\UserListener", although ::class notation normally results in class names without root namespace:

<?php
echo \SimpleXMLElement::class;
// SimpleXMLElement

Using the ::class notation that way works as intended.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tPl0ch gotcha, seems weird, but it's probably a doctrine/annotations bug.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ocramius
Copy link
Member

@tPl0ch tPl0ch force-pushed the hotfix-entity-listener-export branch 2 times, most recently from b3d4e8c to 83497d0 Compare August 14, 2017 08:14
@tPl0ch
Copy link
Contributor Author

tPl0ch commented Aug 14, 2017

@Ocramius I think I have fixed the issues regarding the nullable return types. I totally forgot that a method that has no return statement now actually is none and not null. Also inversed a few conditions to have early returns. Gonna rebase and squash against the current HEAD.

@tPl0ch tPl0ch force-pushed the hotfix-entity-listener-export branch from 83497d0 to d485c18 Compare August 14, 2017 10:41
The current implementation of the exporters are not taking the entity
listeners into account. I have added test cases for most of the edge
cases I could think of and implemented the Exporter handling.

This PR originates from doctrine#5864,
I was overwhelmed by the amount of conflicts I had to resolve so I
started anew on a clean master HEAD.

Squashed commits:

- Code review aftermath
- Add even more return type declarations
- Added `return null` to methods declared with nullable return types
- Removed unneeded docblocks when types are self-explanatory
@tPl0ch tPl0ch force-pushed the hotfix-entity-listener-export branch from d485c18 to b7ae5b4 Compare August 15, 2017 08:09
@Ocramius Ocramius changed the title Entity listeners are now processed by exporters Mapped entity listeners are now processed by metadata exporters Aug 15, 2017
@@ -46,7 +46,7 @@ class AnnotationExporter extends AbstractExporter
*/
public function exportClassMetadata(ClassMetadataInfo $metadata): string
{
if ( ! $this->_entityGenerator) {
if (!$this->_entityGenerator) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, we use if ( ! $withTheSpace

@tPl0ch
Copy link
Contributor Author

tPl0ch commented Aug 16, 2017

@Ocramius should be fine now (hopefully)...

@Ocramius Ocramius added this to the 2.6.0 milestone Aug 16, 2017
@Ocramius Ocramius assigned Ocramius and unassigned tPl0ch Aug 16, 2017
@Ocramius Ocramius merged commit e4006e5 into doctrine:master Aug 16, 2017
Ocramius added a commit that referenced this pull request Aug 16, 2017
…pe changes

That's still to be considered a BC break, since child classes are broken if incompatible.

Sorry @tPl0ch :-(
Ocramius added a commit that referenced this pull request Aug 16, 2017
Ocramius added a commit that referenced this pull request Aug 16, 2017
@Ocramius
Copy link
Member

@tPl0ch manually merged via 76e2155

Sorry for the method hints - I had to revert them, since those classes are open for inheritance, so the additional hints are a BC break.

See https://3v4l.org/kSIhN for the specifics.

@Ocramius
Copy link
Member

Also, thanks for enduring the review hell we generally fire in contributors' direction :-)

@tPl0ch tPl0ch deleted the hotfix-entity-listener-export branch August 16, 2017 19:09
@tPl0ch
Copy link
Contributor Author

tPl0ch commented Aug 16, 2017

@Ocramius is there a phpcs standards configuration file for Doctrine so that all that CS issues can be caught during development?

@Ocramius
Copy link
Member

There is, but we don't apply CS changes yet due to the amount of open PRs that would conflict for no good reason

@Ocramius
Copy link
Member

Ocramius commented Aug 16, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants