Skip to content

Commit

Permalink
adding grumphp, fixing style, narrowing namespace, fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydiablo committed Apr 30, 2018
1 parent 21bd95f commit ac6d6c4
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 16 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-pagination
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
22 changes: 22 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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' => ['align_double_arrow' => true, 'align_equals' => true],
'single_quote' => true,
'array_syntax' => ['syntax' => 'long'],
'concat_space' => ['spacing' => 'one'],
'psr0' => true
])
->setUsingCache(true)
->setFinder($finder);
;
16 changes: 12 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ branches:
only:
master

before_install:
- travis_retry composer self-update

install:
- phpenv rehash
- travis_retry composer install --no-interaction --prefer-source
Expand All @@ -37,15 +34,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=476a8902e500ab994a2932b058650b17cf22c90516bc3d061774a6517664fd52
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
21 changes: 13 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
"require": {
"php": ">=7.0.0",
"diablomedia/zendframework1-paginator": "^1.0.0",
"diablomedia/zendframework1-view": "^1.0.0"
"diablomedia/zendframework1-view": "^1.0.0",
"diablomedia/zendframework1-view-helper-partial": "^1.0.0"
},
"autoload": {
"psr-0": {
"Zend_": "src/"
}
"classmap": [
"src/Zend/View/Helper/PaginationControl.php"
]
},
"autoload-dev": {
"psr-0": {
Expand All @@ -30,14 +31,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 -l7 -c phpstan.neon --no-progress ./src --ansi"
"test": "phpunit",
"test-with-coverage": "phpunit --coverage-clover=clover.xml",
"phpstan": "phpstan analyze -l7 -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: 7
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,3 +1,6 @@
parameters:
excludes_analyse:
- %rootDir%/../../../vendor/*
- %rootDir%/../../../tests/*
ignoreErrors:
- '#Call to an undefined method Zend_View_Interface::partial\(\)\.#'
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
1 change: 0 additions & 1 deletion src/Zend/View/Helper/PaginationControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public function paginationControl(Zend_Paginator $paginator = null, $scrollingSt
if (isset($this->view->paginator) and $this->view->paginator !== null and $this->view->paginator instanceof Zend_Paginator) {
$paginator = $this->view->paginator;
} else {

$e = new Zend_View_Exception('No paginator instance provided or incorrect type');
$e->setView($this->view);
throw $e;
Expand Down
24 changes: 22 additions & 2 deletions tests/Zend/View/Helper/PaginationControlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ public function testAcceptsViewPartialInOtherModule()
*/
public function testUsesPaginatorFromViewOnlyIfNoneSupplied()
{
$this->_viewHelper->view->paginator = $this->_paginator;
$paginator = Zend_Paginator::factory(range(1, 30));
$this->_viewHelper->view->paginator = $this->_paginator;
$paginator = Zend_Paginator::factory(range(1, 30));
Zend_View_Helper_PaginationControl::setDefaultViewPartial('testPagination.phtml');

$output = $this->_viewHelper->paginationControl($paginator);
Expand All @@ -191,4 +191,24 @@ public function testCanUseObjectForScrollingStyle()

$this->assertContains('page count (11) equals pages in range (11)', $output, $output);
}

public function testRenders()
{
$this->expectException(Zend_View_Exception::class);
$this->expectExceptionMessage('No view partial provided and no default set');
$this->_paginator->render(new Zend_View());
}

public function testRendersWithPartial()
{
$view = new Zend_View();
$view->addBasePath(dirname(__FILE__) . '/_files');

Zend_View_Helper_PaginationControl::setDefaultViewPartial('partial.phtml');

$this->_paginator->setView($view);

$string = $this->_paginator->__toString();
$this->assertEquals('partial rendered successfully', $string);
}
}
1 change: 1 addition & 0 deletions tests/Zend/View/Helper/_files/scripts/partial.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
partial rendered successfully

0 comments on commit ac6d6c4

Please sign in to comment.