Skip to content

Commit

Permalink
adding grumphp, fixing style, narrowing autoload namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydiablo committed Jun 5, 2018
1 parent 30c1118 commit 960be79
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .github/settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
repository:
name: zf1-view-helper-partial
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor
/composer.lock
/clover.xml
/clover.xml
.php_cs.cache
25 changes: 25 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->files()
->in(__DIR__)
;

return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'@PHPUnit60Migration:risky' => true,
'binary_operator_spaces' => [
'default' => 'align_single_space_minimal',
'operators' => ['||' => null, '&&' => null]
],
'single_quote' => true,
'array_syntax' => ['syntax' => 'long'],
'concat_space' => ['spacing' => 'one'],
'psr0' => true
])
->setUsingCache(true)
->setFinder($finder);
;
14 changes: 13 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ install:

stages:
- test
- style check
- phpstan analysis
- test with coverage

Expand All @@ -34,15 +35,26 @@ jobs:
allow_failures:
- php: nightly
include:
- stage: style check
php: 7.1
env: TMPDIR=/tmp USE_XDEBUG=false
script:
- composer style-check
- stage: phpstan analysis
php: 7.1
env: TMPDIR=/tmp USE_XDEBUG=false
script:
- composer phpstan
- stage: test with coverage
php: 7.1
env: TMPDIR=/tmp USE_XDEBUG=true
env: TMPDIR=/tmp USE_XDEBUG=true CC_TEST_REPORTER_ID=c8148e292affe8e53a9eee543314648bf2f27f9a394d128f6e7422b599301b12
before_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
script:
- composer test-with-coverage
after_success:
- bash <(curl -s https://codecov.io/bash) -f ./clover.xml
after_script:
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
20 changes: 14 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
},
"autoload": {
"psr-0": {
"Zend_": "src/"
}
"Zend_View_Helper_Partial_": "src/"
},
"classmap": [
"src/Zend/View/Helper/Partial.php",
"src/Zend/View/Helper/PartialLoop.php"
]
},
"autoload-dev": {
"psr-0": {
Expand All @@ -30,14 +34,18 @@
],
"require-dev": {
"phpunit/phpunit": "^6.0",
"phpstan/phpstan": "^0.9.2"
"phpstan/phpstan": "^0.9.2",
"friendsofphp/php-cs-fixer": "^2.11",
"maglnet/composer-require-checker": "^0.1.6 | ^0.2.1",
"phpro/grumphp": "^0.14.0"
},
"archive": {
"exclude": ["/tests"]
},
"scripts": {
"test": "phpunit ./tests",
"test-with-coverage": "phpunit --coverage-clover=clover.xml ./tests",
"phpstan": "phpstan analyze -l1 -c phpstan.neon --no-progress ./src --ansi"
"test": "phpunit",
"test-with-coverage": "phpunit --coverage-clover=clover.xml",
"phpstan": "phpstan analyze -l1 -c phpstan.neon --no-progress ./ --ansi",
"style-check": "php-cs-fixer fix --dry-run -vv"
}
}
16 changes: 16 additions & 0 deletions grumphp.yml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# grumphp.yml
parameters:
tasks:
composer:
strict: true
composer_require_checker: ~
phpcsfixer2:
allow_risky: true
config: .php_cs
phpstan:
level: 1
configuration: phpstan.neon
phpunit:
metadata:
priority: 100
always_execute: true
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
parameters:
excludes_analyse:
- %rootDir%/../../../vendor/*
- %rootDir%/../../../tests/*
ignoreErrors:
5 changes: 5 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
backupGlobals="true"
stderr="true"
colors="true">
<testsuites>
<testsuite name="default">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
Expand Down
3 changes: 1 addition & 2 deletions src/Zend/View/Helper/Partial.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ public function partial($name = null, $module = null, $model = null)
$viewsDir = dirname($moduleDir) . '/views';
$view->addBasePath($viewsDir);
} elseif ((null == $model) && (null !== $module)
&& (is_array($module) || is_object($module)))
{
&& (is_array($module) || is_object($module))) {
$model = $module;
}

Expand Down
17 changes: 8 additions & 9 deletions tests/Zend/View/Helper/PartialLoopTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Zend_View_Helper_PartialLoopTest extends PHPUnit\Framework\TestCase
public function setUp()
{
$this->basePath = dirname(__FILE__) . '/_files/modules';
$this->helper = new Zend_View_Helper_PartialLoop();
$this->helper = new Zend_View_Helper_PartialLoop();
Zend_Controller_Front::getInstance()->resetInstance();
}

Expand Down Expand Up @@ -310,8 +310,8 @@ public function testPartialLoopIncramentsPartialCounter()
$this->helper->setView($view);

$result = $this->helper->partialLoop('partialLoopCouter.phtml', $data);
foreach ($data as $key=>$item) {
$string = 'This is an iteration: ' . $item['message'] . ', pointer at ' . ($key+1);
foreach ($data as $key => $item) {
$string = 'This is an iteration: ' . $item['message'] . ', pointer at ' . ($key + 1);
$this->assertContains($string, $result);
}
}
Expand All @@ -335,14 +335,14 @@ public function testPartialLoopPartialCounterResets()
$this->helper->setView($view);

$result = $this->helper->partialLoop('partialLoopCouter.phtml', $data);
foreach ($data as $key=>$item) {
$string = 'This is an iteration: ' . $item['message'] . ', pointer at ' . ($key+1);
foreach ($data as $key => $item) {
$string = 'This is an iteration: ' . $item['message'] . ', pointer at ' . ($key + 1);
$this->assertContains($string, $result);
}

$result = $this->helper->partialLoop('partialLoopCouter.phtml', $data);
foreach ($data as $key=>$item) {
$string = 'This is an iteration: ' . $item['message'] . ', pointer at ' . ($key+1);
foreach ($data as $key => $item) {
$string = 'This is an iteration: ' . $item['message'] . ', pointer at ' . ($key + 1);
$this->assertContains($string, $result);
}
}
Expand All @@ -361,8 +361,7 @@ public function testPartialLoopSetsTotalCount()

$view = new Zend_View(
array(
'scriptPath' =>
$this->basePath . '/default/views/scripts'
'scriptPath' => $this->basePath . '/default/views/scripts'
)
);
$this->helper->setView($view);
Expand Down
10 changes: 5 additions & 5 deletions tests/Zend/View/Helper/PartialTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Zend_View_Helper_PartialTest extends PHPUnit\Framework\TestCase
public function setUp()
{
$this->basePath = dirname(__FILE__) . '/_files/modules';
$this->helper = new Zend_View_Helper_Partial();
$this->helper = new Zend_View_Helper_Partial();
Zend_Controller_Front::getInstance()->resetInstance();
}

Expand Down Expand Up @@ -152,11 +152,11 @@ public function testCloneViewReturnsDifferentViewInstance()
*/
public function testCloneViewClearsViewVariables()
{
$view = new Zend_View();
$view = new Zend_View();
$view->foo = 'bar';
$this->helper->setView($view);

$clone = $this->helper->cloneView();
$clone = $this->helper->cloneView();
$clonedVars = $clone->getVars();

$this->assertEmpty($clonedVars);
Expand All @@ -165,7 +165,7 @@ public function testCloneViewClearsViewVariables()

public function testObjectModelWithPublicPropertiesSetsViewVariables()
{
$model = new stdClass();
$model = new stdClass();
$model->foo = 'bar';
$model->bar = 'baz';

Expand Down Expand Up @@ -200,7 +200,7 @@ public function testObjectModelWithToArraySetsViewVariables()
public function testObjectModelSetInObjectKeyWhenKeyPresent()
{
$this->helper->setObjectKey('foo');
$model = new stdClass();
$model = new stdClass();
$model->footest = 'bar';
$model->bartest = 'baz';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
*/
class Foo_BazController extends Zend_Controller_Action
{

public function barOneAction()
{
// this is for testActionCalledWithinActionResetsResponseState
Expand All @@ -45,6 +44,4 @@ public function barThreeAction()
{
// this is for testActionCalledWithinActionResetsResponseState
}

}

0 comments on commit 960be79

Please sign in to comment.