RecordTraitTest::test_updateSmartProperty()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 14
c 2
b 0
f 1
dl 0
loc 22
rs 9.7998
cc 2
nc 1
nop 0
1
<?php
2
3
namespace ByTIC\Models\SmartProperties\Tests\RecordsTraits\HasSmartProperties;
4
5
use ByTIC\EventDispatcher\Dispatcher\EventDispatcher;
6
use ByTIC\Models\SmartProperties\Properties\AbstractProperty\Generic;
7
use ByTIC\Models\SmartProperties\Tests\AbstractTest;
8
use ByTIC\Models\SmartProperties\Tests\Fixtures\RecordsTraits\HasSmartProperties\Record;
9
use ByTIC\Models\SmartProperties\Tests\Fixtures\RecordsTraits\HasSmartProperties\Records;
10
use ByTIC\Models\SmartProperties\Tests\Fixtures\RecordsTraits\HasSmartProperties\RegistrationStatuses\Unregistered;
11
use Nip\Container\Container;
12
use Symfony\Component\Workflow\Event\Event;
13
14
/**
15
 * Class TraitsTest
16
 * @package ByTIC\Common\Tests\Payments\Methods
17
 */
18
class RecordTraitTest extends AbstractTest
19
{
20
    /**
21
     * @var Record
22
     */
23
    private $object;
24
25
    public function testGetPropertyWithoutValue()
26
    {
27
        $status = $this->object->getSmartProperty('Status');
28
        self::assertInstanceOf(Generic::class, $status);
29
        self::assertSame('allocated', $status->getName());
30
31
        $registrationStatus = $this->object->getSmartProperty('RegistrationStatus');
32
        self::assertInstanceOf(Generic::class, $registrationStatus);
33
        self::assertSame('unregistered', $registrationStatus->getName());
34
    }
35
36
    public function test_getProperty_EmptyValue()
37
    {
38
        $this->object->registration_status = '';
39
        $registrationStatus = $this->object->getSmartProperty('RegistrationStatus');
40
        self::assertInstanceOf(Unregistered::class, $registrationStatus);
41
    }
42
43
    public function testGetStatusWithValue()
44
    {
45
        $this->object->status = 'applicant';
46
        $this->object->registration_status = 'unpaid';
47
48
        $status = $this->object->getSmartProperty('Status');
49
        self::assertInstanceOf(Generic::class, $status);
50
        self::assertSame('applicant', $status->getName());
51
52
        $registrationStatus = $this->object->getSmartProperty('RegistrationStatus');
53
        self::assertInstanceOf(Generic::class, $registrationStatus);
54
        self::assertSame('unpaid', $registrationStatus->getName());
55
    }
56
57
    public function test_updateSmartProperty()
58
    {
59
        $this->object->setAttribute('status', 'applicant');
60
61
        $eventDispatcher = \Mockery::mock(EventDispatcher::class)->makePartial();
62
        $eventDispatcher->shouldReceive('dispatch')->once()->with(\Mockery::on(function ($event) {
63
            if (!($event instanceof Event)) {
64
                return false;
65
            }
66
            $transition = $event->getTransition();
67
68
            self::assertSame(['applicant'], $transition->getFroms());
69
            self::assertSame(['allocated'], $transition->getTos());
70
            return true;
71
        }));
72
        Container::getInstance()->set('events', $eventDispatcher);
73
74
        self::assertSame('applicant', $this->object->getSmartProperty('Status')->getName());
75
76
        $this->object->updateSmartProperty('Status', 'allocated');
77
        self::assertSame('allocated', $this->object->status);
78
        self::assertSame('allocated', $this->object->getSmartProperty('Status')->getName());
79
    }
80
81
    protected function setUp(): void
82
    {
83
        parent::setUp();
84
        $this->object = \Mockery::mock(Record::class)->makePartial();
0 ignored issues
show
Documentation Bug introduced by
It seems like Mockery::mock(ByTIC\Mode...::class)->makePartial() of type Mockery\Mock is incompatible with the declared type ByTIC\Models\SmartProper...sSmartProperties\Record of property $object.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
85
86
        $manager = new Records();
87
        $this->object->shouldReceive('getManager')->andReturn($manager);
88
    }
89
}
90