Issues (87)

tests/Client/JsonApi/StandardTest.php (1 issue)

Severity
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017-2025
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() : void
20
	{
21
		$this->context = \TestHelper::context();
22
		$this->view = $this->context->view();
23
24
		$this->object = new \Aimeos\Client\JsonApi\Standard( $this->context, '' );
0 ignored issues
show
The call to Aimeos\Client\JsonApi\Standard::__construct() has too many arguments starting with ''. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
		$this->object = /** @scrutinizer ignore-call */ new \Aimeos\Client\JsonApi\Standard( $this->context, '' );

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
25
		$this->object->setView( $this->view );
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->assertGreaterThanOrEqual( 12, count( $result['meta']['resources'] ) );
53
		$this->assertArrayNotHasKey( 'errors', $result );
54
	}
55
56
57
	public function testOptionsException()
58
	{
59
		$object = $this->getMockBuilder( \Aimeos\Client\JsonApi\Standard::class )
60
			->setConstructorArgs( [$this->context, ''] )
61
			->onlyMethods( ['context'] )
62
			->getMock();
63
64
		$object->expects( $this->once() )->method( 'context' )
65
			->will( $this->throwException( new \Exception() ) );
66
67
68
		$object->setView( $this->view );
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
}
78