Completed
Push — master ( 8ec403...fa21f3 )
by Evgeny
03:18
created

CrudDeleteActionTest::_initializeAction()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 18
nc 1
nop 2
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright 2016, 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, 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\CrudDeleteAction;
15
use CakeDC\Api\Service\ServiceRegistry;
16
use CakeDC\Api\Test\ConfigTrait;
17
use CakeDC\Api\Test\FixturesTrait;
18
use CakeDC\Api\TestSuite\TestCase;
19
20
class CrudDeleteActionTest extends TestCase
21
{
22
23
    use ConfigTrait;
24
    use FixturesTrait;
25
26
    /**
27
     * @var CrudDeleteAction
28
     */
29
    public $Action;
30
31
    /**
32
     * setUp method
33
     *
34
     * @return void
35
     */
36
    public function setUp()
37
    {
38
        parent::setUp();
39
    }
40
41
    /**
42
     * tearDown method
43
     *
44
     * @return void
45
     */
46
    public function tearDown()
47
    {
48
        ServiceRegistry::clear();
49
        unset($this->Service, $this->Action, $this->request);
50
        parent::tearDown();
51
    }
52
53
    /**
54
     * Test load value method
55
     *
56
     * @return void
57
     */
58
    public function testExecuteSuccess()
59
    {
60
        $this->_initializeAction(1, [
61
            'title' => 'New message'
62
        ]);
63
64
        $onFindEntity = false;
65
        $this->Action->eventManager()->on('Action.Crud.onFindEntity', function () use (&$onFindEntity) {
66
            $onFindEntity = true;
67
        });
68
69
        $result = $this->Action->execute();
70
        $this->assertTrue($result);
71
        $this->assertTrue($onFindEntity);
72
    }
73
74
    /**
75
     * Test load value method
76
     *
77
     * @return void
78
     * @expectedException \Cake\Datasource\Exception\RecordNotFoundException
79
     */
80
    public function testExecuteNotFound()
81
    {
82
        $this->_initializeAction(999, [
83
            'title' => 'New message'
84
        ]);
85
        $this->Action->execute();
86
    }
87
88
    protected function _initializeAction($id, $post = [])
89
    {
90
        $this->_initializeRequest([
91
            'params' => [
92
                'service' => 'articles',
93
                'pass' => [
94
                    $id,
95
                ],
96
            ],
97
            'post' => $post,
98
        ], 'DELETE');
99
        $options = [
100
            'version' => null,
101
			'service' => $this->request['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...
102
            'request' => $this->request,
103
            '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...
104
            'baseUrl' => '/articles/' . $id,
105
        ];
106
        $this->Service = ServiceRegistry::get($this->request['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...
107
108
        $this->Action = new CrudDeleteAction([
109
            'service' => $this->Service,
110
            'id' => $id,
111
        ]);
112
    }
113
}
114