Skip to content

New tests, TagArrayToStringTransformer #501

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

Merged
merged 12 commits into from
Mar 14, 2017
Merged

New tests, TagArrayToStringTransformer #501

merged 12 commits into from
Mar 14, 2017

Conversation

Grafikart
Copy link
Contributor

Added some tests to demonstrate how to mock a Repository and test things without the database

Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

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

👍 if possible, please add a test condition for the usual mistake of adding too many commas (or empty tags). Example: Hello, Demo,, How and Hello, Demo, How,

@Grafikart
Copy link
Contributor Author

@javiereguiluz the array_map, array_filter, explode is getting out of control, how would you improve the readability of this ? I wanted to avoid Intermediary variables :(

@javiereguiluz
Copy link
Member

javiereguiluz commented Mar 13, 2017

@Grafikart array_filter without arguments filters empty elements (I learned this nice trick here: http://stackoverflow.com/a/3654309/2804294) I don't know if it's readable ... but i's a bit shorter/simpler. Thanks!

@Grafikart
Copy link
Contributor Author

Nice tip indeed

}

/**
* Spaces at the end (and begining) of a world shouldn't matter.

Choose a reason for hiding this comment

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

beginning :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Member

@yceruto yceruto left a comment

Choose a reason for hiding this comment

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

👍

@@ -54,7 +54,7 @@ public function reverseTransform($string)
return [];
}

$names = explode(',', $string);
$names = array_filter(array_unique(array_map('trim', explode(',', $string))));
Copy link
Member

@yceruto yceruto Mar 13, 2017

Choose a reason for hiding this comment

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

The tagsinput plugins itself does not allows duplicated, empty tags, extra spaces, double comma (on client side), BUT it could be hacked :) so I'm 👍 to check this on server side as double validation. Maybe I would add strtolower also to keep consistency with current ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure about strtolower, for instance I want my "JavaScript", "WordPress" tags to keep the upcases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could still add this transformation within the constructor

public function __construct(ObjectManager $manager, $forceStrToLower = false)

Copy link
Member

Choose a reason for hiding this comment

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

Let's keep things simple and let's not add the $forceStrToLower option.

*/
public function testUsesAlreadyDefinedTags()
{
$persisted_tags = [
Copy link
Member

@yceruto yceruto Mar 13, 2017

Choose a reason for hiding this comment

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

Use camelCase, not underscores, for variable :) (Ref.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops, linter didn't caught this one ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed with the next commit

@@ -0,0 +1,117 @@
<?php

Copy link
Member

Choose a reason for hiding this comment

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

Missing license docblock.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed with the next commit

Copy link
Member

@yceruto yceruto Mar 13, 2017

Choose a reason for hiding this comment

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

*
* See http://symfony.com/doc/current/testing/database.html
*
* @author Jonathan Boyer <[email protected]>
Copy link
Member

@yceruto yceruto Mar 13, 2017

Choose a reason for hiding this comment

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

@author AFAIK it's not common in tests classes, instead you can move it to TagArrayToStringTransformer class ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh right misinterpreted the last review :) fixing it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the link should stay here to explain how mocks work. I remove the @author only right ?

Copy link
Member

Choose a reason for hiding this comment

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

That's right.

Symfony policy is to *not* add the authors in test files. Personally I don't agree ... but in this repo we must follow the Symfony practices. That's why I removed you from here ... but I added you in the PHP class associated with this test.
* Moved the helper methods at the end of the file and made them `private`
* Minor changes to match the code style of the other tests
Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

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

👍

@javiereguiluz
Copy link
Member

It's merged now! Thanks @Grafikart for your contribution!

@javiereguiluz javiereguiluz merged commit ae2391f into symfony:master Mar 14, 2017
javiereguiluz added a commit that referenced this pull request Mar 14, 2017
…reguiluz)

This PR was merged into the master branch.

Discussion
----------

New tests, TagArrayToStringTransformer

Added some tests to demonstrate how to mock a Repository and test things without the database

Commits
-------

ae2391f Fixed code syntax issue reported by Travis CI
15a8d39 Minor changes
0f14c57 Added the missing license header and removed the author info
75734c6 Added Jonathan to the list of authors
e3ab52c Fixed more typos
b596f77 Fixed typo
72a0f85 Simplified code
3e891f5 Created a new case
f69514a Merge remote-tracking branch 'origin/tag-test' into tag-test
2ca2e9b Fixed some typos
55d5bb4 Simplified some code
a8de079 New tests, TagArrayToStringTransformer
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.

4 participants