Easy Mock is a mocking library for Java which can help you to test your code isolated from some other components.
If you ever get the next compile error:
"expected (java.lang.void) in easymock cannot be applied to (void)"
It may be a result of you trying to call EasyMock.expect(mock.methodWhichReturnsVoid()), instead of doing that you should use expectLastCall method, you can use it like:
mock.methodWhichReturnsVoid();
EasyMock.expectLastCall();
I posted this tip because it took me several minutes to figure out what I was doing wrong, by the way, I was really tired!
Robert Rusu
Posts on different topics such as Java, PHP, freelancing, various frameworks and programming principles.
Showing posts with label tips. Show all posts
Showing posts with label tips. Show all posts
Monday, April 14, 2014
Saturday, April 5, 2014
Symfony2.3 form, grandchildren forms are not validated
Recently I had some issues with Symfony2.3 grandchildren forms not being validated even if I used as default option 'cascade_validation' => true. After doing some research I found other people having same issue and I found out that the solution is that besides putting 'cascade_validation' to true as default option to the form I also had to 'cascade_validation' => true in the collection of children and grandchildren forms I added.
Check the code sample below
Father form
References: https://github.com/symfony/symfony/issues/5204
I hope it helped you!
Robert Rusu
Check the code sample below
Father form
class FatherType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'children',
'collection',
array(
'type' => new ChildFormType(),
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'required' => false,
'cascade_validation' => true //important to be added
)
);
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(
array(
'data_class' => 'Company/SomeBundle/Form/Entity/FatherFormEntity',
'cascade_validation' => true, //important to be added
)
);
}
public function getName()
{
return 'father';
}
}
Child formclass ChildType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'grandchildren',
'collection',
array(
'type' => new GrandchildFormType(),
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'required' => false,
'cascade_validation' => true //important to be added
)
);
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(
array(
'data_class' => 'Company/SomeBundle/Form/Entity/ChildFormEntity',
'cascade_validation' => true, //important to be added
)
);
}
public function getName()
{
return 'child';
}
}
Grandchild formclass GrandchildType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'attribute',
'text'
);
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(
array(
'data_class' => 'Company/SomeBundle/Form/Entity/GrandchildFormEntity',
'cascade_validation' => true,
)
);
}
public function getName()
{
return 'grandchild';
}
}
References: https://github.com/symfony/symfony/issues/5204
I hope it helped you!
Robert Rusu
Thursday, January 2, 2014
Git stash
Using git stash
Sometimes we are working on a new feature on a project using the git version control and we are requested to fix a bug or just check some piece of code on another branch. We would not want to commit a half way done feature, also we would not like to delete the changes to the branch. Well we can use git stash, by just running this command the changes are stashed until we later need them, if we run git status we can see that no changes appear to the branch and we can change branches without the need to commit unstable code and messing our project history. After we finished fixing the bug we checkout the original branch at which we started the feature and we can run git stash apply to add back the changes to the branch.
Other scenarios
There are other scenarios when we might use git stash. For example we started to implement a new feature on a wrong branch. Again git stash helps us, we can run this command and create a new branch using git checkout -b some_new_branch or on an existing branch using git checkout some_existing_branch, now we can run git stash apply and the code which was not commit on the previous branch appears now on the new one.
We can also stash multiple set of changes and you can see them using git stash list, if we want to apply changes from a specific stash we can do git stash apply stash@{stash number}
Saturday, August 24, 2013
Symfony2 routing tip
Symfony2 routing tip
Did you ever needed to make the default value to NULL of a routing parameter when using XML for symfony2?
Here is a sample configuration
<route id="acme_user_show" pattern="/{id}">
<default key="_controller">AcmeUserBundle:User:show</default>
<default key="id" xsi:nil="true" />
</route>
Subscribe to:
Posts (Atom)