Skip to content

Commit

Permalink
phpstan: Also analyze unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bnf committed Jan 28, 2019
1 parent f489bfb commit 58237f7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ script:
- find . -name \*.php ! -path "./.build/*" -exec php -l {} >/dev/null \;
- if [[ "$ANALYSIS" != 'true' ]]; then .build/vendor/bin/phpunit ; fi
- if [[ "$ANALYSIS" == 'true' ]]; then .build/vendor/bin/phpunit --coverage-text --coverage-clover clover.xml ; fi
- .build/vendor/bin/phpstan analyze
- if [[ "$ANALYSIS" == 'true' ]]; then .build/vendor/bin/phpstan analyze ; fi

after_success:
- if [[ "$ANALYSIS" == 'true' ]]; then travis_retry .build/vendor/bin/php-coveralls -v ; fi
37 changes: 19 additions & 18 deletions Tests/Unit/SetPageCacheHookTest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
namespace Qbus\SkipPageIsBeingGenerated\Tests\Unit;

use Prophecy\Prophecy\ObjectProphecy;
use Qbus\SkipPageIsBeingGenerated\Hooks\SetPageCacheHook;
use TYPO3\CMS\Core\Cache\Backend\RedisBackend;
use TYPO3\CMS\Core\Cache\Backend\BackendInterface;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
//use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

/**
Expand All @@ -27,8 +27,9 @@ class SetPageCacheHookTest extends UnitTestCase
protected $cacheBackendProphecy;

/**
* @var params
* @var array
*/
protected $params = [];

/**
* @var SetPageCacheHook
Expand All @@ -50,7 +51,7 @@ class SetPageCacheHookTest extends UnitTestCase
*/
protected $lifetime;

public function setUp()
public function setUp(): void
{
$cacheBackendProphecy = $this->prophesize();
$cacheBackendProphecy->willImplement(BackendInterface::class);
Expand Down Expand Up @@ -82,65 +83,65 @@ public function setUp()
];
}

public function testSetInvalidatesLifetime()
public function testSetInvalidatesLifetime(): void
{
$this->hook->set($this->params, $this->cacheFrontendProphecy->reveal());

$this->assertEquals(-1, $this->lifetime);
static::assertEquals(-1, $this->lifetime);
}

public function testSetInvalidatesLifetimeForRedis()
public function testSetInvalidatesLifetimeForRedis(): void
{
$this->cacheBackendProphecy->willExtend(RedisBackend::class);

$this->hook->set($this->params, $this->cacheFrontendProphecy->reveal());

$this->assertEquals(1, $this->lifetime);
$this->assertFalse($this->variable);
static::assertEquals(1, $this->lifetime);
static::assertFalse($this->variable);
}

public function testSetDoesNothingForNonTemporaryPageCache()
public function testSetDoesNothingForNonTemporaryPageCache(): void
{
unset($this->variable['temp_content']);

$this->hook->set($this->params, $this->cacheFrontendProphecy->reveal());

$this->assertEquals(30, $this->lifetime);
static::assertEquals(30, $this->lifetime);
}

public function testSetDoesNothingForNonPageCache()
public function testSetDoesNothingForNonPageCache(): void
{
$this->cacheFrontendProphecy->getIdentifier()->willReturn('cache_pagesection');

$this->hook->set($this->params, $this->cacheFrontendProphecy->reveal());

$this->assertEquals(30, $this->lifetime);
static::assertEquals(30, $this->lifetime);
}

public function testSetDoesNothingForRedirectsPageCache()
public function testSetDoesNothingForRedirectsPageCache(): void
{
$this->entryIdentifier = 'redirects';

$this->hook->set($this->params, $this->cacheFrontendProphecy->reveal());

$this->assertEquals(30, $this->lifetime);
static::assertEquals(30, $this->lifetime);
}

public function testSetDoesNothingForTitleTagPageCache()
public function testSetDoesNothingForTitleTagPageCache(): void
{
$this->entryIdentifier .= '-titleTag-record';

$this->hook->set($this->params, $this->cacheFrontendProphecy->reveal());

$this->assertEquals(30, $this->lifetime);
static::assertEquals(30, $this->lifetime);
}

public function testSetDoesNothingForMetatagPageCache()
public function testSetDoesNothingForMetatagPageCache(): void
{
$this->entryIdentifier .= '-metatag-html5';

$this->hook->set($this->params, $this->cacheFrontendProphecy->reveal());

$this->assertEquals(30, $this->lifetime);
static::assertEquals(30, $this->lifetime);
}
}
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
"require-dev": {
"typo3/testing-framework": "^2.0 || ^4.9",
"phpspec/prophecy": "^1.8",
"phpstan/phpstan": "^0.10",
"phpstan/phpstan-strict-rules": "^0.10",
"saschaegerer/phpstan-typo3": "^0.10.0",
"phpstan/phpstan": "^0.9 || ^0.10",
"phpstan/phpstan-strict-rules": "^0.9 || ^0.10",
"saschaegerer/phpstan-typo3": "0.9.x-dev || ^0.10.0",
"phpstan/phpstan-phpunit": "^0.9 || ^0.10",
"jangregor/phpstan-prophecy": "^0.1 || ^0.3",
"php-coveralls/php-coveralls": "^2.1"
},
"autoload": {
Expand Down
6 changes: 6 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
includes:
- .build/vendor/saschaegerer/phpstan-typo3/extension.neon
- .build/vendor/phpstan/phpstan-strict-rules/rules.neon
- .build/vendor/phpstan/phpstan-phpunit/extension.neon
- .build/vendor/jangregor/phpstan-prophecy/src/extension.neon

parameters:
level: max
ignoreErrors:
# phpstan-prophecy can not detect the implemented interface
- '^Parameter #2 \$frontend of method Qbus\\SkipPageIsBeingGenerated\\Hooks\\SetPageCacheHook::set()^'
paths:
- Classes
- Tests

0 comments on commit 58237f7

Please sign in to comment.