Skip to content
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

Merged
merged 1 commit into from
Jul 11, 2014
Merged

Conform to PSR-2, add Composer/PHPUnit configs #11

merged 1 commit into from
Jul 11, 2014

Conversation

jrdnull
Copy link
Contributor

@jrdnull jrdnull commented Jul 7, 2014

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:

% curl -sS https://getcomposer.org/installer | php
% php composer.phar install
% php vendor/bin/phpunit [Exercise]

Let me know any problems/improvements and I'll work on it.

@jrdnull
Copy link
Contributor Author

jrdnull commented Jul 7, 2014

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)
Copy link

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

@jrdnull
Copy link
Contributor Author

jrdnull commented Jul 8, 2014

@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.

@kytrinyx
Copy link
Member

kytrinyx commented Jul 8, 2014

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.

@jrdnull
Copy link
Contributor Author

jrdnull commented Jul 8, 2014

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)
Copy link

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.

Copy link
Contributor Author

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.

Copy link

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.

@kytrinyx
Copy link
Member

kytrinyx commented Jul 8, 2014

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.

@kytrinyx
Copy link
Member

kytrinyx commented Jul 8, 2014

I've added a couple of issues to add support for this:

https://github.com/exercism/x-api/issues/27
exercism/cli#88


public function __construct($decimal = '')
{
$array = array_reverse(str_split((string)$decimal));
Copy link

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.

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 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.

Copy link

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 😄

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'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?

Copy link

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.

Copy link
Contributor Author

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?

Choose a reason for hiding this comment

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

IIRC didn't @kytrinyx say we shouldn't influence the style used in users solutions?

That may be true...if so, then so-be-it.

@kytrinyx -- would you prefer user style be fairly free-form?

Copy link
Contributor Author

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?

@jrdnull
Copy link
Contributor Author

jrdnull commented Jul 9, 2014

@wilmoore I think this should address all of the issues, I have created an issue to discuss the 5.6 features here: #12

Let me know if there is anything else, cheers.

@wilmoore
Copy link

Let me know if there is anything else, cheers

LGTM 👍

@wilmoore
Copy link

@jrdnull - just squash and I'll merge.

@jrdnull
Copy link
Contributor Author

jrdnull commented Jul 11, 2014

@wilmoore squashed 👍

Update Makefile, add SETUP.md
Add PHP CodeSniffer
Use @group annotation to skip tests
wilmoore added a commit that referenced this pull request Jul 11, 2014
Conform to PSR-2, add Composer/PHPUnit configs
@wilmoore wilmoore merged commit 33d23de into exercism:master Jul 11, 2014
@wilmoore
Copy link

Thanks a lot @jrdnull -- great work 👍

@wilmoore
Copy link

FYI, @jrdnull - I notice that the stuff in SETUP.md doesn't quite work for me. For example:

% php vendor/bin/phpunit Trinary

When I run that, I get:

PHP Fatal error: Class 'Exercism\Trinary\Trinary' not found...

@jrdnull
Copy link
Contributor Author

jrdnull commented Jul 11, 2014

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.

@wilmoore
Copy link

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.

@wilmoore
Copy link

I am not sure I love the re-writing of the source code

Additionally, I don't love having multiple ways to run the tests. I'd prefer to see either of:

  • make test-assignment ASSIGNMENT=AssignmentName
  • phpunit AssignmentName

But not both.

@jrdnull
Copy link
Contributor Author

jrdnull commented Jul 13, 2014

I am not sure I love the re-writing of the source code

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.

Additionally, I don't love having multiple ways to run the tests.

We're still going to need two ways of running the tests to allow the CI to test against the example implementations.

@wilmoore
Copy link

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.

wilmoore added a commit that referenced this pull request Aug 31, 2014
Conform to PSR-2, add Composer/PHPUnit configs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants