Completed
Push — master ( f10ba0...92e5ec )
by AJ
05:56
created

ShopifyAPIComponentTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 15
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 13
nc 1
nop 0
1
<?php
2
/**
3
 * CakePHPify : CakePHP Plugin for Shopify API Authentication
4
 * Copyright (c) Multidimension.al (http://multidimension.al)
5
 * Github : https://github.com/multidimension-al/cakephpify
6
 *
7
 * Licensed under The MIT License
8
 * For full copyright and license information, please see the LICENSE file
9
 * Redistributions of files must retain the above copyright notice.
10
 *
11
 * @copyright (c) Multidimension.al (http://multidimension.al)
12
 * @link      https://github.com/multidimension-al/cakephpify CakePHPify Github
13
 * @license   http://www.opensource.org/licenses/mit-license.php MIT License
14
 */
15
16
namespace Multidimensional\Cakephpify\Test\TestCase\Controller\Component;
17
18
use Cake\Controller\ComponentRegistry;
19
use Cake\Controller\Controller;
20
use Cake\Event\Event;
21
use Cake\Network\Request;
22
use Cake\Network\Response;
23
use Cake\TestSuite\TestCase;
24
use Multidimensional\Cakephpify\Controller\Component\ShopifyAPIComponent;
25
use Multidimensional\Cakephpify\Test\Fixture\AccessTokensFixture;
26
use Multidimensional\Cakephpify\Test\Fixture\ShopsFixture;
27
28
class ShopifyAPIComponentTest extends TestCase
29
{
30
31
    public $component = null;
32
    public $controller = null;
33
    public $fixtures = ['plugin.Multidimensional/Cakephpify.Shops', 'plugin.Multidimensional/Cakephpify.AccessTokens'];
34
35
    public function setUp()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
36
    {
37
        parent::setUp();
38
        $request = new Request();
39
        $response = new Response();
40
        $this->controller = $this->getMockBuilder('Cake\Controller\Controller')
41
            ->setConstructorArgs([$request, $response])
42
            ->setMethods(null)
43
            ->getMock();
44
        $registry = new ComponentRegistry($this->controller);
45
        $this->component = new ShopifyAPIComponent($registry);
46
		$this->component->initialize(['apiKey' => 'abc123']);
47
        $event = new Event('Controller.startup', $this->controller);
48
        $this->component->startup($event);
49
    }
50
51
    public function tearDown()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
52
    {
53
        parent::tearDown();
54
        unset($this->component, $this->controller);
55
    }
56
57
    public function testShopDomain()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
58
    {
59
		$shopDomain = "test.myshopify.com";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal test.myshopify.com does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
60
		$return = $this->component->setShopDomain($shopDomain);
61
		$this->assertSame($return, $shopDomain);
62
		$return = $this->component->getShopDomain();
63
		$this->assertSame($return, $shopDomain);
64
		
65
		$shopDomain = "random.myshopify.com";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal random.myshopify.com does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
66
		$this->component->setShopDomain($shopDomain);
67
		$return = $this->component->setShopDomain($shopDomain);
68
		$this->assertSame($return, $shopDomain);
69
		$return = $this->component->getShopDomain();
70
		$this->assertSame($return, $shopDomain);
71
		
72
		$shopDomain = NULL;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
73
		$return = $this->component->setShopDomain($shopDomain);
74
		$this->assertNull($return);
75
		$return = $this->component->getShopDomain();
76
		$this->assertNull($return);
77
		
78
		$shopDomain = false;
79
		$return = $this->component->setShopDomain($shopDomain);
0 ignored issues
show
Documentation introduced by
$shopDomain is of type boolean, but the function expects a string.

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...
80
		$this->assertFalse($return);
81
		$return = $this->component->getShopDomain();
82
		$this->assertFalse($return);
83
		
84
		$shopDomain = true;
85
		$return = $this->component->setShopDomain($shopDomain);
0 ignored issues
show
Documentation introduced by
$shopDomain is of type boolean, but the function expects a string.

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...
86
		$this->assertTrue($return);
87
		$return = $this->component->getShopDomain();
88
		$this->assertTrue($return);
89
    }
90
91
    public function testSetAccessToken()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
92
    {
93
        $this->markTestIncomplete('Not implemented yet.');
94
    }
95
96
    public function testGetAuthorizeUrl()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
97
    {
98
        $this->markTestIncomplete('Not implemented yet.');
99
    }
100
101
    public function testGetAccessToken()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
102
    {
103
        $this->markTestIncomplete('Not implemented yet.');
104
    }
105
106
    public function testNonce()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
107
    {
108
		$nonce = md5(rand());
109
		$return = $this->component->setNonce($nonce);
110
		$this->assertSame($return, $nonce);
111
		$return = $this->component->getNonce();
112
		$this->assertSame($return, $nonce);
113
		
114
		$nonce = md5(rand());
115
		$this->component->setNonce($nonce);
116
		$return = $this->component->setNonce($nonce);
117
		$this->assertSame($return, $nonce);
118
		$return = $this->component->getNonce();
119
		$this->assertSame($return, $nonce);
120
		
121
		$nonce = NULL;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
122
		$return = $this->component->setNonce($nonce);
123
		$this->assertNull($return);
124
		$return = $this->component->getNonce();
125
		$this->assertNull($return);
126
		
127
		$nonce = false;
128
		$return = $this->component->setNonce($nonce);
0 ignored issues
show
Documentation introduced by
$nonce is of type boolean, but the function expects a string.

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...
129
		$this->assertFalse($return);
130
		$return = $this->component->getNonce();
131
		$this->assertFalse($return);
132
		
133
		$nonce = true;
134
		$return = $this->component->setNonce($nonce);
0 ignored issues
show
Documentation introduced by
$nonce is of type boolean, but the function expects a string.

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...
135
		$this->assertTrue($return);
136
		$return = $this->component->getNonce();
137
		$this->assertTrue($return);
138
    }
139
140
}
141