Skip to content
This repository was archived by the owner on Dec 8, 2017. It is now read-only.

Commit 5be532f

Browse files
author
Sam Parkinson
committed
Merge branch 'development'
2 parents 6ff9b2b + 60121aa commit 5be532f

24 files changed

+124
-83
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ cache:
1313

1414
before_script:
1515
- composer self-update
16-
- composer install --no-interaction --optimize-autoloader
16+
- composer install --no-interaction --optimize-autoloader --prefer-source
1717

1818
script:
1919
- vendor/bin/phpunit

CONTRIBUTING.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,40 @@ The following guidelines for contribution should be followed if you wish to subm
44

55
## Getting Started
66

7-
* Submit an [issue ticket](https://github.com/sjparkinson/static-review/issues) for your issue if one **does not** exist already
7+
* If you have found a bug, submit an [ticket][issues] for your issue if one **does not** exist already
88

9-
* Describe the issue and include steps to reproduce if it's a bug
9+
* Describe the issue and include steps to reproduce the problem
1010

1111
* If you are able and want to fix this, fork the repository on GitHub
1212

13-
## Making Changes
13+
* When adding a feature, feel free to [get in contact][twitter] before starting any development
14+
15+
[issues]: https://github.com/sjparkinson/static-review/issues
16+
[twitter]: https://twitter.com/samparkinson_
1417

15-
* In your forked repository, create a topic branch for your upcoming patch (e.g. `feature/autoplay` or `bugfix/ios-crash`)
18+
## Making Changes
1619

17-
* Usually this is based on the master branch
20+
* In your forked repository, create a topic branch for your upcoming patch (e.g. `feature/svn-support` or `bugfix/example-review-fix`)
1821

19-
* Create a branch based on master, but please **do not** work directly on the `master` branch
22+
* Create a branch based on `master`, but please **do not** work directly on the `master` branch
2023

2124
* Make sure you stick to the coding style that is used already
2225

23-
* If possible, submit unit tests with your patch / new feature so it can be tested easily
26+
* If possible, submit unit tests with your patch / new feature
27+
28+
* Ensure that nothing is broken by [running the test suite][test-suite]
2429

25-
* Ensure that nothing is broken by [running all the unit tests](https://github.com/sjparkinson/static-review/blob/development/README.md#unit-tests)
30+
[test-suite]: https://github.com/sjparkinson/static-review/blob/development/README.md#unit-tests)
2631

2732
## Submitting Changes
2833

2934
1. Push your changes to a topic branch in your fork of the repository
3035

31-
2. Open a pull request to merge to the original repository
36+
2. Open a pull request to merge to the [original repository][origin]
3237

33-
3. Lastly, please reference and update your original issue with the code changes
38+
[origin]: https://github.com/sjparkinson/static-review
3439

3540
# Additional Resources
3641

37-
* [General GitHub documentation](http://help.github.com/)
38-
* [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
42+
* [General GitHub documentation](http://help.github.com)
43+
* [GitHub pull request documentation](http://help.github.com/send-pull-requests)

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ Within a [composer][composer] managed project you can simply do the following...
1919

2020
```bash
2121
$ composer require sjparkinson/static-review:~1.0
22-
$ vendor/bin/static-review.php list hook
2322
```
2423

25-
Then you can add one of the hooks to your project like so...
24+
You can then add one of the hooks to your project like so...
2625

2726
```bash
2827
$ vendor/bin/static-review.php hook:install example-pre-commit .git/hooks/pre-commit

Vagrantfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# -*- mode: ruby -*-
22
# vi: set ft=ruby :
33

4-
# @see https://www.vagrantup.com
5-
64
Vagrant.configure("2") do |config|
75

86
# Box
@@ -15,9 +13,10 @@ Vagrant.configure("2") do |config|
1513
# Setup
1614
config.vm.provision :shell, :inline => "apt-get update --fix-missing"
1715
config.vm.provision :shell, :inline => "apt-get install -q -y cowsay python-software-properties python g++ make git curl"
18-
config.vm.provision :shell, :inline => "add-apt-repository ppa:ondrej/php5 && apt-get update"
16+
config.vm.provision :shell, :inline => "add-apt-repository ppa:ondrej/php5"
17+
config.vm.provision :shell, :inline => "apt-get update"
1918
config.vm.provision :shell, :inline => "apt-get install -q -y php5-cli php5-curl php5-xdebug"
20-
config.vm.provision :shell, :inline => "curl -s https://getcomposer.org/installer | php"
19+
config.vm.provision :shell, :inline => "curl -sS https://getcomposer.org/installer | php"
2120
config.vm.provision :shell, :inline => "mv ./composer.phar /usr/local/bin/composer"
2221

2322
# Done

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626

2727
"autoload-dev": {
2828
"psr-4": {
29-
"StaticReview\\Tests\\": "tests/"
29+
"StaticReview\\Test\\Unit\\": "tests/unit/",
30+
"StaticReview\\Test\\Functional\\": "tests/functional/"
3031
}
3132
},
3233

phpunit.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
<!-- Test suites -->
99
<testsuites>
1010
<testsuite name="unit">
11-
<directory>tests/</directory>
11+
<directory>tests/unit</directory>
12+
</testsuite>
13+
<testsuite name="functional">
14+
<directory>tests/functional</directory>
1215
</testsuite>
1316
</testsuites>
1417

src/Command/HookInstallCommand.php

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,47 @@
2121

2222
class HookInstallCommand extends Command
2323
{
24+
const ARGUMENT_TARGET = 'target';
25+
const ARGUMENT_LINK = 'link';
26+
2427
protected function configure()
2528
{
2629
$this->setName('hook:install');
2730

2831
$this->setDescription('Symlink a hook to the given target.');
2932

30-
$this->addArgument('target', InputArgument::REQUIRED, 'The hook to link, either a path to a file or the filename of a hook in the hooks folder.')
31-
->addArgument('link', InputArgument::REQUIRED, 'The target location, including the filename (e.g. .git/hooks/pre-commit).');
33+
$this->addArgument(self::ARGUMENT_TARGET, InputArgument::REQUIRED, 'The hook to link, either a path to a file or the filename of a hook in the hooks folder.')
34+
->addArgument(self::ARGUMENT_LINK, InputArgument::REQUIRED, 'The target location, including the filename (e.g. .git/hooks/pre-commit).');
3235

3336
$this->addOption('force', 'f', InputOption::VALUE_NONE, 'Overrite any existing files at the symlink target.');
3437
}
3538

3639
protected function execute(InputInterface $input, OutputInterface $output)
3740
{
41+
$hookArgument = $input->getArgument(self::ARGUMENT_TARGET);
42+
43+
$target = $this->getTargetPath($hookArgument);
44+
$link = $input->getArgument(self::ARGUMENT_LINK);
3845
$force = $input->getOption('force');
39-
$target = $this->getTargetPath($input);
40-
$link = $input->getArgument('link');
4146

4247
if ($output->isVeryVerbose()) {
43-
$message = sprintf('<info>Using %s for the hook target.</info>', $target);
48+
$message = sprintf('<info>Using %s for the install path.</info>', $link);
49+
$output->writeln($message);
50+
51+
$message = sprintf('<info>Using %s as the hook.</info>', $target);
4452
$output->writeln($message);
53+
}
4554

46-
$message = sprintf('<info>Using %s for the hook path.</info>', $link);
55+
if (! is_dir(dirname($link))) {
56+
$message = sprintf('<error>The directory at %s does not exist.</error>', $link);
4757
$output->writeln($message);
58+
exit(1);
4859
}
4960

5061
if (file_exists($link) && $force) {
5162
unlink($link);
5263

53-
$message = sprintf('<info>Removed existing file at %s.</info>', $link);
64+
$message = sprintf('<comment>Removed existing file at %s.</comment>', $link);
5465
$output->writeln($message);
5566
}
5667

@@ -66,16 +77,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
6677
}
6778

6879
/**
69-
* @param $input InputInterface
80+
* @param $hookArgument string
7081
* @return string
7182
*/
72-
protected function getTargetPath(InputInterface $input)
83+
protected function getTargetPath($hookArgument)
7384
{
74-
if (file_exists($input->getArgument('target'))) {
75-
$target = realpath($input->getArgument('target'));
85+
if (file_exists($hookArgument)) {
86+
$target = realpath($hookArgument);
7687
} else {
7788
$path = '%s/%s.php';
78-
$target = sprintf($path, realpath(__DIR__ . '/../../hooks/'), $input->getArgument('target'));
89+
$target = sprintf($path, realpath(__DIR__ . '/../../hooks/'), $hookArgument);
7990
}
8091

8192
if (! file_exists($target)) {

src/Command/HookListCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected function configure()
2424
{
2525
$this->setName('hook:list');
2626

27-
$this->setDescription('Lists all the avaliable hooks.');
27+
$this->setDescription('Lists all the included hooks.');
2828
}
2929

3030
protected function execute(InputInterface $input, OutputInterface $output)

src/Command/HookRunCommand.php

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,24 @@
2121

2222
class HookRunCommand extends Command
2323
{
24+
const ARGUMENT_HOOK = 'hook';
25+
2426
protected function configure()
2527
{
2628
$this->setName('hook:run');
2729

2830
$this->setDescription('Run the specified hook.');
2931

30-
$this->addArgument('hook', InputArgument::REQUIRED, 'The hook file to run.');
32+
$this->addArgument(self::ARGUMENT_HOOK, InputArgument::REQUIRED, 'The hook file to run.');
3133
}
3234

3335
protected function execute(InputInterface $input, OutputInterface $output)
3436
{
35-
$hooksPath = realpath(__DIR__ . '/../../hooks/');
36-
37-
$source = $hooksPath . '/' . $input->getArgument('hook') . '.php';
37+
$hookArg = $input->getArgument(self::ARGUMENT_HOOK);
38+
$path = $this->getTargetPath($hookArg);
3839

39-
if (file_exists($source)) {
40-
$cmd = 'php ' . $source;
40+
if (file_exists($hook)) {
41+
$cmd = 'php ' . $hook;
4142

4243
$process = new Process($cmd);
4344

@@ -46,4 +47,26 @@ protected function execute(InputInterface $input, OutputInterface $output)
4647
});
4748
}
4849
}
50+
51+
/**
52+
* @param $hookArgument string
53+
* @return string
54+
*/
55+
protected function getTargetPath($hookArgument)
56+
{
57+
if (file_exists($hookArgument)) {
58+
$target = realpath($hookArgument);
59+
} else {
60+
$path = '%s/%s.php';
61+
$target = sprintf($path, realpath(__DIR__ . '/../../hooks/'), $hookArgument);
62+
}
63+
64+
if (! file_exists($target)) {
65+
$error = sprintf('<error>The hook %s does not exist!</error>', $target);
66+
$output->writeln($error);
67+
exit(1);
68+
}
69+
70+
return $target;
71+
}
4972
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* @see http://github.com/sjparkinson/static-review/blob/master/LICENSE.md
1111
*/
1212

13-
namespace StaticReview\Tests\Collection;
13+
namespace StaticReview\Test\Unit\Collection;
1414

1515
use StaticReview\Collection\Collection;
1616

@@ -40,7 +40,7 @@ public function testConstructorWithArgument()
4040
$this->collection->__construct($items);
4141

4242
for ($i = 0; $i > count($this->collection); $i++) {
43-
$this->assertEquals($items[$i], $this->collection[$i]);
43+
$this->assertSame($items[$i], $this->collection[$i]);
4444
}
4545
}
4646

@@ -62,12 +62,12 @@ public function testAppendWithValidItem()
6262
$this->collection->append($item);
6363

6464
$this->assertCount(1, $this->collection);
65-
$this->assertEquals($item, $this->collection->current());
65+
$this->assertSame($item, $this->collection->current());
6666

6767
$this->collection->append($item);
6868

6969
$this->assertCount(2, $this->collection);
70-
$this->assertEquals($item, $this->collection->next());
70+
$this->assertSame($item, $this->collection->next());
7171
}
7272

7373
/**

0 commit comments

Comments
 (0)