Completed
Push — master ( 649aac...9efee0 )
by Aimeos
01:52
created

JsonApiTest::testCreateEmpty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017-2018
6
 */
7
8
9
namespace Aimeos\Client;
10
11
12
class JsonApiTest extends \PHPUnit\Framework\TestCase
13
{
14
	public function testCreate()
15
	{
16
		$context = \TestHelperJapi::getContext();
17
18
		$client = \Aimeos\Client\JsonApi::create( $context, 'product' );
19
		$this->assertInstanceOf( \Aimeos\Client\JsonApi\Iface::class, $client );
20
	}
21
22
23
	public function testCreateEmpty()
24
	{
25
		$context = \TestHelperJapi::getContext();
26
27
		$client = \Aimeos\Client\JsonApi::create( $context, '' );
28
		$this->assertInstanceOf( \Aimeos\Client\JsonApi\Iface::class, $client );
29
	}
30
31
32
	public function testCreateInvalidPath()
33
	{
34
		$context = \TestHelperJapi::getContext();
35
36
		$this->setExpectedException( \Aimeos\Client\JsonApi\Exception::class );
37
		\Aimeos\Client\JsonApi::create( $context, '%^' );
38
	}
39
40
41
	public function testCreateInvalidName()
42
	{
43
		$context = \TestHelperJapi::getContext();
44
45
		$this->setExpectedException( \Aimeos\Client\JsonApi\Exception::class );
46
		\Aimeos\Client\JsonApi::create( $context, '', '%^' );
47
	}
48
49
50
	public function testClear()
51
	{
52
		$cache = \Aimeos\Client\JsonApi::cache( true );
53
54
		$context = \TestHelperJapi::getContext();
55
56
		$client1 = \Aimeos\Client\JsonApi::create( $context, 'product' );
57
		\Aimeos\Client\JsonApi::clear();
58
		$client2 = \Aimeos\Client\JsonApi::create( $context, 'product' );
59
60
		\Aimeos\Client\JsonApi::cache( $cache );
61
62
		$this->assertNotSame( $client1, $client2 );
63
	}
64
65
66
	public function testClearSite()
67
	{
68
		$cache = \Aimeos\Client\JsonApi::cache( true );
69
70
		$context = \TestHelperJapi::getContext();
71
72
		$cntlA1 = \Aimeos\Client\JsonApi::create( $context, 'product' );
73
		$cntlB1 = \Aimeos\Client\JsonApi::create( $context, 'attribute' );
74
75
		\Aimeos\Client\JsonApi::clear( (string) $context );
76
77
		$cntlA2 = \Aimeos\Client\JsonApi::create( $context, 'product' );
78
		$cntlB2 = \Aimeos\Client\JsonApi::create( $context, 'attribute' );
79
80
		\Aimeos\Client\JsonApi::cache( $cache );
81
82
		$this->assertNotSame( $cntlA1, $cntlA2 );
83
		$this->assertNotSame( $cntlB1, $cntlB2 );
84
	}
85
86
87
	public function testClearSpecific()
88
	{
89
		$cache = \Aimeos\Client\JsonApi::cache( true );
90
91
		$context = \TestHelperJapi::getContext();
92
93
		$cntlA1 = \Aimeos\Client\JsonApi::create( $context, 'product' );
94
		$cntlB1 = \Aimeos\Client\JsonApi::create( $context, 'attribute' );
95
96
		\Aimeos\Client\JsonApi::clear( (string) $context, 'product' );
97
98
		$cntlA2 = \Aimeos\Client\JsonApi::create( $context, 'product' );
99
		$cntlB2 = \Aimeos\Client\JsonApi::create( $context, 'attribute' );
100
101
		\Aimeos\Client\JsonApi::cache( $cache );
102
103
		$this->assertNotSame( $cntlA1, $cntlA2 );
104
		$this->assertSame( $cntlB1, $cntlB2 );
105
	}
106
107
}