Skip to content

Commit

Permalink
Fixed cast to bool
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 15, 2017
1 parent 609dccc commit 13cbfac
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Doctrine/Common/Proxy/AbstractProxyFactory.php
Expand Up @@ -98,7 +98,7 @@ public function __construct(ProxyGenerator $proxyGenerator, ClassMetadataFactory
{
$this->proxyGenerator = $proxyGenerator;
$this->metadataFactory = $metadataFactory;
$this->autoGenerate = (int)$autoGenerate;
$this->autoGenerate = (bool)$autoGenerate;
}

/**
Expand Down

9 comments on commit 13cbfac

@more7dev
Copy link

Choose a reason for hiding this comment

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

This commit introduced a bug.
Cast to bool is wrong, because this option has possible integer values. Previous version was ok.

Later in the AbstractProxyFactory::getProxyDefinition we have
switch ($this->autoGenerate) {
where we compare this value to integer constants.
In case of setting autoGenerate to true, the case is
self::AUTOGENERATE_FILE_NOT_EXISTS
but it should be
self::AUTOGENERATE_ALWAYS

If you set in configuration:
$config->setAutoGenerateProxyClasses(true);
proxy classes should be always generated, but because of that bug, they are generated only if proxy class file does not exist. If you later change entity class code, proxy class remains unchanged.

@Ocramius
Copy link
Member

Choose a reason for hiding this comment

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

@more7dev can you put this description into a test case?

@more7dev
Copy link

@more7dev more7dev commented on 13cbfac Aug 29, 2017

Choose a reason for hiding this comment

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

The problem is that
$config->setAutoGenerateProxyClasses($mode);
does not work as described in the documentation.

Reverting this commit will fix the problem.

I`m not sure, what test case you have in mind.

@Ocramius
Copy link
Member

Choose a reason for hiding this comment

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

I`m not sure, what test case you have in mind.

The test case should assert that the various self::AUTOGENERATE_* flags are correctly set after __construct

@Ocramius
Copy link
Member

Choose a reason for hiding this comment

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

The fact that we didn't have these tests in place is indeed why we got the regression in first place. A test case would:

  • demonstrate the issue and the regression
  • prevent further future regressions

@ondrejmirtes
Copy link
Contributor Author

@ondrejmirtes ondrejmirtes commented on 13cbfac Aug 29, 2017 via email

Choose a reason for hiding this comment

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

@Ocramius
Copy link
Member

@Ocramius Ocramius commented on 13cbfac Aug 29, 2017 via email

Choose a reason for hiding this comment

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

@ondrejmirtes
Copy link
Contributor Author

@ondrejmirtes ondrejmirtes commented on 13cbfac Aug 29, 2017 via email

Choose a reason for hiding this comment

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

@dragosprotung
Copy link
Contributor

@dragosprotung dragosprotung commented on 13cbfac Aug 30, 2017

Choose a reason for hiding this comment

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

Submitted PR #816 for this

Please sign in to comment.