Open walterdolce opened 9 years ago
There is a function generated without a name here. This looks really weird.
Yep @stof , sorry didn't notice that on the first look. That'd be an other weird one yes. Not sure why is like that.
Magento makes use of __call
where it intercepts "get"s and "set"s so that you can do setSomething("foo")
which would end up being used by an internal setData('something', 'foo')
, if that's of any help. Same applies for get(s): getSomething()
is sent to the internal getData('something')
For reference, this is where that's happening (assuming the class is of that type): https://github.com/magento/magento2/blob/develop/lib/internal/Magento/Framework/DataObject.php#L378
Well, magento sets the @method
phpdoc for its magi methods, so they should be understood by Prophecy. The place where the method without name appears makes me think it is related to magic methods (it is in the middle of other magic methods).
The phpdoc for magic methods looks right in the Magento source code in the develop branch. Can you tell me which version of Magento you are using exactly ? Maybe they fixed their phpdoc.
Currently using 1.0.0-beta3
there is no such tag in the repository. This will make it harder...
Can you paste the phpdoc of the Magento\Newsletter\Model\Subscriber
class available in your version ? I only need the class-level phpdoc.
:-/
Sure. This is it:
/**
* Subscriber model
*
* @method \Magento\Newsletter\Model\Resource\Subscriber _getResource()
* @method \Magento\Newsletter\Model\Resource\Subscriber getResource()
* @method int getStoreId()
* @method $this setStoreId(int $value)
* @method string getChangeStatusAt()
* @method $this setChangeStatusAt(string $value)
* @method int getCustomerId()
* @method $this setCustomerId(int $value)
* @method string getSubscriberEmail()
* @method $this setSubscriberEmail(string $value)
* @method int getSubscriberStatus()
* @method $this setSubscriberStatus(int $value)
* @method string getSubscriberConfirmCode()
* @method $this setSubscriberConfirmCode(string $value)
* @method int getSubscriberId()
* @method Subscriber setSubscriberId(int $value)
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
It seems it is invalid @method
again. If you replace the all $this
in the docblock with \Magento\Newsletter\Model\Subscriber
then prophecy will be able to create the double. So the docblock should be something like this:
/**
* Subscriber model
*
* @method \Magento\Newsletter\Model\Resource\Subscriber _getResource()
* @method \Magento\Newsletter\Model\Resource\Subscriber getResource()
* @method int getStoreId()
* @method \Magento\Newsletter\Model\Subscriber setStoreId(int $value)
* @method string getChangeStatusAt()
* @method \Magento\Newsletter\Model\Subscriber setChangeStatusAt(string $value)
* @method int getCustomerId()
* @method \Magento\Newsletter\Model\Subscriber setCustomerId(int $value)
* @method string getSubscriberEmail()
* @method \Magento\Newsletter\Model\Subscriber setSubscriberEmail(string $value)
* @method int getSubscriberStatus()
* @method \Magento\Newsletter\Model\Subscriber setSubscriberStatus(int $value)
* @method string getSubscriberConfirmCode()
* @method \Magento\Newsletter\Model\Subscriber setSubscriberConfirmCode(string $value)
* @method int getSubscriberId()
* @method Subscriber setSubscriberId(int $value)
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
@walterdolce if this change fix your problem then I will include this fix in this PR: https://github.com/magento/magento2/pull/1792
Well, we should support $this
then.
Is it an error on Magento's part that we should support, or is it valid syntax?
In the broader picture it would be good to handle the eval
failing in a cleaner way, if that's even possible.
which eval
?
and $this
is valid in the PSR-5 draft to document fluid APIs IIRC
The Prophecy double-generating eval that's erroring. It would be good to transform it into a catchable exception.
Hey guys,
What do you think about $this? Are you going to support it in a future version?
Why not. Just send a PR.
should be fixed in 1.6.1
While working on Magento2 and trying to spec one of the classes I was working on I stumbled into this error caused by the code generation Prophecy performs.
I'm not sure if/how that's reproducible without using Magento2, so I'll assume that you have a working instance to reproduce it in this case.
The specific error is:
PHP Parse error: syntax error, unexpected '(', expecting identifier (T_STRING) in /vagrant/vendor/phpspec/prophecy/src/Prophecy/Doubler/Generator/ClassCreator.php(49) : eval()'d code on line 286
Here's the spec:
Here's the actual class:
Here's the generated code. I think it's missing the closing curly bracket (
}
) for the namespace. Please note that even by hardcoding it and ensure code correctness, the class will not be doubled anyway.Please let me know if you need anything else.