Prevented "Undefined index" notice when updating #484

Merged
merged 2 commits into from Oct 22, 2012

4 participants

@jaspernbrouwer

While executing updates on an entity scheduled for update without a change-set, an "Undefined index" notice is raised.

This issue will occur when you manually call $em()->getUnitOfWork()->scheduleForUpdate() on an entity that hasn't changed. The entity will be included in UnitOfWork::$entityUpdates, but because there are no changes, its oid will not be included in UnitOfWork::$entityChangeSets.

I know I'm misusing scheduleForUpdate() a bit in this case, but the notice can easily be prevented with a !empty().

@jaspernbrouwer jaspernbrouwer Prevented "Undefined index" notice when updating
While executing updates on an entity scheduled for update without
a change-set, an "Undefined index" notice is raised.
0cfc37d
@doctrinebot

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DDC-2086

@stof
Doctrine member

can you add a testcase to prevent regressions ?

@jaspernbrouwer

I've added a test to UnitOfWorkTests.

Before the fix it outputs:

$ ./run-all.sh tests/Doctrine/Tests/ORM/UnitOfWorkTest.php 
RUNNING TESTS WITH CONFIG mysql.phpunit.xml
PHPUnit 3.7.8 by Sebastian Bergmann.

Configuration read from /Users/jappie/Development/doctrine-tests/mysql.phpunit.xml

......E

Time: 1 second, Memory: 10.50Mb

There was 1 error:

1) Doctrine\Tests\ORM\UnitOfWorkTest::testNoUndefinedIndexNoticeOnScheduleForUpdateWithoutChanges
Undefined index: 00000000381897d5000000005eec8ef2

/Users/jappie/Development/doctrine-tests/lib/Doctrine/ORM/UnitOfWork.php:985
/Users/jappie/Development/doctrine-tests/lib/Doctrine/ORM/UnitOfWork.php:319
/Users/jappie/Development/doctrine-tests/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php:228

FAILURES!
Tests: 7, Assertions: 35, Errors: 1.

After the fix it outputs:

$ ./run-all.sh tests/Doctrine/Tests/ORM/UnitOfWorkTest.php 
RUNNING TESTS WITH CONFIG mysql.phpunit.xml
PHPUnit 3.7.8 by Sebastian Bergmann.

Configuration read from /Users/jappie/Development/doctrine-tests/mysql.phpunit.xml

.......

Time: 1 second, Memory: 10.50Mb

OK (7 tests, 35 assertions)

I hope this will suffice.

@guilhermeblanco guilhermeblanco merged commit cd7ef6e into doctrine:master Oct 22, 2012

1 check passed

Details default The Travis build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment