CrudAddActionTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 88
rs 10
wmc 5
lcom 1
cbo 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A tearDown() 0 6 1
A testExecuteSuccess() 0 10 1
A testExecuteValidationError() 0 9 1
A _initializeAction() 0 22 1
1
<?php
2
/**
3
 * Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com)
4
 *
5
 * Licensed under The MIT License
6
 * Redistributions of files must retain the above copyright notice.
7
 *
8
 * @copyright Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com)
9
 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
10
 */
11
12
namespace CakeDC\Api\Test\TestCase\Service\Action;
13
14
use CakeDC\Api\Service\Action\CrudAddAction;
15
use CakeDC\Api\Service\ServiceRegistry;
16
use CakeDC\Api\TestSuite\TestCase;
17
use CakeDC\Api\Test\ConfigTrait;
18
use CakeDC\Api\Test\FixturesTrait;
19
20
use Cake\Datasource\EntityInterface;
21
22
class CrudAddActionTest extends TestCase
23
{
24
25
    use ConfigTrait;
26
    use FixturesTrait;
27
28
    /**
29
     * @var CrudAddAction
30
     */
31
    public $Action;
32
33
    /**
34
     * setUp method
35
     *
36
     * @return void
37
     */
38
    public function setUp()
39
    {
40
        parent::setUp();
41
    }
42
43
    /**
44
     * tearDown method
45
     *
46
     * @return void
47
     */
48
    public function tearDown()
49
    {
50
        ServiceRegistry::clear();
0 ignored issues
show
Deprecated Code introduced by
The method CakeDC\Api\Service\ServiceRegistry::clear() has been deprecated with message: 3.6.0 Use \CakeDC\Api\Service\Locator\ServiceLocator::clear() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
51
        unset($this->Action, $this->request);
52
        parent::tearDown();
53
    }
54
55
    /**
56
     * Test load value method
57
     *
58
     * @return void
59
     */
60
    public function testExecuteSuccess()
61
    {
62
        $this->_initializeAction([
63
            'title' => 'New message'
64
        ]);
65
66
        $result = $this->Action->execute();
67
        $this->assertTrue($result instanceof EntityInterface);
68
        $this->assertNotEmpty($result['id']);
69
    }
70
71
    /**
72
     * Test load value method
73
     *
74
     * @return void
75
     * @expectedException \CakeDC\Api\Exception\ValidationException
76
     */
77
    public function testExecuteValidationError()
78
    {
79
        $this->_initializeAction([
80
            'title' => ''
81
        ]);
82
83
        $result = $this->Action->execute();
84
        $this->assertTrue($result instanceof EntityInterface);
85
    }
86
87
    protected function _initializeAction($post = [])
88
    {
89
        $this->_initializeRequest([
90
            'params' => [
91
                'service' => 'articles',
92
                'pass' => [],
93
            ],
94
            'post' => $post,
95
        ], 'POST');
96
        $options = [
97
            'version' => null,
98
            'service' => $this->request->getParam('service'),
0 ignored issues
show
Bug introduced by
The property request does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
99
            'request' => $this->request,
100
            'response' => $this->response,
0 ignored issues
show
Bug introduced by
The property response does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
101
            'baseUrl' => '/articles',
102
        ];
103
        $this->Service = ServiceRegistry::get($this->request->getParam('service'), $options);
0 ignored issues
show
Bug introduced by
The property Service does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Deprecated Code introduced by
The method CakeDC\Api\Service\ServiceRegistry::get() has been deprecated with message: 3.6.0 Use \CakeDC\Api\Service\Locator\ServiceLocator::get() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
104
105
        $this->Action = new CrudAddAction([
106
            'service' => $this->Service,
107
        ]);
108
    }
109
}
110