Skip to content

Commit

Permalink
support for php 5.6
Browse files Browse the repository at this point in the history
  • Loading branch information
tmilos committed Dec 21, 2016
1 parent 66a8d65 commit 1839ca3
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 58 deletions.
14 changes: 12 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
language: php

php:
- 5.6
- 7.0
- 7.1
- hhvm

matrix:
fast_finish: true
allow_failures:
- php: hhvm

before_install:
- composer self-update
- composer --version
- wget http://get.sensiolabs.org/php-cs-fixer.phar -O php-cs-fixer.phar
- if [ "$TRAVIS_PHP_VERSION" == "7.0" ]; then wget http://get.sensiolabs.org/php-cs-fixer.phar -O php-cs-fixer.phar; fi
- if [ "$TRAVIS_PHP_VERSION" == "7.0" ]; then php php-cs-fixer.phar --version; fi

install:
- COMPOSER_ROOT_VERSION=dev-master composer update --prefer-source

script:
- if [ "$TRAVIS_PHP_VERSION" == "7.0" ]; then php php-cs-fixer.phar fix --dry-run -v; fi
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml
- if [ "$TRAVIS_PHP_VERSION" == "7.0" ]; then vendor/bin/phpunit --coverage-clover build/logs/clover.xml; fi
- if [ "$TRAVIS_PHP_VERSION" != "7.0" ]; then vendor/bin/phpunit; fi

after_script:
- if [ "$TRAVIS_PHP_VERSION" == "7.0" ]; then vendor/bin/coveralls -v; fi
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
},
"require": {
"php": ">=7.0"
"php": ">=5.6.0"
},
"require-dev": {
"phpunit/phpunit": "~4.8|~5.6",
Expand Down
2 changes: 0 additions & 2 deletions src/Tmilos/Context/Action.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Tmilos/Context package.
*
Expand Down
2 changes: 0 additions & 2 deletions src/Tmilos/Context/Action/AbstractWrappedAction.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Tmilos/Context package.
*
Expand Down
4 changes: 1 addition & 3 deletions src/Tmilos/Context/Action/ActionMapper.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Tmilos/Context package.
*
Expand All @@ -22,5 +20,5 @@ interface ActionMapper
*
* @return Action
*/
public function __invoke(Action $action): Action;
public function __invoke(Action $action);
}
6 changes: 2 additions & 4 deletions src/Tmilos/Context/Action/ArrayCompositeAction.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Tmilos/Context package.
*
Expand Down Expand Up @@ -34,7 +32,7 @@ public function __construct(array $actions = [])
}
}

public function getActions(): array
public function getActions()
{
return $this->actions;
}
Expand All @@ -58,7 +56,7 @@ public function map($mapper)
}
}

public function dump(): array
public function dump()
{
$result = [];
foreach ($this->actions as $action) {
Expand Down
2 changes: 0 additions & 2 deletions src/Tmilos/Context/Action/CatchableErrorAction.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Tmilos/Context package.
*
Expand Down
4 changes: 1 addition & 3 deletions src/Tmilos/Context/Action/CompositeAction.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Tmilos/Context package.
*
Expand Down Expand Up @@ -35,5 +33,5 @@ public function map($mapper);
/**
* @return Action[]
*/
public function getActions(): array;
public function getActions();
}
2 changes: 0 additions & 2 deletions src/Tmilos/Context/Action/NullAction.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Tmilos/Context package.
*
Expand Down
16 changes: 7 additions & 9 deletions src/Tmilos/Context/Context.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Tmilos/Context package.
*
Expand Down Expand Up @@ -31,45 +29,45 @@ public function getTopParent();
*
* @return mixed|Context
*/
public function get(string $name, $default = null);
public function get($name, $default = null);

/**
* @param string $name
* @param string $class
*
* @return Context|mixed
*/
public function getOrCreate(string $name, string $class);
public function getOrCreate($name, $class);

/**
* @param string $name
* @param callable $callable
*
* @return Context|mixed
*/
public function getOrCall(string $name, callable $callable);
public function getOrCall($name, $callable);

/**
* @param string $name
*
* @return bool
*/
public function has(string $name): bool;
public function has($name);

/**
* @param string $name
* @param Context|mixed $value
*
* @return void
*/
public function set(string $name, $value);
public function set($name, $value);

/**
* @param string $name
*
* @return Context|mixed|null
*/
public function remove(string $name);
public function remove($name);

/**
* @return void
Expand All @@ -79,5 +77,5 @@ public function clear();
/**
* @return array
*/
public function toArray(): array;
public function toArray();
}
24 changes: 11 additions & 13 deletions src/Tmilos/Context/Context/ArrayContext.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Tmilos/Context package.
*
Expand Down Expand Up @@ -42,12 +40,12 @@ protected function setParent(Context $parent = null)
$this->parent = $parent;
}

public function get(string $name, $default = null)
public function get($name, $default = null)
{
return array_key_exists($name, $this->items) ? $this->items[$name] : $default;
}

public function getOrCreate(string $name, string $class)
public function getOrCreate($name, $class)
{
$result = $this->get($name);
if (!$result) {
Expand All @@ -64,7 +62,7 @@ public function getOrCreate(string $name, string $class)
return $this->items[$name];
}

public function getOrCall(string $name, callable $callable)
public function getOrCall($name, $callable)
{
$result = $this->get($name);
if (!$result) {
Expand All @@ -78,22 +76,22 @@ public function getOrCall(string $name, callable $callable)
return $this->items[$name];
}

public function has(string $name): bool
public function has($name)
{
return array_key_exists($name, $this->items);
}

public function toArray(): array
public function toArray()
{
return $this->doDump(false);
}

public function dump(): array
public function dump()
{
return $this->doDump(true);
}

public function set(string $name, $value)
public function set($name, $value)
{
$existing = isset($this->items[$name]) ? $this->items[$name] : null;
if ($existing === $value) {
Expand All @@ -108,7 +106,7 @@ public function set(string $name, $value)
}
}

public function remove(string $name)
public function remove($name)
{
$result = null;
if (array_key_exists($name, $this->items)) {
Expand All @@ -133,17 +131,17 @@ public function clear()
$this->items = [];
}

public function getIterator(): \ArrayIterator
public function getIterator()
{
return new \ArrayIterator($this->items);
}

public function count(): int
public function count()
{
return count($this->items);
}

private function doDump(bool $includeClass): array
private function doDump($includeClass)
{
$result = [];
if ($includeClass) {
Expand Down
4 changes: 1 addition & 3 deletions src/Tmilos/Context/Context/ExceptionContext.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Tmilos/Context package.
*
Expand Down Expand Up @@ -32,7 +30,7 @@ public function __construct(\Exception $exception = null)
/**
* @return \Exception
*/
public function getException(): \Exception
public function getException()
{
return $this->exception;
}
Expand Down
4 changes: 1 addition & 3 deletions src/Tmilos/Context/Dumpable.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Tmilos/Context package.
*
Expand All @@ -18,5 +16,5 @@ interface Dumpable
/**
* @return array
*/
public function dump(): array;
public function dump();
}
32 changes: 24 additions & 8 deletions tests/Tests/Tmilos/Context/Action/AbstractWrappedActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class AbstractWrappedActionTest extends \PHPUnit_Framework_TestCase
{
public function test_calls_inner_execute()
{
$context = $this->createMock(Context::class);
$innerAction = $this->createMock(Action::class);
$context = $this->getContextMock();
$innerAction = $this->getActionMock();
$action = $this->getAbstractWrappedActionMock($innerAction);

$innerAction->expects($this->once())
Expand All @@ -23,8 +23,8 @@ public function test_calls_inner_execute()

public function test_before_action_is_called()
{
$context = $this->createMock(Context::class);
$innerAction = $this->createMock(Action::class);
$context = $this->getContextMock();
$innerAction = $this->getActionMock();
$action = $this->getAbstractWrappedActionMock($innerAction);

$action->expects($this->once())
Expand All @@ -36,8 +36,8 @@ public function test_before_action_is_called()

public function test_after_action_is_called()
{
$context = $this->createMock(Context::class);
$innerAction = $this->createMock(Action::class);
$context = $this->getContextMock();
$innerAction = $this->getActionMock();
$action = $this->getAbstractWrappedActionMock($innerAction);

$action->expects($this->once())
Expand All @@ -49,8 +49,8 @@ public function test_after_action_is_called()

public function test_order_of_calls()
{
$context = $this->createMock(Context::class);
$innerAction = $this->createMock(Action::class);
$context = $this->getContextMock();
$innerAction = $this->getActionMock();
$action = $this->getAbstractWrappedActionMock($innerAction);

$calls = [];
Expand Down Expand Up @@ -88,4 +88,20 @@ private function getAbstractWrappedActionMock(Action $innerAction)
->getMock()
;
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject|Context
*/
private function getContextMock()
{
return $this->createMock(Context::class);
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject|Action
*/
private function getActionMock()
{
return $this->createMock(Action::class);
}
}
10 changes: 9 additions & 1 deletion tests/Tests/Tmilos/Context/Action/NullActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ class NullActionTest extends \PHPUnit_Framework_TestCase
public function test_can_be_executed()
{
$action = new NullAction();
$action->execute($this->createMock(Context::class));
$action->execute($this->getContextMock());
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject|Context
*/
private function getContextMock()
{
return $this->createMock(Context::class);
}
}

0 comments on commit 1839ca3

Please sign in to comment.