Skip to content

Commit

Permalink
Merge pull request #3 from hollodotme/master
Browse files Browse the repository at this point in the history
Add PHPStan to build tools
  • Loading branch information
hollodotme committed Oct 21, 2018
2 parents ac54cb5 + f36289c commit 3881691
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 67 deletions.
3 changes: 0 additions & 3 deletions .coveralls.yml

This file was deleted.

28 changes: 16 additions & 12 deletions .travis.yml
@@ -1,27 +1,31 @@
language: php

php:
- 7.0
- 7.1
- 7.2
- 7.1snapshot
- 7.2snapshot

branches:
only:
- master
- development
- /^feature\/.+$/
- /^issue\/.+$/
- master
- development
- /^feature\/.+$/
- /^issue\/.+$/

before_script:
- git checkout $TRAVIS_BRANCH
- composer self-update
- mkdir -p vendor/bin
- composer install -o --prefer-dist --no-interaction
- mkdir build/logs
- git checkout $TRAVIS_BRANCH
- composer self-update
- mkdir -p vendor/bin
- composer install -o --prefer-dist --no-interaction
- mkdir build/logs

script:
- php vendor/bin/phpunit.phar -c build/
- php vendor/bin/phpunit.phar -c build/ --coverage-clover build/logs/clover.xml
- php vendor/bin/phpstan.phar analyze --level max src

after_success:
- travis_retry php vendor/bin/coveralls.phar -v --exclude-no-stmt
- travis_retry php vendor/bin/coveralls.phar -v --exclude-no-stmt

notifications:
slack: fortunesolutions:PoLjMJuARdFicBIEPzdNrZ96
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -5,6 +5,7 @@
[![Total Downloads](https://poser.pugx.org/icehawk/session/downloads)](https://packagist.org/packages/icehawk/session)
[![Latest Unstable Version](https://poser.pugx.org/icehawk/session/v/unstable)](https://packagist.org/packages/icehawk/session)
[![License](https://poser.pugx.org/icehawk/session/license)](https://packagist.org/packages/icehawk/session)
[![phpstan enabled](https://img.shields.io/badge/phpstan-enabled-green.svg)](https://github.com/phpstan/phpstan)

# ![IceHawk Framework](https://icehawk.github.io/images/Logo-Flying-Tail-White.png)

Expand Down
44 changes: 17 additions & 27 deletions build/phpunit.xml
@@ -1,29 +1,19 @@
<phpunit
bootstrap="../tests/Unit/bootstrap.php"
verbose="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestSize="true"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true">
<testsuites>
<testsuite name="IceHawkSession">
<directory suffix="Test.php">../tests/Unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">../src</directory>
</whitelist>
<blacklist>
<directory suffix=".php">../tests/Unit</directory>
<directory>../tests/Unit/Fixtures</directory>
<directory>../vendor</directory>
</blacklist>
</filter>
<logging>
<log type="coverage-html" target="logs/coverage"/>
<log type="coverage-clover" target="logs/clover.xml"/>
</logging>
bootstrap="../tests/bootstrap.php"
verbose="true"
beStrictAboutOutputDuringTests="true"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true">
<testsuites>
<testsuite name="IceHawkSession">
<directory suffix="Test.php">../tests/Unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">../src</directory>
</whitelist>
</filter>
</phpunit>
14 changes: 9 additions & 5 deletions composer.json
Expand Up @@ -27,7 +27,7 @@
},
"autoload-dev": {
"psr-4": {
"IceHawk\\Session\\Tests\\Unit\\": "tests/Unit/"
"IceHawk\\Session\\Tests\\": "tests/"
}
},
"scripts": {
Expand All @@ -37,19 +37,23 @@
"extra": {
"tools": {
"phpunit": {
"url": "https://phar.phpunit.de/phpunit.phar",
"url": "https://phar.phpunit.de/phpunit-7.phar",
"only-dev": true
},
"phpmetrics": {
"url": "https://github.com/phpmetrics/PhpMetrics/raw/master/build/phpmetrics.phar",
"url": "https://github.com/phpmetrics/PhpMetrics/releases/download/v2.4.1/phpmetrics.phar",
"only-dev": true
},
"phpdox": {
"url": "https://github.com/theseer/phpdox/releases/download/0.8.1.1/phpdox-0.8.1.1.phar",
"url": "https://github.com/theseer/phpdox/releases/download/0.11.2/phpdox-0.11.2.phar",
"only-dev": true
},
"coveralls": {
"url": "https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar",
"url": "https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar",
"only-dev": true
},
"phpstan": {
"url": "https://github.com/phpstan/phpstan/releases/download/0.10.5/phpstan.phar",
"only-dev": true
}
}
Expand Down
16 changes: 8 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions src/AbstractSession.php
@@ -1,4 +1,4 @@
<?php declare(strict_types = 1);
<?php declare(strict_types=1);
/**
* Copyright (c) 2016 Holger Woltersdorf & Contributors
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -14,6 +14,7 @@
namespace IceHawk\Session;

use IceHawk\Session\Interfaces\MapsSessionData;
use function in_array;

/**
* Class AbstractSession
Expand All @@ -24,10 +25,10 @@ abstract class AbstractSession
/** @var array */
private $sessionData;

/** @var array|MapsSessionData[] */
/** @var array */
private $keyDataMappers;

/** @var array|MapsSessionData[] */
/** @var array */
private $globalDataMappers;

public function __construct( array &$sessionData )
Expand All @@ -39,7 +40,7 @@ public function __construct( array &$sessionData )

final public function addDataMapper( MapsSessionData $dataMapper, array $keys = [] )
{
if ( empty($keys) )
if ( empty( $keys ) )
{
$this->addGlobalDataMapper( $dataMapper );
}
Expand All @@ -54,17 +55,17 @@ final public function addDataMapper( MapsSessionData $dataMapper, array $keys =

private function addGlobalDataMapper( MapsSessionData $dataMapper )
{
if ( !in_array( $dataMapper, $this->globalDataMappers ) )
if ( !in_array( $dataMapper, $this->globalDataMappers, false ) )
{
$this->globalDataMappers[] = $dataMapper;
}
}

private function addKeyDataMapper( MapsSessionData $dataMapper, string $key )
{
if ( isset($this->keyDataMappers[ $key ]) )
if ( isset( $this->keyDataMappers[ $key ] ) )
{
if ( !in_array( $dataMapper, $this->keyDataMappers[ $key ] ) )
if ( !in_array( $dataMapper, $this->keyDataMappers[ $key ], false ) )
{
$this->keyDataMappers[ $key ][] = $dataMapper;
}
Expand Down Expand Up @@ -131,12 +132,12 @@ private function mapValueFromSessionData( string $key )

final protected function isset( string $key ) : bool
{
return isset($this->sessionData[ $key ]);
return isset( $this->sessionData[ $key ] );
}

final protected function unset( string $key )
{
unset($this->sessionData[ $key ]);
unset( $this->sessionData[ $key ] );
}

public function clear()
Expand Down
37 changes: 35 additions & 2 deletions tests/Unit/AbstractSessionTest.php
@@ -1,4 +1,4 @@
<?php declare(strict_types = 1);
<?php declare(strict_types=1);
/**
* Copyright (c) 2016 Holger Woltersdorf & Contributors
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -15,9 +15,14 @@

use IceHawk\Session\Tests\Unit\Fixtures\DataMapper;
use IceHawk\Session\Tests\Unit\Fixtures\Session;
use PHPUnit\Framework\TestCase;

class AbstractSessionTest extends \PHPUnit_Framework_TestCase
class AbstractSessionTest extends TestCase
{
/**
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testCanSetValue()
{
$sessionData = [];
Expand All @@ -28,6 +33,10 @@ public function testCanSetValue()
$this->assertEquals( 'Unit-Test', $sessionData[ Session::UNIT_TEST_KEY ] );
}

/**
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testCanGetValue()
{
$sessionData = [Session::UNIT_TEST_KEY => 'Unit-Test'];
Expand All @@ -36,6 +45,10 @@ public function testCanGetValue()
$this->assertEquals( 'Unit-Test', $session->getUnitTestValue() );
}

/**
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testCanCheckIfKeyIsset()
{
$sessionData = [Session::UNIT_TEST_KEY => 'Unit-Test'];
Expand All @@ -44,6 +57,10 @@ public function testCanCheckIfKeyIsset()
$this->assertTrue( $session->issetUnitTestValue() );
}

/**
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testCanUnsetValue()
{
$sessionData = [Session::UNIT_TEST_KEY => 'Unit-Test'];
Expand All @@ -55,6 +72,10 @@ public function testCanUnsetValue()
$this->assertNull( $session->getUnitTestValue() );
}

/**
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testCanMapAllValues()
{
$sessionData = [];
Expand All @@ -67,6 +88,10 @@ public function testCanMapAllValues()
$this->assertEquals( 'Unit-Test', $session->getUnitTestValue() );
}

/**
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testCanMapSpecificValues()
{
$sessionData = [];
Expand All @@ -79,6 +104,10 @@ public function testCanMapSpecificValues()
$this->assertEquals( 'Unit-Test', $session->getUnitTestValue() );
}

/**
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testSpecificMappingHappensFirst()
{
$sessionData = [];
Expand All @@ -94,6 +123,10 @@ public function testSpecificMappingHappensFirst()
$this->assertEquals( 'Unit-Test', $session->getUnitTestValue() );
}

/**
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testCanClearSession()
{
$sessionData = [Session::UNIT_TEST_KEY => 'value'];
Expand Down
16 changes: 15 additions & 1 deletion tests/Unit/bootstrap.php → tests/bootstrap.php
Expand Up @@ -11,4 +11,18 @@
* all copies or substantial portions of the Software.
*/

require(__DIR__ . '/../../vendor/autoload.php');
if (
extension_loaded( 'xdebug' )
&& version_compare( '2.6.0', phpversion( 'xdebug' ), '<=' )
)
{
/** @noinspection PhpUndefinedFunctionInspection */
/** @noinspection PhpUndefinedConstantInspection */
xdebug_set_filter(
XDEBUG_FILTER_CODE_COVERAGE,
XDEBUG_PATH_WHITELIST,
[dirname( __DIR__ ) . '/src']
);
}

require __DIR__ . '/../vendor/autoload.php';

0 comments on commit 3881691

Please sign in to comment.