Completed
Push — master ( ba7de8...b94793 )
by Aimeos
02:24
created

StandardTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 4
c 5
b 0
f 0
lcom 1
cbo 3
dl 0
loc 66
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A testGet() 0 11 1
A testOptions() 0 13 1
A testOptionsException() 0 20 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017
6
 */
7
8
9
namespace Aimeos\Client\JsonApi;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $context;
15
	private $object;
16
	private $view;
17
18
19
	protected function setUp()
20
	{
21
		$this->context = \TestHelperJapi::getContext();
22
		$templatePaths = \TestHelperJapi::getTemplatePaths();
23
		$this->view = $this->context->getView();
24
25
		$this->object = new \Aimeos\Client\JsonApi\Standard( $this->context, $this->view, $templatePaths, '' );
26
	}
27
28
29
	public function testGet()
30
	{
31
		$response = $this->object->get( $this->view->request(), $this->view->response() );
32
		$result = json_decode( (string) $response->getBody(), true );
33
34
		$this->assertEquals( 200, $response->getStatusCode() );
35
		$this->assertEquals( 1, count( $response->getHeader( 'Allow' ) ) );
36
		$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) );
37
38
		$this->assertArrayHasKey( 'title', $result['errors'] );
39
	}
40
41
42
	public function testOptions()
43
	{
44
		$response = $this->object->options( $this->view->request(), $this->view->response() );
45
		$result = json_decode( (string) $response->getBody(), true );
46
47
		$this->assertEquals( 200, $response->getStatusCode() );
48
		$this->assertEquals( 1, count( $response->getHeader( 'Allow' ) ) );
49
		$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) );
50
51
		$this->assertEquals( null, $result['meta']['prefix'] );
52
		$this->assertGreaterThan( 8, count( $result['meta']['resources'] ) );
53
		$this->assertArrayNotHasKey( 'errors', $result );
54
	}
55
56
57
	public function testOptionsException()
58
	{
59
		$templatePaths = \TestHelperJapi::getTemplatePaths();
60
61
		$object = $this->getMockBuilder( '\Aimeos\Client\JsonApi\Standard' )
62
			->setConstructorArgs( [$this->context, $this->view, $templatePaths, ''] )
63
			->setMethods( ['getContext'] )
64
			->getMock();
65
66
		$object->expects( $this->once() )->method( 'getContext' )
67
			->will( $this->throwException( new \Exception() ) );
68
69
70
		$response = $object->options( $this->view->request(), $this->view->response() );
71
		$result = json_decode( (string) $response->getBody(), true );
72
73
74
		$this->assertEquals( 500, $response->getStatusCode() );
75
		$this->assertArrayHasKey( 'errors', $result );
76
	}
77
}