Completed
Pull Request — master (#14)
by Helpful
03:02
created

HybridSessionCookieTest::getStore()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 6
Ratio 100 %
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 6
loc 6
rs 9.4285
1
<?php
2
3
/**
4
 * Tests the {@see HybridSessionStore_Cookie} class
5
 */
6
class HybridSessionCookieTest extends HybridSessionAbstractTest {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
8
	/**
9
	 * @return HybridSessionStore_Cookie
10
	 */
11 View Code Duplication
	protected function getStore() {
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...
12
		$store = Injector::inst()->get('HybridSessionStore_Cookie');
13
		$store->setKey(uniqid());
14
		$store->open(getTempFolder().'/'.__CLASS__, 'SESSIONCOOKIE');
15
		return $store;
16
	}
17
18 View Code Duplication
	public function testStoreLargeData() {
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
		$session = uniqid();
20
		$store = $this->getStore();
21
22
		// Test new session is blank
23
		$result = $store->read($session);
24
		$this->assertEmpty($result);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<HybridSessionCookieTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
25
26
		// Save data against session
27
		$data1 = array(
28
			'Large' => str_repeat('A', 600),
29
			'Content' => str_repeat('B', 600)
30
		);
31
		$store->write($session, serialize($data1));
32
		$result = $store->read($session);
33
34
		// Cookies should not try to store data that large
35
		$this->assertEmpty($result);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<HybridSessionCookieTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
36
	}
37
38
	/**
39
	 * Ensure that subsequent reads without the necessary write do not report data
40
	 */
41
	public function testReadInvalidatesData() {
42
		$session = uniqid();
43
		$store = $this->getStore();
44
45
		// Test new session is blank
46
		$result = $store->read($session);
47
		$this->assertEmpty($result);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<HybridSessionCookieTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
48
49
		// Save data against session
50
		$data1 = array(
51
			'Color' => 'red',
52
			'Animal' => 'elephant'
53
		);
54
		$store->write($session, serialize($data1));
55
		$result = $store->read($session);
56
		$this->assertEquals($data1, unserialize($result));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<HybridSessionCookieTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
57
58
		// Since we have read the data into the result, the application could modify this content
59
		// and be unable to write it back due to headers being sent. We should thus assume
60
		// that subsequent reads without a successful write do not purport to have valid data
61
		$data1['Color'] = 'blue';
62
		$result = $store->read($session);
63
		$this->assertEmpty($result);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<HybridSessionCookieTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
64
65
		// Check that writing to cookie fails after headers are sent and these results remain
66
		// invalidated
67
		HybridSessionAbstractTest_TestCookieBackend::$override_headers_sent = true;
0 ignored issues
show
Documentation Bug introduced by
The property $override_headers_sent was declared of type string, but true is of type boolean. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
68
		$store->write($session, serialize($data1));
69
		$result = $store->read($session);
70
		$this->assertEmpty($result);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<HybridSessionCookieTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
71
72
	}
73
}
74