Completed
Push — master ( 55fcad...fbf322 )
by Aimeos
05:08
created

SlimTest::setUp()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 24
rs 8.9713
cc 3
eloc 14
nc 4
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016
6
 */
7
8
9
namespace Aimeos\MW\View\Helper\Request;
10
11
12
class SlimTest extends \PHPUnit_Framework_TestCase
13
{
14
	private $object;
15
	private $mock;
16
17
18
	protected function setUp()
19
	{
20
		if( !interface_exists( '\Psr\Http\Message\ServerRequestInterface' ) ) {
21
			$this->markTestSkipped( '\Psr\Http\Message\ServerRequestInterface is not available' );
22
		}
23
24
		if( !class_exists( '\Slim\Route' ) ) {
25
			$this->markTestSkipped( '\Slim\Route is not available' );
26
		}
27
28
		$view = new \Aimeos\MW\View\Standard();
29
		$route = new \Slim\Route( array( 'GET' ), '/shop', null );
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
30
		$route->setName( 'route' );
31
32
		$this->mock = $this->getMock( '\Psr\Http\Message\ServerRequestInterface' );
33
34
		$this->mock->expects( $this->once() )->method( 'getAttribute' )
35
			->will( $this->returnValue( $route ) );
36
37
		$this->mock->expects( $this->once() )->method( 'getServerParams' )
38
			->will( $this->returnValue( array( 'REMOTE_ADDR' => '127.0.0.1' ) ) );
39
40
		$this->object = new \Aimeos\MW\View\Helper\Request\Slim( $view, $this->mock );
41
	}
42
43
44
	protected function tearDown()
45
	{
46
		unset( $this->object, $this->mock );
47
	}
48
49
50
	public function testTransform()
51
	{
52
		$this->assertInstanceOf( '\Aimeos\MW\View\Helper\Request\Slim', $this->object->transform() );
53
		$this->assertInstanceOf( '\Psr\Http\Message\ServerRequestInterface', $this->object->transform() );
54
	}
55
56
57
	public function testGetClientAddress()
58
	{
59
		$this->assertEquals( '127.0.0.1', $this->object->getClientAddress() );
60
	}
61
62
63
	public function testGetTarget()
64
	{
65
		$this->assertEquals( 'route', $this->object->getTarget() );
66
	}
67
}
68