Passed
Push — master ( 64043f...33d76f )
by Carlos
04:40
created

AtributoTest::testValueNoAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of FacturaScripts
4
 * Copyright (C) 2017-2021  Carlos Garcia Gomez     <[email protected]>
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as
8
 * published by the Free Software Foundation, either version 3 of the
9
 * License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License
17
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18
 */
19
20
namespace FacturaScripts\Test\Core\Model;
21
22
use FacturaScripts\Core\Model\Atributo;
23
use FacturaScripts\Core\Model\AtributoValor;
24
use FacturaScripts\Test\Core\LogErrorsTrait;
25
use PHPUnit\Framework\TestCase;
26
27
final class AtributoTest extends TestCase
28
{
29
    use LogErrorsTrait;
30
31
    public function testCreate()
32
    {
33
        $attribute = $this->getTestAttribute();
34
        $this->assertTrue($attribute->save(), 'attribute-cant-save');
35
        $this->assertNotNull($attribute->primaryColumnValue(), 'attribute-not-stored');
36
        $this->assertTrue($attribute->exists(), 'attribute-cant-persist');
37
        $this->assertTrue($attribute->delete(), 'attribute-cant-delete');
38
    }
39
40
    public function testCreateWithNoCode()
41
    {
42
        $attribute = new Atributo();
43
        $attribute->nombre = 'Test Attribute with new code';
44
        $this->assertTrue($attribute->save(), 'attribute-cant-save');
45
        $this->assertTrue($attribute->delete(), 'attribute-cant-delete');
46
    }
47
48
    public function testAttributeValues()
49
    {
50
        // creamos el atributo
51
        $attribute = $this->getTestAttribute();
52
        $this->assertTrue($attribute->save(), 'attribute-cant-save');
53
54
        // creamos un valor
55
        $attributeValue = new AtributoValor();
56
        $attributeValue->codatributo = $attribute->codatributo;
57
        $attributeValue->valor = 'Value 1';
58
        $this->assertTrue($attributeValue->save(), 'attribute-value-cant-save');
59
60
        // eliminamos el atributo
61
        $this->assertTrue($attribute->delete(), 'attribute-value-cant-delete');
62
63
        // se debe haber eliminado el valor
64
        $this->assertFalse($attributeValue->exists(), 'attribute-value-still-persist');
65
    }
66
67
    public function testValueNoAttribute()
68
    {
69
        $attributeValue = new AtributoValor();
70
        $attributeValue->valor = 'Value 1';
71
        $this->assertFalse($attributeValue->save(), 'value-can-save-without-attribute');
72
    }
73
74
    private function getTestAttribute(): Atributo
75
    {
76
        $attribute = new Atributo();
77
        $attribute->codatributo = 'Test';
78
        $attribute->nombre = 'Test Atribute';
79
        return $attribute;
80
    }
81
82
    protected function tearDown()
83
    {
84
        $this->logErrors();
85
    }
86
}
87