-
-
Notifications
You must be signed in to change notification settings - Fork 142
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
Conform to PSR-2, add Composer/PHPUnit configs #11
Conversation
I'll hold off creating pull requests for the two new exercises until this is sorted as they are based off this branch. The exercises I have added the hamming exercise and UncleBob's bowling game kata to avoid anyone duplicating the effort. |
@@ -3,26 +3,29 @@ IGNOREDIRS := ".git|vendor|bin" | |||
ASSIGNMENTS = $(shell find . -maxdepth 1 -mindepth 1 -type d -not -path '*/\.*' | tr -d './' | sort | grep -Ev $(IGNOREDIRS)) | |||
|
|||
# output directories | |||
DIR := $(shell pwd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may be able to use the builtin $(CURDIR)
environment variable.
https://www.gnu.org/software/make/manual/html_node/Recursion.html
@wilmoore I've made that change, also I've changed it back to fetch phpunit and test with that passing the --no-configuration flag so it doesn't expect the autoloader to be there. I've also added a SETUP.md, assuming that composer.json and phpunit.xml will be available to the user in the {exercism download dir}/php dir. |
This looks good to me. I'm going to give the final word to @wilmoore since he's written PHP more recently than I have. |
Sounds good, I've added the leap problem to another branch for if/when this is merged. @kytrinyx is there the functionality in place at the moment to provide the composer.json & phpunit.xml files in the base directory of the language exercise folder? |
@for class in $(shell ls $(ASSIGNMENT)/*.php | grep -v Test); do \ | ||
echo "<?php require_once '$(CURDIR)/$$class'; ?>" >> $(OUTDIR)/$(TSTFILE); \ | ||
done | ||
@sed -e "/$this->markTestSkipped/d" -e "/namespace/d" $(ASSIGNMENT)/*Test.$(FILEEXT) >> $(OUTDIR)/$(TSTFILE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I love this methodology. I think we could do better by utilizing phpunit's @group
in tandem with --group
and/or --group-exclude
cli options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So instead of marking the tests as skipped give them a group annotation such as @group skipped and ask the user to remove the annotation rather than the $this->markTestSkipped line?
So the user would run tests with (Edit: we can just specify it in the phpunit.xml so they don't have to pass it)
$ php vendor/bin/phpunit Exercise
The @group comment annotation would be easier/quicker to remove than removing a line inside the test method. I'll make another commit to switch to this method of excluding the other tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...give them a group annotation such as @group skipped and ask the user to remove the annotation rather than the $this->markTestSkipped line?
Yes, and also keep in mind that:
If phpunit.xml or phpunit.xml.dist (in that order) exist in the current working directory and --configuration is not used, the configuration will be automatically read from that file.
Which means we could potentially allow the user to not worry about it and utilize a phpunit.xml
that does what we want.
There's no support for that at the moment. It should be trivial to add it to the API side of things, and we'll need to add functionality to the CLI. That's not a big deal, it just means that we'll have to specify to people doing the PHP track that they'll need the most recent version of the CLI when they get started. |
I've added a couple of issues to add support for this: https://github.com/exercism/x-api/issues/27 |
|
||
public function __construct($decimal = '') | ||
{ | ||
$array = array_reverse(str_split((string)$decimal)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't a deal breaker, but my feeling is that there are a lot of nested parens here. Perhaps breaking it out would be nice.
Also, I believe that psr-1
doesn't like (string)$decimal
since there is no space between the paren and $decimal
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't really looked too much at these exercises, I just ran autoformat against them. What about if the cast was removed as it shouldn't be needed anyway?
$array = array_reverse(str_split($decimal));
I would even combine that to:
public function __construct($decimal = '')
{
$this->digits = array_map('intval', array_reverse(str_split($decimal)));
}
PSR-1/2 doesn't seem to care about the space between the cast, I couldn't find an example in the standards and CodeSniffer and PHPStorm rulesets do not point it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just ran autoformat against them
I generally feel like auto-formatting is great if the recipe is sharable. Perhaps we can use: https://github.com/fabpot/PHP-CS-Fixer
I like this because there are also dedicated plugins for multiple IDE/editors available or the CLI can be run directly.
Let's set this up since we've already moved in the direction of utilizing auto-formatting on the code.
What about if the cast was removed as it shouldn't be needed anyway?
Yes, let's drop it given it isn't really necessary.
I would even combine that to
👍
PSR-1/2 doesn't seem to care about the space between the cast...
I guess it's a moot point if we remove it though 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added PHP_CodeSniffer to the build so any violations should fail. I'm not sure how we could have PHP-CS-Fixer run, perhaps add a link to it in the README to make contributors aware of it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how we could have PHP-CS-Fixer run, perhaps add a link to it in the README to make contributors aware of it?
Yes, that should be good enough; though, seems like this may be better placed in the SETUP.md
file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better placed in the SETUP.md file
IIRC didn't @kytrinyx say we shouldn't influence the style used in users solutions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wilmoore this was the comment I was referring to, is there anything else needs to be done with this PR?
LGTM 👍 |
@jrdnull - just squash and I'll merge. |
@wilmoore squashed 👍 |
Update Makefile, add SETUP.md Add PHP CodeSniffer Use @group annotation to skip tests
Conform to PSR-2, add Composer/PHPUnit configs
Thanks a lot @jrdnull -- great work 👍 |
FYI, @jrdnull - I notice that the stuff in
When I run that, I get:
|
Have you created Trinary.php? You'll have to use the make test to run the tests against the Example.php's. I guess the instructions could be clearer. |
Yeah, there is that, plus I am not sure I love the re-writing of the source code. I'll try to work on this when I have some spare cycles. If you get to it first, that's even better. |
Additionally, I don't love having multiple ways to run the tests. I'd prefer to see either of:
But not both. |
The only way to avoid this is to remove autoloading and rename the file like it used to, or have an additional autoloader for the examples. Although this is a now a moot point due to #17.
We're still going to need two ways of running the tests to allow the CI to test against the example implementations. |
I should have been more specific. I could have summed it up by saying we need to get rid of the extra code re-writing which we do in #18. |
Conform to PSR-2, add Composer/PHPUnit configs
I've removed the two new exercises and squashed this into one commit, this PR reformat to PSR-2 standards.
The classes are now autoloaded with the phpunit.xml and composer.json provided. (This is done using Composer's autoloader)
The make file has been updated so only the tests are rewritten to the tmp dir and they are modified on the way to not skip tests and to require in the classes needed so it doesn't require an autoloader. (I'm sure this can be done in a nicer way as this is a bit hacky)
I am unsure how the CLI tool provides files, is it possible that when fetching PHP exercises that the composer.json & phpunit.xml are provided as well as perhaps a language specific README? That way when a user came to do some PHP exercises they would have a standard quick and easy way to get PHPUnit and the tests running. e.g:
Let me know any problems/improvements and I'll work on it.