Completed
Push — master ( c8cdf3...1aa220 )
by Aimeos
09:24
created

Laravel5Test::testSetMultiple()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 8
loc 8
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2016
6
 */
7
8
9
namespace Aimeos\MW\Cache;
10
11
12
class Laravel5Test extends \PHPUnit_Framework_TestCase
13
{
14
	private $object;
15
	private $mock;
16
17
18 View Code Duplication
	protected function setUp()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
	{
20
		if( interface_exists( '\\Illuminate\\Contracts\\Cache\\Store' ) === false ) {
21
			$this->markTestSkipped( 'Class \\Illuminate\\Contracts\\Cache\\Store not found' );
22
		}
23
24
		$this->mock = $this->getMockBuilder( '\\Illuminate\\Contracts\\Cache\\Store' )->getMock();
25
		$this->object = new \Aimeos\MW\Cache\Laravel5( $this->mock );
26
	}
27
28
29
	protected function tearDown()
30
	{
31
		unset( $this->mock, $this->object );
32
	}
33
34
35
	public function testDelete()
36
	{
37
		$this->mock->expects( $this->once() )->method( 'forget' )->with( $this->equalTo( 'key' ) );
38
		$this->object->delete( 'key' );
39
	}
40
41
42
	public function testDeleteMultiple()
43
	{
44
		$this->mock->expects( $this->exactly( 2 ) )->method( 'forget' )->with( $this->equalTo( 'key' ) );
45
		$this->object->deleteMultiple( array( 'key', 'key' ) );
46
	}
47
48
49
	public function testDeleteByTags()
50
	{
51
		$this->mock->expects( $this->once() )->method( 'flush' );
52
		$this->object->deleteByTags( array( 'tag', 'tag' ) );
53
	}
54
55
56
	public function testClear()
57
	{
58
		$this->mock->expects( $this->once() )->method( 'flush' );
59
		$this->object->clear();
60
	}
61
62
63 View Code Duplication
	public function testGet()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
	{
65
		$this->mock->expects( $this->once() )->method( 'get' )
66
			->with( $this->equalTo( 'key' ) )->will( $this->returnValue( 'value' ) );
67
68
		$this->assertEquals( 'value', $this->object->get( 'key', 'default' ) );
69
	}
70
71
72 View Code Duplication
	public function testGetDefault()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
	{
74
		$this->mock->expects( $this->once() )->method( 'get' )
75
			->with( $this->equalTo( 'key' ) )->will( $this->returnValue( null ) );
76
77
		$this->assertEquals( 'default', $this->object->get( 'key', 'default' ) );
78
	}
79
80
81 View Code Duplication
	public function testGetMultiple()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
82
	{
83
		$this->mock->expects( $this->exactly( 2 ) )->method( 'get' )
84
			->will( $this->returnValue( 'value' ) );
85
86
		$expected = array( 'key1' => 'value', 'key2' => 'value' );
87
		$this->assertEquals( $expected, $this->object->getMultiple( array( 'key1', 'key2' ) ) );
0 ignored issues
show
Documentation introduced by
array('key1', 'key2') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a object<Aimeos\MW\Cache\iterable>.

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...
88
	}
89
90
91
	public function testGetMultipleByTags()
92
	{
93
		$this->assertEquals( array(), $this->object->getMultipleByTags( array( 'key', 'key' ) ) );
94
	}
95
96
97 View Code Duplication
	public function testSet()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
98
	{
99
		$this->mock->expects( $this->once() )->method( 'put' )
100
			->with( $this->equalTo( 'key' ), $this->equalTo( 'value' ), $this->greaterThan( 0 ) );
101
102
		$this->object->set( 'key', 'value', '2100-01-01 00:00:00', array( 'tag' ) );
103
	}
104
105
106 View Code Duplication
	public function testSetForever()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
107
	{
108
		$this->mock->expects( $this->once() )->method( 'forever' )
109
			->with( $this->equalTo( 'key' ), $this->equalTo( 'value' ) );
110
111
		$this->object->set( 'key', 'value', null, array( 'tag' ) );
112
	}
113
114
115 View Code Duplication
	public function testSetMultiple()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
116
	{
117
		$this->mock->expects( $this->once() )->method( 'put' )
118
			->with( $this->equalTo( 'key' ), $this->equalTo( 'value' ), $this->greaterThan( 0 ) );
119
120
		$expires = array( 'key' => '2100-01-01 00:00:00' );
121
		$this->object->setMultiple( array( 'key' => 'value' ), $expires, array( 'key' => array( 'tag' ) ) );
0 ignored issues
show
Documentation introduced by
array('key' => 'value') is of type array<string,string,{"key":"string"}>, but the function expects a object<Aimeos\MW\Cache\iterable>.

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...
122
	}
123
}
124